@ -108,6 +108,7 @@ type ServiceConfig struct {
CredentialSpec * CredentialSpecConfig ` mapstructure:"credential_spec" yaml:"credential_spec,omitempty" json:"credential_spec,omitempty" `
CredentialSpec * CredentialSpecConfig ` mapstructure:"credential_spec" yaml:"credential_spec,omitempty" json:"credential_spec,omitempty" `
DependsOn DependsOnConfig ` mapstructure:"depends_on" yaml:"depends_on,omitempty" json:"depends_on,omitempty" `
DependsOn DependsOnConfig ` mapstructure:"depends_on" yaml:"depends_on,omitempty" json:"depends_on,omitempty" `
Deploy * DeployConfig ` yaml:",omitempty" json:"deploy,omitempty" `
Deploy * DeployConfig ` yaml:",omitempty" json:"deploy,omitempty" `
DeviceCgroupRules [ ] string ` mapstructure:"device_cgroup_rules" yaml:"device_cgroup_rules,omitempty" json:"device_cgroup_rules,omitempty" `
Devices [ ] string ` yaml:",omitempty" json:"devices,omitempty" `
Devices [ ] string ` yaml:",omitempty" json:"devices,omitempty" `
DNS StringList ` yaml:",omitempty" json:"dns,omitempty" `
DNS StringList ` yaml:",omitempty" json:"dns,omitempty" `
DNSOpts [ ] string ` mapstructure:"dns_opt" yaml:"dns_opt,omitempty" json:"dns_opt,omitempty" `
DNSOpts [ ] string ` mapstructure:"dns_opt" yaml:"dns_opt,omitempty" json:"dns_opt,omitempty" `
@ -129,6 +130,7 @@ type ServiceConfig struct {
Ipc string ` yaml:",omitempty" json:"ipc,omitempty" `
Ipc string ` yaml:",omitempty" json:"ipc,omitempty" `
Isolation string ` mapstructure:"isolation" yaml:"isolation,omitempty" json:"isolation,omitempty" `
Isolation string ` mapstructure:"isolation" yaml:"isolation,omitempty" json:"isolation,omitempty" `
Labels Labels ` yaml:",omitempty" json:"labels,omitempty" `
Labels Labels ` yaml:",omitempty" json:"labels,omitempty" `
CustomLabels Labels ` yaml:"-" json:"-" `
Links [ ] string ` yaml:",omitempty" json:"links,omitempty" `
Links [ ] string ` yaml:",omitempty" json:"links,omitempty" `
Logging * LoggingConfig ` yaml:",omitempty" json:"logging,omitempty" `
Logging * LoggingConfig ` yaml:",omitempty" json:"logging,omitempty" `
LogDriver string ` mapstructure:"log_driver" yaml:"log_driver,omitempty" json:"log_driver,omitempty" `
LogDriver string ` mapstructure:"log_driver" yaml:"log_driver,omitempty" json:"log_driver,omitempty" `
@ -292,8 +294,12 @@ type BuildConfig struct {
Context string ` yaml:",omitempty" json:"context,omitempty" `
Context string ` yaml:",omitempty" json:"context,omitempty" `
Dockerfile string ` yaml:",omitempty" json:"dockerfile,omitempty" `
Dockerfile string ` yaml:",omitempty" json:"dockerfile,omitempty" `
Args MappingWithEquals ` yaml:",omitempty" json:"args,omitempty" `
Args MappingWithEquals ` yaml:",omitempty" json:"args,omitempty" `
SSH SSHConfig ` yaml:"ssh,omitempty" json:"ssh,omitempty" `
Labels Labels ` yaml:",omitempty" json:"labels,omitempty" `
Labels Labels ` yaml:",omitempty" json:"labels,omitempty" `
CacheFrom StringList ` mapstructure:"cache_from" yaml:"cache_from,omitempty" json:"cache_from,omitempty" `
CacheFrom StringList ` mapstructure:"cache_from" yaml:"cache_from,omitempty" json:"cache_from,omitempty" `
CacheTo StringList ` mapstructure:"cache_to" yaml:"cache_to,omitempty" json:"cache_to,omitempty" `
NoCache bool ` mapstructure:"no_cache" yaml:"no_cache,omitempty" json:"no_cache,omitempty" `
Pull bool ` mapstructure:"pull" yaml:"pull,omitempty" json:"pull,omitempty" `
ExtraHosts HostsList ` mapstructure:"extra_hosts" yaml:"extra_hosts,omitempty" json:"extra_hosts,omitempty" `
ExtraHosts HostsList ` mapstructure:"extra_hosts" yaml:"extra_hosts,omitempty" json:"extra_hosts,omitempty" `
Isolation string ` yaml:",omitempty" json:"isolation,omitempty" `
Isolation string ` yaml:",omitempty" json:"isolation,omitempty" `
Network string ` yaml:",omitempty" json:"network,omitempty" `
Network string ` yaml:",omitempty" json:"network,omitempty" `
@ -305,11 +311,11 @@ type BuildConfig struct {
// BlkioConfig define blkio config
// BlkioConfig define blkio config
type BlkioConfig struct {
type BlkioConfig struct {
Weight uint16 ` yaml:",omitempty" json:"weight,omitempty" `
Weight uint16 ` yaml:",omitempty" json:"weight,omitempty" `
WeightDevice [ ] WeightDevice ` yaml:",omitempty" json:"weight_device,omitempty"`
WeightDevice [ ] WeightDevice ` mapstructure:"weight_device" yaml:",omitempty" json:"weight_device,omitempty"`
DeviceReadBps [ ] ThrottleDevice ` yaml:",omitempty" json:"device_read_bps,omitempty"`
DeviceReadBps [ ] ThrottleDevice ` mapstructure:"device_read_bps" yaml:",omitempty" json:"device_read_bps,omitempty"`
DeviceReadIOps [ ] ThrottleDevice ` yaml:",omitempty" json:"device_read_iops,omitempty"`
DeviceReadIOps [ ] ThrottleDevice ` mapstructure:"device_read_iops" yaml:",omitempty" json:"device_read_iops,omitempty"`
DeviceWriteBps [ ] ThrottleDevice ` yaml:",omitempty" json:"device_write_bps,omitempty"`
DeviceWriteBps [ ] ThrottleDevice ` mapstructure:"device_write_bps" yaml:",omitempty" json:"device_write_bps,omitempty"`
DeviceWriteIOps [ ] ThrottleDevice ` yaml:",omitempty" json:"device_write_iops,omitempty"`
DeviceWriteIOps [ ] ThrottleDevice ` mapstructure:"device_write_iops" yaml:",omitempty" json:"device_write_iops,omitempty"`
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
}
}
@ -423,6 +429,39 @@ func (l Labels) Add(key, value string) Labels {
return l
return l
}
}
type SSHKey struct {
ID string
Path string
}
// SSHConfig is a mapping type for SSH build config
type SSHConfig [ ] SSHKey
func ( s SSHConfig ) Get ( id string ) ( string , error ) {
for _ , sshKey := range s {
if sshKey . ID == id {
return sshKey . Path , nil
}
}
return "" , fmt . Errorf ( "ID %s not found in SSH keys" , id )
}
// MarshalYAML makes SSHKey implement yaml.Marshaller
func ( s SSHKey ) MarshalYAML ( ) ( interface { } , error ) {
if s . Path == "" {
return s . ID , nil
}
return fmt . Sprintf ( "%s: %s" , s . ID , s . Path ) , nil
}
// MarshalJSON makes SSHKey implement json.Marshaller
func ( s SSHKey ) MarshalJSON ( ) ( [ ] byte , error ) {
if s . Path == "" {
return [ ] byte ( fmt . Sprintf ( ` "%s" ` , s . ID ) ) , nil
}
return [ ] byte ( fmt . Sprintf ( ` "%s": %s ` , s . ID , s . Path ) ) , nil
}
// MappingWithColon is a mapping type that can be converted from a list of
// MappingWithColon is a mapping type that can be converted from a list of
// 'key: value' strings
// 'key: value' strings
type MappingWithColon map [ string ] string
type MappingWithColon map [ string ] string
@ -493,6 +532,7 @@ type Resource struct {
// TODO: types to convert from units and ratios
// TODO: types to convert from units and ratios
NanoCPUs string ` mapstructure:"cpus" yaml:"cpus,omitempty" json:"cpus,omitempty" `
NanoCPUs string ` mapstructure:"cpus" yaml:"cpus,omitempty" json:"cpus,omitempty" `
MemoryBytes UnitBytes ` mapstructure:"memory" yaml:"memory,omitempty" json:"memory,omitempty" `
MemoryBytes UnitBytes ` mapstructure:"memory" yaml:"memory,omitempty" json:"memory,omitempty" `
PIds int64 ` mapstructure:"pids" yaml:"pids,omitempty" json:"pids,omitempty" `
Devices [ ] DeviceRequest ` mapstructure:"devices" yaml:"devices,omitempty" json:"devices,omitempty" `
Devices [ ] DeviceRequest ` mapstructure:"devices" yaml:"devices,omitempty" json:"devices,omitempty" `
GenericResources [ ] GenericResource ` mapstructure:"generic_resources" yaml:"generic_resources,omitempty" json:"generic_resources,omitempty" `
GenericResources [ ] GenericResource ` mapstructure:"generic_resources" yaml:"generic_resources,omitempty" json:"generic_resources,omitempty" `
@ -579,7 +619,7 @@ type ServicePortConfig struct {
Mode string ` yaml:",omitempty" json:"mode,omitempty" `
Mode string ` yaml:",omitempty" json:"mode,omitempty" `
HostIP string ` mapstructure:"host_ip" yaml:"host_ip,omitempty" json:"host_ip,omitempty" `
HostIP string ` mapstructure:"host_ip" yaml:"host_ip,omitempty" json:"host_ip,omitempty" `
Target uint32 ` yaml:",omitempty" json:"target,omitempty" `
Target uint32 ` yaml:",omitempty" json:"target,omitempty" `
Published uint32 ` yaml:",omitempty" json:"published,omitempty" `
Published string ` yaml:",omitempty" json:"published,omitempty" `
Protocol string ` yaml:",omitempty" json:"protocol,omitempty" `
Protocol string ` yaml:",omitempty" json:"protocol,omitempty" `
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
@ -613,22 +653,14 @@ func ParsePortConfig(value string) ([]ServicePortConfig, error) {
func convertPortToPortConfig ( port nat . Port , portBindings map [ nat . Port ] [ ] nat . PortBinding ) ( [ ] ServicePortConfig , error ) {
func convertPortToPortConfig ( port nat . Port , portBindings map [ nat . Port ] [ ] nat . PortBinding ) ( [ ] ServicePortConfig , error ) {
var portConfigs [ ] ServicePortConfig
var portConfigs [ ] ServicePortConfig
for _ , binding := range portBindings [ port ] {
for _ , binding := range portBindings [ port ] {
startHostPort , endHostPort , err := nat . ParsePortRange ( binding . HostPort )
if err != nil && binding . HostPort != "" {
return nil , fmt . Errorf ( "invalid hostport binding (%s) for port (%s)" , binding . HostPort , port . Port ( ) )
}
for i := startHostPort ; i <= endHostPort ; i ++ {
portConfigs = append ( portConfigs , ServicePortConfig {
portConfigs = append ( portConfigs , ServicePortConfig {
HostIP : binding . HostIP ,
HostIP : binding . HostIP ,
Protocol : strings . ToLower ( port . Proto ( ) ) ,
Protocol : strings . ToLower ( port . Proto ( ) ) ,
Target : uint32 ( port . Int ( ) ) ,
Target : uint32 ( port . Int ( ) ) ,
Published : uint32 ( i ) ,
Published : binding . HostPort ,
Mode : "ingress" ,
Mode : "ingress" ,
} )
} )
}
}
}
return portConfigs , nil
return portConfigs , nil
}
}
@ -655,16 +687,30 @@ const (
VolumeTypeTmpfs = "tmpfs"
VolumeTypeTmpfs = "tmpfs"
// VolumeTypeNamedPipe is the type for mounting Windows named pipes
// VolumeTypeNamedPipe is the type for mounting Windows named pipes
VolumeTypeNamedPipe = "npipe"
VolumeTypeNamedPipe = "npipe"
// SElinuxShared share the volume content
SElinuxShared = "z"
// SElinuxUnshared label content as private unshared
SElinuxUnshared = "Z"
)
)
// ServiceVolumeBind are options for a service volume of type bind
// ServiceVolumeBind are options for a service volume of type bind
type ServiceVolumeBind struct {
type ServiceVolumeBind struct {
SELinux string ` mapstructure:"selinux" yaml:",omitempty" json:"selinux,omitempty" `
Propagation string ` yaml:",omitempty" json:"propagation,omitempty" `
Propagation string ` yaml:",omitempty" json:"propagation,omitempty" `
CreateHostPath bool ` mapstructure:"create_host_path" yaml:"create_host_path,omitempty" json:"create_host_path,omitempty" `
CreateHostPath bool ` mapstructure:"create_host_path" yaml:"create_host_path,omitempty" json:"create_host_path,omitempty" `
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
Extensions map [ string ] interface { } ` yaml:",inline" json:"-" `
}
}
// SELinux represents the SELinux re-labeling options.
const (
// SELinuxShared option indicates that the bind mount content is shared among multiple containers
SELinuxShared string = "z"
// SELinuxPrivate option indicates that the bind mount content is private and unshared
SELinuxPrivate string = "Z"
)
// Propagation represents the propagation of a mount.
// Propagation represents the propagation of a mount.
const (
const (
// PropagationRPrivate RPRIVATE
// PropagationRPrivate RPRIVATE