2015-11-12 19:55:17 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2016-01-04 15:58:20 +00:00
|
|
|
"fmt"
|
2016-01-27 21:03:09 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2016-12-01 16:11:15 +00:00
|
|
|
"github.com/docker/docker/pkg/system"
|
2015-11-12 19:55:17 +00:00
|
|
|
)
|
|
|
|
|
2017-04-11 17:34:19 +00:00
|
|
|
const (
|
2016-12-01 16:11:15 +00:00
|
|
|
containerSecretMountPath = `C:\ProgramData\Docker\secrets`
|
|
|
|
containerInternalSecretMountPath = `C:\ProgramData\Docker\internal\secrets`
|
2017-05-11 18:55:03 +00:00
|
|
|
containerInternalConfigsDirPath = `C:\ProgramData\Docker\internal\configs`
|
2017-04-11 17:34:19 +00:00
|
|
|
)
|
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
// ExitStatus provides exit reasons for a container.
|
|
|
|
type ExitStatus struct {
|
|
|
|
// The exit code with which the container exited.
|
|
|
|
ExitCode int
|
|
|
|
}
|
|
|
|
|
2016-09-04 07:17:58 +00:00
|
|
|
// UnmountIpcMounts unmounts Ipc related mounts.
|
2015-11-12 19:55:17 +00:00
|
|
|
// This is a NOOP on windows.
|
|
|
|
func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// IpcMounts returns the list of Ipc related mounts.
|
2016-03-18 18:53:27 +00:00
|
|
|
func (container *Container) IpcMounts() []Mount {
|
2015-11-12 19:55:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:11:15 +00:00
|
|
|
// CreateSecretSymlinks creates symlinks to files in the secret mount.
|
|
|
|
func (container *Container) CreateSecretSymlinks() error {
|
|
|
|
for _, r := range container.SecretReferences {
|
|
|
|
if r.File == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resolvedPath, _, err := container.ResolvePath(getSecretTargetPath(r))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-02 01:59:11 +00:00
|
|
|
if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
|
2016-12-01 16:11:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := os.Symlink(filepath.Join(containerInternalSecretMountPath, r.SecretID), resolvedPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:51:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:11:15 +00:00
|
|
|
// SecretMounts returns the mount for the secret path.
|
|
|
|
// All secrets are stored in a single mount on Windows. Target symlinks are
|
|
|
|
// created for each secret, pointing to the files in this mount.
|
|
|
|
func (container *Container) SecretMounts() []Mount {
|
|
|
|
var mounts []Mount
|
|
|
|
if len(container.SecretReferences) > 0 {
|
|
|
|
mounts = append(mounts, Mount{
|
|
|
|
Source: container.SecretMountPath(),
|
|
|
|
Destination: containerInternalSecretMountPath,
|
|
|
|
Writable: false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return mounts
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:51:13 +00:00
|
|
|
// UnmountSecrets unmounts the fs for secrets
|
|
|
|
func (container *Container) UnmountSecrets() error {
|
2016-12-01 16:11:15 +00:00
|
|
|
return os.RemoveAll(container.SecretMountPath())
|
2016-10-27 20:51:13 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 18:55:03 +00:00
|
|
|
// CreateConfigSymlinks creates symlinks to files in the config mount.
|
|
|
|
func (container *Container) CreateConfigSymlinks() error {
|
|
|
|
for _, configRef := range container.ConfigReferences {
|
|
|
|
if configRef.File == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resolvedPath, _, err := container.ResolvePath(configRef.File.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-02 01:59:11 +00:00
|
|
|
if err := system.MkdirAll(filepath.Dir(resolvedPath), 0, ""); err != nil {
|
2017-05-11 18:55:03 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := os.Symlink(filepath.Join(containerInternalConfigsDirPath, configRef.ConfigID), resolvedPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigMounts returns the mount for configs.
|
|
|
|
// All configs are stored in a single mount on Windows. Target symlinks are
|
|
|
|
// created for each config, pointing to the files in this mount.
|
|
|
|
func (container *Container) ConfigMounts() []Mount {
|
|
|
|
var mounts []Mount
|
|
|
|
if len(container.ConfigReferences) > 0 {
|
|
|
|
mounts = append(mounts, Mount{
|
|
|
|
Source: container.ConfigsDirPath(),
|
|
|
|
Destination: containerInternalConfigsDirPath,
|
|
|
|
Writable: false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return mounts
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:53:06 +00:00
|
|
|
// DetachAndUnmount unmounts all volumes.
|
|
|
|
// On Windows it only delegates to `UnmountVolumes` since there is nothing to
|
|
|
|
// force unmount.
|
|
|
|
func (container *Container) DetachAndUnmount(volumeEventLog func(name, action string, attributes map[string]string)) error {
|
|
|
|
return container.UnmountVolumes(volumeEventLog)
|
2015-11-12 19:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TmpfsMounts returns the list of tmpfs mounts
|
2016-09-22 20:14:15 +00:00
|
|
|
func (container *Container) TmpfsMounts() ([]Mount, error) {
|
2016-06-06 09:57:11 +00:00
|
|
|
var mounts []Mount
|
2016-09-22 20:14:15 +00:00
|
|
|
return mounts, nil
|
2015-11-12 19:55:17 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 15:58:20 +00:00
|
|
|
// UpdateContainer updates configuration of a container
|
2016-03-01 18:23:43 +00:00
|
|
|
func (container *Container) UpdateContainer(hostConfig *containertypes.HostConfig) error {
|
2016-01-04 15:58:20 +00:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2017-03-07 02:29:27 +00:00
|
|
|
|
2016-01-04 15:58:20 +00:00
|
|
|
resources := hostConfig.Resources
|
2017-03-07 02:29:27 +00:00
|
|
|
if resources.CPUShares != 0 ||
|
|
|
|
resources.Memory != 0 ||
|
|
|
|
resources.NanoCPUs != 0 ||
|
|
|
|
resources.CgroupParent != "" ||
|
|
|
|
resources.BlkioWeight != 0 ||
|
|
|
|
len(resources.BlkioWeightDevice) != 0 ||
|
|
|
|
len(resources.BlkioDeviceReadBps) != 0 ||
|
|
|
|
len(resources.BlkioDeviceWriteBps) != 0 ||
|
|
|
|
len(resources.BlkioDeviceReadIOps) != 0 ||
|
|
|
|
len(resources.BlkioDeviceWriteIOps) != 0 ||
|
|
|
|
resources.CPUPeriod != 0 ||
|
|
|
|
resources.CPUQuota != 0 ||
|
|
|
|
resources.CPURealtimePeriod != 0 ||
|
|
|
|
resources.CPURealtimeRuntime != 0 ||
|
|
|
|
resources.CpusetCpus != "" ||
|
|
|
|
resources.CpusetMems != "" ||
|
|
|
|
len(resources.Devices) != 0 ||
|
|
|
|
len(resources.DeviceCgroupRules) != 0 ||
|
|
|
|
resources.DiskQuota != 0 ||
|
|
|
|
resources.KernelMemory != 0 ||
|
|
|
|
resources.MemoryReservation != 0 ||
|
|
|
|
resources.MemorySwap != 0 ||
|
|
|
|
resources.MemorySwappiness != nil ||
|
|
|
|
resources.OomKillDisable != nil ||
|
|
|
|
resources.PidsLimit != 0 ||
|
|
|
|
len(resources.Ulimits) != 0 ||
|
|
|
|
resources.CPUCount != 0 ||
|
|
|
|
resources.CPUPercent != 0 ||
|
|
|
|
resources.IOMaximumIOps != 0 ||
|
|
|
|
resources.IOMaximumBandwidth != 0 {
|
|
|
|
return fmt.Errorf("resource updating isn't supported on Windows")
|
2016-01-04 15:58:20 +00:00
|
|
|
}
|
|
|
|
// update HostConfig of container
|
|
|
|
if hostConfig.RestartPolicy.Name != "" {
|
2016-08-15 08:38:47 +00:00
|
|
|
if container.HostConfig.AutoRemove && !hostConfig.RestartPolicy.IsNone() {
|
|
|
|
return fmt.Errorf("Restart policy cannot be updated because AutoRemove is enabled for the container")
|
|
|
|
}
|
2016-01-04 15:58:20 +00:00
|
|
|
container.HostConfig.RestartPolicy = hostConfig.RestartPolicy
|
|
|
|
}
|
2015-12-28 11:19:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-27 21:03:09 +00:00
|
|
|
// cleanResourcePath cleans a resource path by removing C:\ syntax, and prepares
|
|
|
|
// to combine with a volume path
|
|
|
|
func cleanResourcePath(path string) string {
|
|
|
|
if len(path) >= 2 {
|
|
|
|
c := path[0]
|
|
|
|
if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
|
|
|
|
path = path[2:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filepath.Join(string(os.PathSeparator), path)
|
|
|
|
}
|
2016-03-01 18:23:43 +00:00
|
|
|
|
2016-03-10 04:33:21 +00:00
|
|
|
// BuildHostnameFile writes the container's hostname file.
|
|
|
|
func (container *Container) BuildHostnameFile() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-09-13 00:17:09 +00:00
|
|
|
// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
|
|
|
|
func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
|
|
|
|
return true
|
|
|
|
}
|