mirror of https://github.com/docker/compose.git
cleanup
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
515f3ba1e7
commit
747d2de397
|
@ -131,7 +131,8 @@ func getImageName(service types.ServiceConfig, projectName string) string {
|
||||||
return imageName
|
return imageName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project, s types.ServiceConfig, number int, inherit *moby.Container, autoRemove bool) (*container.Config, *container.HostConfig, *network.NetworkingConfig, error) {
|
func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project, service types.ServiceConfig, number int, inherit *moby.Container,
|
||||||
|
autoRemove bool) (*container.Config, *container.HostConfig, *network.NetworkingConfig, error) {
|
||||||
|
|
||||||
hash, err := jsonHash(s)
|
hash, err := jsonHash(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -139,14 +140,14 @@ func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := map[string]string{}
|
labels := map[string]string{}
|
||||||
for k, v := range s.Labels {
|
for k, v := range service.Labels {
|
||||||
labels[k] = v
|
labels[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
labels[projectLabel] = p.Name
|
labels[projectLabel] = p.Name
|
||||||
labels[serviceLabel] = s.Name
|
labels[serviceLabel] = service.Name
|
||||||
labels[versionLabel] = ComposeVersion
|
labels[versionLabel] = ComposeVersion
|
||||||
if _, ok := s.Labels[oneoffLabel]; !ok {
|
if _, ok := service.Labels[oneoffLabel]; !ok {
|
||||||
labels[oneoffLabel] = "False"
|
labels[oneoffLabel] = "False"
|
||||||
}
|
}
|
||||||
labels[configHashLabel] = hash
|
labels[configHashLabel] = hash
|
||||||
|
@ -158,33 +159,30 @@ func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project
|
||||||
runCmd strslice.StrSlice
|
runCmd strslice.StrSlice
|
||||||
entrypoint strslice.StrSlice
|
entrypoint strslice.StrSlice
|
||||||
)
|
)
|
||||||
if len(s.Command) > 0 {
|
if len(service.Command) > 0 {
|
||||||
runCmd = strslice.StrSlice(s.Command)
|
runCmd = strslice.StrSlice(service.Command)
|
||||||
}
|
}
|
||||||
if len(s.Entrypoint) > 0 {
|
if len(service.Entrypoint) > 0 {
|
||||||
entrypoint = strslice.StrSlice(s.Entrypoint)
|
entrypoint = strslice.StrSlice(service.Entrypoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tty = s.Tty
|
tty = service.Tty
|
||||||
stdinOpen = s.StdinOpen
|
stdinOpen = service.StdinOpen
|
||||||
attachStdin = false
|
attachStdin = false
|
||||||
)
|
)
|
||||||
image := getImageName(s, p.Name)
|
image := getImageName(service, p.Name)
|
||||||
imgInspect, _, err := cs.apiClient.ImageInspectWithRaw(ctx, image)
|
imgInspect, _, err := s.apiClient.ImageInspectWithRaw(ctx, image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
mountOptions, err := buildContainerMountOptions(*p, s, imgInspect, inherit)
|
mountOptions, err := buildContainerMountOptions(*p, service, imgInspect, inherit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
volumeMounts := map[string]struct{}{}
|
volumeMounts := map[string]struct{}{}
|
||||||
binds := []string{}
|
binds := []string{}
|
||||||
for _, m := range mountOptions {
|
for _, m := range mountOptions {
|
||||||
if m.Type == mount.TypeVolume {
|
|
||||||
|
|
||||||
}
|
|
||||||
if m.Type == mount.TypeVolume {
|
if m.Type == mount.TypeVolume {
|
||||||
volumeMounts[m.Target] = struct{}{}
|
volumeMounts[m.Target] = struct{}{}
|
||||||
if m.Source != "" {
|
if m.Source != "" {
|
||||||
|
@ -194,10 +192,10 @@ func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
containerConfig := container.Config{
|
containerConfig := container.Config{
|
||||||
Hostname: s.Hostname,
|
Hostname: service.Hostname,
|
||||||
Domainname: s.DomainName,
|
Domainname: service.DomainName,
|
||||||
User: s.User,
|
User: service.User,
|
||||||
ExposedPorts: buildContainerPorts(s),
|
ExposedPorts: buildContainerPorts(service),
|
||||||
Tty: tty,
|
Tty: tty,
|
||||||
OpenStdin: stdinOpen,
|
OpenStdin: stdinOpen,
|
||||||
StdinOnce: true,
|
StdinOnce: true,
|
||||||
|
@ -206,21 +204,21 @@ func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
Cmd: runCmd,
|
Cmd: runCmd,
|
||||||
Image: image,
|
Image: image,
|
||||||
WorkingDir: s.WorkingDir,
|
WorkingDir: service.WorkingDir,
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
NetworkDisabled: s.NetworkMode == "disabled",
|
NetworkDisabled: service.NetworkMode == "disabled",
|
||||||
MacAddress: s.MacAddress,
|
MacAddress: service.MacAddress,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
StopSignal: s.StopSignal,
|
StopSignal: service.StopSignal,
|
||||||
Env: convert.ToMobyEnv(s.Environment),
|
Env: convert.ToMobyEnv(service.Environment),
|
||||||
Healthcheck: convert.ToMobyHealthCheck(s.HealthCheck),
|
Healthcheck: convert.ToMobyHealthCheck(service.HealthCheck),
|
||||||
// Volumes: // FIXME unclear to me the overlap with HostConfig.Mounts
|
// Volumes: // FIXME unclear to me the overlap with HostConfig.Mounts
|
||||||
Volumes: volumeMounts,
|
Volumes: volumeMounts,
|
||||||
StopTimeout: convert.ToSeconds(s.StopGracePeriod),
|
StopTimeout: convert.ToSeconds(service.StopGracePeriod),
|
||||||
}
|
}
|
||||||
|
|
||||||
// append secrets mounts
|
// append secrets mounts
|
||||||
bindMounts, err := buildContainerSecretMounts(*p, s, imgInspect, inherit)
|
bindMounts, err := buildContainerSecretMounts(*p, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -229,26 +227,26 @@ func (cs *composeService) getCreateOptions(ctx context.Context, p *types.Project
|
||||||
bindMounts = append(bindMounts, m)
|
bindMounts = append(bindMounts, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portBindings := buildContainerPortBindingOptions(s)
|
portBindings := buildContainerPortBindingOptions(service)
|
||||||
|
|
||||||
resources := getDeployResources(s)
|
resources := getDeployResources(service)
|
||||||
networkMode := getNetworkMode(p, s)
|
networkMode := getNetworkMode(p, service)
|
||||||
hostConfig := container.HostConfig{
|
hostConfig := container.HostConfig{
|
||||||
AutoRemove: autoRemove,
|
AutoRemove: autoRemove,
|
||||||
Binds: binds,
|
Binds: binds,
|
||||||
Mounts: bindMounts,
|
Mounts: bindMounts,
|
||||||
CapAdd: strslice.StrSlice(s.CapAdd),
|
CapAdd: strslice.StrSlice(service.CapAdd),
|
||||||
CapDrop: strslice.StrSlice(s.CapDrop),
|
CapDrop: strslice.StrSlice(service.CapDrop),
|
||||||
NetworkMode: networkMode,
|
NetworkMode: networkMode,
|
||||||
Init: s.Init,
|
Init: service.Init,
|
||||||
ReadonlyRootfs: s.ReadOnly,
|
ReadonlyRootfs: service.ReadOnly,
|
||||||
// ShmSize: , TODO
|
// ShmSize: , TODO
|
||||||
Sysctls: s.Sysctls,
|
Sysctls: service.Sysctls,
|
||||||
PortBindings: portBindings,
|
PortBindings: portBindings,
|
||||||
Resources: resources,
|
Resources: resources,
|
||||||
}
|
}
|
||||||
|
|
||||||
networkConfig := buildDefaultNetworkConfig(s, networkMode, getContainerName(p.Name, s, number))
|
networkConfig := buildDefaultNetworkConfig(service, networkMode, getContainerName(p.Name, service, number))
|
||||||
return &containerConfig, &hostConfig, networkConfig, nil
|
return &containerConfig, &hostConfig, networkConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +317,7 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if img.ContainerConfig != nil {
|
if img.ContainerConfig != nil {
|
||||||
for k, _ := range img.ContainerConfig.Volumes {
|
for k := range img.ContainerConfig.Volumes {
|
||||||
|
|
||||||
mount, err := buildMount(p, types.ServiceVolumeConfig{
|
mount, err := buildMount(p, types.ServiceVolumeConfig{
|
||||||
Type: types.VolumeTypeVolume,
|
Type: types.VolumeTypeVolume,
|
||||||
|
@ -346,7 +344,7 @@ func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby
|
||||||
return values, nil
|
return values, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildContainerSecretMounts(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
|
func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount.Mount, error) {
|
||||||
var mounts = map[string]mount.Mount{}
|
var mounts = map[string]mount.Mount{}
|
||||||
|
|
||||||
secretsDir := "/run/secrets"
|
secretsDir := "/run/secrets"
|
||||||
|
|
|
@ -38,12 +38,3 @@ func contains(slice []string, item string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexOf(slice []string, item string) int {
|
|
||||||
for i, v := range slice {
|
|
||||||
if v == item {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue