Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit da6cb7c

Browse files
authored
Merge pull request #1581 from gtardif/fix_down_no_composefile
Fix down not working if run from a different folder than up, because container labels stored relative paths
2 parents 92920a0 + cc0423d commit da6cb7c

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/awslabs/goformation/v4 v4.15.6
1818
github.com/buger/goterm v1.0.0
1919
github.com/cnabio/cnab-to-oci v0.3.1-beta1
20-
github.com/compose-spec/compose-go v0.0.0-20210421142148-66b18e67d2c0
20+
github.com/compose-spec/compose-go v0.0.0-20210422124345-d4bf0e1bfea5
2121
github.com/containerd/console v1.0.1
2222
github.com/containerd/containerd v1.4.3
2323
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
308308
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
309309
github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
310310
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
311-
github.com/compose-spec/compose-go v0.0.0-20210421142148-66b18e67d2c0 h1:aoUSQGFmWi8dn1OfT4H5Mx48u5wHt+n07nLFw5j1JXs=
312-
github.com/compose-spec/compose-go v0.0.0-20210421142148-66b18e67d2c0/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
311+
github.com/compose-spec/compose-go v0.0.0-20210422124345-d4bf0e1bfea5 h1:uR5dDxz7FboGxh2YjlMJJBOc7RPl87rbV80VV7WJ9N0=
312+
github.com/compose-spec/compose-go v0.0.0-20210422124345-d4bf0e1bfea5/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
313313
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
314314
github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59/go.mod h1:pA0z1pT8KYB3TCXK/ocprsh7MAkoW8bZVzPdih9snmM=
315315
github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340 h1:9atoWyI9RtXFwf7UDbme/6M8Ud0rFrx+Q3ZWgSnsxtw=

local/compose/create.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
280280
return nil, nil, nil, err
281281
}
282282

283-
shmSize := int64(0)
284-
if service.ShmSize != "" {
285-
shmSize, err = strconv.ParseInt(service.ShmSize, 10, 64)
286-
if err != nil {
287-
return nil, nil, nil, err
288-
}
289-
}
290-
291283
tmpfs := map[string]string{}
292284
for _, t := range service.Tmpfs {
293285
if arr := strings.SplitN(t, ":", 2); len(arr) > 1 {
@@ -316,7 +308,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
316308
IpcMode: container.IpcMode(ipcmode),
317309
ReadonlyRootfs: service.ReadOnly,
318310
RestartPolicy: getRestartPolicy(service),
319-
ShmSize: shmSize,
311+
ShmSize: int64(service.ShmSize),
320312
Sysctls: service.Sysctls,
321313
PortBindings: portBindings,
322314
Resources: resources,

local/compose/down.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22-
"path/filepath"
2322
"strings"
2423
"time"
2524

@@ -208,12 +207,7 @@ func (s *composeService) projectFromContainerLabels(containers Containers, proje
208207
}
209208

210209
func loadProjectOptionsFromLabels(c moby.Container) (*cli.ProjectOptions, error) {
211-
var configFiles []string
212-
relativePathConfigFiles := strings.Split(c.Labels[configFilesLabel], ",")
213-
for _, c := range relativePathConfigFiles {
214-
configFiles = append(configFiles, filepath.Base(c))
215-
}
216-
return cli.NewProjectOptions(configFiles,
210+
return cli.NewProjectOptions(strings.Split(c.Labels[configFilesLabel], ","),
217211
cli.WithOsEnv,
218212
cli.WithWorkingDirectory(c.Labels[workingDirLabel]),
219213
cli.WithName(c.Labels[projectLabel]))

local/compose/kill_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func testContainer(service string, id string) apitypes.Container {
8383
}
8484

8585
func containerLabels(service string) map[string]string {
86-
return map[string]string{serviceLabel: service, configFilesLabel: "testdata/docker-compose.yml", workingDirLabel: "testdata", projectLabel: testProject}
86+
return map[string]string{serviceLabel: service, configFilesLabel: "docker-compose.yml", workingDirLabel: "testdata", projectLabel: testProject}
8787
}
8888

8989
func anyCancellableContext() gomock.Matcher {

local/e2e/compose/compose_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ func TestComposePull(t *testing.T) {
141141
assert.Assert(t, strings.Contains(output, "another Pulled"))
142142
}
143143

144+
func TestDownComposefileInParentFolder(t *testing.T) {
145+
146+
c := NewParallelE2eCLI(t, binDir)
147+
148+
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
149+
projectName := strings.TrimPrefix(tmpFolder, "fixtures/simple-composefile/")
150+
defer os.Remove(tmpFolder) //nolint: errcheck
151+
assert.NilError(t, err)
152+
153+
res := c.RunDockerCmd("compose", "--project-directory", tmpFolder, "up", "-d")
154+
res.Assert(t, icmd.Expected{Err: "Started", ExitCode: 0})
155+
156+
res = c.RunDockerCmd("compose", "-p", projectName, "down")
157+
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
158+
}
159+
144160
func TestAttachRestart(t *testing.T) {
145161
c := NewParallelE2eCLI(t, binDir)
146162

0 commit comments

Comments
 (0)