Skip to content

Commit b96b544

Browse files
Merge branch 'v2' into 8768-avoid-pulling-same-image-multiple-times
2 parents 293cf21 + 6fe34c4 commit b96b544

File tree

12 files changed

+116
-25
lines changed

12 files changed

+116
-25
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ jobs:
195195
with:
196196
name: compose
197197
path: ${{ env.DESTDIR }}
198+
-
199+
name: Create checksums
200+
working-directory: ${{ env.DESTDIR }}
201+
run: |
202+
find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# .*/# #' > checksums.txt
203+
shasum -a 256 -U -c checksums.txt
198204
-
199205
name: License
200206
run: cp packaging/* ${{ env.DESTDIR }}/

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ COPY --link --from=build /usr/bin/docker-compose /docker-compose.exe
167167
FROM binary-$TARGETOS AS binary
168168

169169
FROM --platform=$BUILDPLATFORM alpine AS releaser
170-
RUN apk add --no-cache file perl-utils
171170
WORKDIR /work
172171
ARG TARGETOS
173172
ARG TARGETARCH
@@ -177,8 +176,7 @@ RUN --mount=from=binary \
177176
# TODO: should just use standard arch
178177
TARGETARCH=$([ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH"); \
179178
TARGETARCH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH"); \
180-
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')" && \
181-
(cd /out ; for f in *; do shasum --binary --algorithm 256 $f | tee -a /out/checksums.txt > $f.sha256; done)
179+
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')"
182180

183181
FROM scratch AS release
184182
COPY --from=releaser /out/ /

cmd/compose/compose.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
dockercli "github.com/docker/cli/cli"
3333
"github.com/docker/cli/cli-plugins/manager"
3434
"github.com/docker/cli/cli/command"
35+
"github.com/docker/cli/cli/flags"
36+
"github.com/docker/docker/client"
3537
"github.com/morikuni/aec"
3638
"github.com/pkg/errors"
3739
"github.com/sirupsen/logrus"
@@ -291,6 +293,18 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command {
291293
if err != nil {
292294
return err
293295
}
296+
297+
// Reset DockerCli and APIClient to get possible `DOCKER_HOST` and/or `DOCKER_CONTEXT` loaded from environment file.
298+
err = dockerCli.Apply(func(cli *command.DockerCli) error {
299+
return cli.Initialize(flags.NewClientOptions(),
300+
command.WithInitializeClient(func(_ *command.DockerCli) (client.APIClient, error) {
301+
return nil, nil
302+
}))
303+
})
304+
if err != nil {
305+
return err
306+
}
307+
294308
parent := cmd.Root()
295309
if parent != nil {
296310
parentPrerun := parent.PersistentPreRunE
@@ -383,8 +397,10 @@ func setEnvWithDotEnv(prjOpts *projectOptions) error {
383397
return err
384398
}
385399
for k, v := range envFromFile {
386-
if err := os.Setenv(k, v); err != nil { // overwrite the process env with merged OS + env file results
387-
return err
400+
if _, ok := os.LookupEnv(k); !ok { // Precedence to OS Env
401+
if err := os.Setenv(k, v); err != nil {
402+
return err
403+
}
388404
}
389405
}
390406
return nil

docker-bake.hcl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ target "binary-cross" {
100100
"linux/arm/v7",
101101
"linux/arm64",
102102
"linux/ppc64le",
103+
"linux/riscv64",
103104
"linux/s390x",
104-
"windows/amd64"
105+
"windows/amd64",
106+
"windows/arm64"
105107
]
106108
}
107109

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AlecAivazis/survey/v2 v2.3.5
77
github.com/buger/goterm v1.0.4
88
github.com/cnabio/cnab-to-oci v0.3.6
9-
github.com/compose-spec/compose-go v1.4.0
9+
github.com/compose-spec/compose-go v1.5.0
1010
github.com/containerd/console v1.0.3
1111
github.com/containerd/containerd v1.6.8
1212
github.com/distribution/distribution/v3 v3.0.0-20220729163034-26163d82560f
@@ -19,7 +19,7 @@ require (
1919
github.com/golang/mock v1.6.0
2020
github.com/hashicorp/go-multierror v1.1.1
2121
github.com/hashicorp/go-version v1.6.0
22-
github.com/mattn/go-isatty v0.0.14
22+
github.com/mattn/go-isatty v0.0.16
2323
github.com/mattn/go-shellwords v1.0.12
2424
github.com/moby/buildkit v0.10.3
2525
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
@@ -111,7 +111,7 @@ require (
111111
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
112112
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
113113
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
114-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
114+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
115115
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
116116
golang.org/x/text v0.3.7 // indirect
117117
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC
286286
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
287287
github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
288288
github.com/compose-spec/compose-go v1.2.1/go.mod h1:pAy7Mikpeft4pxkFU565/DRHEbDfR84G6AQuiL+Hdg8=
289-
github.com/compose-spec/compose-go v1.4.0 h1:zaYVAZ6lIByr7Jffi20AabfeUwcTrdXfH3X1R5HEm+g=
290-
github.com/compose-spec/compose-go v1.4.0/go.mod h1:l7RUULbFFLzlQHuxtJr7SVLyWdqEpbJEGTWCgcu6Eqw=
289+
github.com/compose-spec/compose-go v1.5.0 h1:yOmYpIm13pYt2o+oKVe/JAD6o2Tv+eUyOcRhf0qF4fA=
290+
github.com/compose-spec/compose-go v1.5.0/go.mod h1:l7RUULbFFLzlQHuxtJr7SVLyWdqEpbJEGTWCgcu6Eqw=
291291
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
292292
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
293293
github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
@@ -971,8 +971,9 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
971971
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
972972
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
973973
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
974-
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
975974
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
975+
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
976+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
976977
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
977978
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
978979
github.com/mattn/go-shellwords v1.0.6/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
@@ -1795,8 +1796,9 @@ golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBc
17951796
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
17961797
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
17971798
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1798-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
17991799
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1800+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
1801+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18001802
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
18011803
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
18021804
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

pkg/api/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/compose-spec/compose-go/types"
2323
)
2424

25+
var _ Service = &ServiceProxy{}
26+
2527
// ServiceProxy implements Service by delegating to implementation functions. This allows lazy init and per-method overrides
2628
type ServiceProxy struct {
2729
BuildFn func(ctx context.Context, project *types.Project, options BuildOptions) error
@@ -59,8 +61,6 @@ func NewServiceProxy() *ServiceProxy {
5961
// Interceptor allow to customize the compose types.Project before the actual Service method is executed
6062
type Interceptor func(ctx context.Context, project *types.Project)
6163

62-
var _ Service = &ServiceProxy{}
63-
6464
// WithService configure proxy to use specified Service as delegate
6565
func (s *ServiceProxy) WithService(service Service) *ServiceProxy {
6666
s.BuildFn = service.Build

pkg/compose/convergence.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ func shouldWaitForDependency(serviceName string, dependencyConfig types.ServiceD
352352
return false, nil
353353
}
354354
if service, err := project.GetService(serviceName); err != nil {
355+
for _, ds := range project.DisabledServices {
356+
if ds.Name == serviceName {
357+
// don't wait for disabled service (--no-deps)
358+
return false, nil
359+
}
360+
}
355361
return false, err
356362
} else if service.Scale == 0 {
357363
// don't wait for the dependency which configured to have 0 containers running

pkg/compose/create.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ func prepareNetworks(project *types.Project) {
146146
}
147147

148148
func prepareServicesDependsOn(p *types.Project) error {
149+
allServices := types.Project{}
150+
allServices.Services = p.AllServices()
151+
149152
for i, service := range p.Services {
150153
var dependencies []string
151154
networkDependency := getDependentServiceFromMode(service.NetworkMode)
@@ -178,20 +181,24 @@ func prepareServicesDependsOn(p *types.Project) error {
178181
dependencies = append(dependencies, strings.Split(link, ":")[0])
179182
}
180183

184+
for d := range service.DependsOn {
185+
dependencies = append(dependencies, d)
186+
}
187+
181188
if len(dependencies) == 0 {
182189
continue
183190
}
184-
if service.DependsOn == nil {
185-
service.DependsOn = make(types.DependsOnConfig)
186-
}
187191

188192
// Verify dependencies exist in the project, whether disabled or not
189-
projAllServices := types.Project{}
190-
projAllServices.Services = p.AllServices()
191-
deps, err := projAllServices.GetServices(dependencies...)
193+
deps, err := allServices.GetServices(dependencies...)
192194
if err != nil {
193195
return err
194196
}
197+
198+
if service.DependsOn == nil {
199+
service.DependsOn = make(types.DependsOnConfig)
200+
}
201+
195202
for _, d := range deps {
196203
if _, ok := service.DependsOn[d.Name]; !ok {
197204
service.DependsOn[d.Name] = types.ServiceDependency{

pkg/e2e/compose_environment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestEnvPriority(t *testing.T) {
3434
})
3535

3636
// Full options activated
37-
// 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From environment patched by --env-file)
37+
// 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From OS Environment)
3838
// 2. Compose File (service::environment section)
3939
// 3. Compose File (service::env_file section file)
4040
// 4. Container Image ENV directive
@@ -45,7 +45,7 @@ func TestEnvPriority(t *testing.T) {
4545
"run", "--rm", "-e", "WHEREAMI", "env-compose-priority")
4646
cmd.Env = append(cmd.Env, "WHEREAMI=shell")
4747
res := icmd.RunCmd(cmd)
48-
assert.Equal(t, strings.TrimSpace(res.Stdout()), "override")
48+
assert.Equal(t, strings.TrimSpace(res.Stdout()), "shell")
4949
})
5050

5151
// Full options activated
@@ -63,7 +63,7 @@ func TestEnvPriority(t *testing.T) {
6363
})
6464

6565
// No Compose file, all other options
66-
// 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From environment patched by --env-file)
66+
// 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From OS Environment)
6767
// 2. Compose File (service::environment section)
6868
// 3. Compose File (service::env_file section file)
6969
// 4. Container Image ENV directive
@@ -74,7 +74,7 @@ func TestEnvPriority(t *testing.T) {
7474
"run", "--rm", "-e", "WHEREAMI", "env-compose-priority")
7575
cmd.Env = append(cmd.Env, "WHEREAMI=shell")
7676
res := icmd.RunCmd(cmd)
77-
assert.Equal(t, strings.TrimSpace(res.Stdout()), "override")
77+
assert.Equal(t, strings.TrimSpace(res.Stdout()), "shell")
7878
})
7979

8080
// No Compose file, all other options with env variable from OS environment

0 commit comments

Comments
 (0)