No need to support service `container_name` in this PR, will do separately, minor cleanup

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
Guillaume Tardif 2020-12-14 18:03:25 +01:00
parent 8259604074
commit 8eb9733914
3 changed files with 3 additions and 18 deletions

View File

@ -61,10 +61,6 @@ func (s *composeService) ensureService(ctx context.Context, project *types.Proje
for i := 0; i < missing; i++ {
number := next + i
name := fmt.Sprintf("%s_%s_%d", project.Name, service.Name, number)
if len(service.ContainerName) > 0 {
name = service.ContainerName
}
eg.Go(func() error {
return s.createContainer(ctx, project, service, name, number)
})

View File

@ -105,10 +105,7 @@ func getContainerCreateOptions(p *types.Project, s types.ServiceConfig, number i
labels[projectLabel] = p.Name
labels[serviceLabel] = s.Name
labels[versionLabel] = ComposeVersion
if _, ok := s.Labels[oneoffLabel]; ok {
labels[oneoffLabel] = s.Labels[oneoffLabel]
labels[slugLabel] = s.Labels[slugLabel]
} else {
if _, ok := s.Labels[oneoffLabel]; !ok {
labels[oneoffLabel] = "False"
}
labels[configHashLabel] = hash

View File

@ -34,25 +34,19 @@ func (s *composeService) CreateOneOffContainer(ctx context.Context, project *typ
if err != nil {
return "", err
}
err = s.ensureImagesExists(ctx, project)
if err != nil {
if err = s.ensureImagesExists(ctx, project); err != nil {
return "", err
}
if err := s.ensureProjectNetworks(ctx, project); err != nil {
return "", err
}
if err := s.ensureProjectVolumes(ctx, project); err != nil {
return "", err
}
// ensure required services are up and running before creating the oneoff container
err = s.ensureRequiredServices(ctx, project, service)
if err != nil {
if err = s.ensureRequiredServices(ctx, project, service); err != nil {
return "", err
}
//apply options to service config
updateOneOffServiceConfig(&service, project.Name, opts)
err = s.createContainer(ctx, project, service, service.ContainerName, 1)
@ -120,10 +114,8 @@ func (s *composeService) Run(ctx context.Context, container string, detach bool)
func updateOneOffServiceConfig(service *types.ServiceConfig, projectName string, opts compose.RunOptions) {
if len(opts.Command) > 0 {
// custom command to run
service.Command = opts.Command
}
//service.Environment = opts.Environment
slug := moby.GenerateRandomID()
service.Scale = 1
service.ContainerName = fmt.Sprintf("%s_%s_run_%s", projectName, service.Name, moby.TruncateID(slug))