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

Commit 416af59

Browse files
committed
Fix building compose files with absolute build context / Dockerfile
Signed-off-by: Guillaume Tardif <[email protected]>
1 parent 04c78c2 commit 416af59

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
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-20210503135708-e8ee37c1478c
20+
github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b
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-20210503135708-e8ee37c1478c h1:XDrhClIbE/zCDU4KWCYSYmceYZj5EBn3DMhQ7hVvyUs=
312-
github.com/compose-spec/compose-go v0.0.0-20210503135708-e8ee37c1478c/go.mod h1:6eIT9U2OgdHmkRD6szmqatCrWWEEUSwl/j2iJYH4jLo=
311+
github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b h1:0MPA42m4n8VGsCld8hWmeRYeblPrgRDbiXPvRnjWoLY=
312+
github.com/compose-spec/compose-go v0.0.0-20210505145624-6dcd3d18b38b/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/e2e/compose/compose_build_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package e2e
1818

1919
import (
20+
"io/ioutil"
2021
"net/http"
22+
"os"
23+
"path/filepath"
2124
"strings"
2225
"testing"
2326
"time"
@@ -106,3 +109,41 @@ func TestLocalComposeBuild(t *testing.T) {
106109
c.RunDockerCmd("rmi", "custom-nginx")
107110
})
108111
}
112+
113+
func TestLocalComposeBuildStaticDockerfilePath(t *testing.T) {
114+
c := NewParallelE2eCLI(t, binDir)
115+
116+
t.Run("build ddev-style compose files", func(t *testing.T) {
117+
dir, err := ioutil.TempDir("", "ddev")
118+
assert.NilError(t, err)
119+
defer os.RemoveAll(dir) //nolint:errcheck
120+
121+
assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "docker-compose.yml"), []byte(`services:
122+
service1:
123+
build:
124+
context: `+dir+`/service1
125+
dockerfile: Dockerfile
126+
service2:
127+
build:
128+
context: `+dir+`/service2
129+
dockerfile: `+dir+`/service2/Dockerfile
130+
`), 0644))
131+
132+
assert.NilError(t, os.Mkdir(filepath.Join(dir, "service1"), 0700))
133+
assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service1", "Dockerfile"), []byte(`FROM alpine
134+
RUN echo "hello"
135+
`), 0644))
136+
137+
assert.NilError(t, os.Mkdir(filepath.Join(dir, "service2"), 0700))
138+
assert.NilError(t, ioutil.WriteFile(filepath.Join(dir, "service2", "Dockerfile"), []byte(`FROM alpine
139+
RUN echo "world"
140+
`), 0644))
141+
142+
res := c.RunDockerCmd("compose", "-f", filepath.Join(dir, "docker-compose.yml"), "build")
143+
144+
res.Assert(t, icmd.Expected{Out: `RUN echo "hello"`})
145+
res.Assert(t, icmd.Expected{Out: `RUN echo "world"`})
146+
147+
c.RunDockerCmd("compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down", "--rmi", "all")
148+
})
149+
}

0 commit comments

Comments
 (0)