Skip to content

Commit cf608fa

Browse files
committed
bump compose-go to v1.20.1
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 426377a commit cf608fa

File tree

9 files changed

+152
-12
lines changed

9 files changed

+152
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
77
github.com/Microsoft/go-winio v0.6.1
88
github.com/buger/goterm v1.0.4
9-
github.com/compose-spec/compose-go v1.20.0
9+
github.com/compose-spec/compose-go v1.20.1
1010
github.com/containerd/console v1.0.3
1111
github.com/containerd/containerd v1.7.7
1212
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
137137
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
138138
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
139139
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
140-
github.com/compose-spec/compose-go v1.20.0 h1:h4ZKOst1EF/DwZp7dWkb+wbTVE4nEyT9Lc89to84Ol4=
141-
github.com/compose-spec/compose-go v1.20.0/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
140+
github.com/compose-spec/compose-go v1.20.1 h1:I6gCMGLl96kEf8XZwaozeTwnNfxA2eVsO46W+5ciTEg=
141+
github.com/compose-spec/compose-go v1.20.1/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM=
142142
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
143143
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
144144
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=

pkg/compose/build.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ import (
3232
"github.com/docker/buildx/util/buildflags"
3333
xprogress "github.com/docker/buildx/util/progress"
3434
"github.com/docker/cli/cli/command"
35-
"github.com/docker/compose/v2/internal/tracing"
36-
"github.com/docker/compose/v2/pkg/api"
37-
"github.com/docker/compose/v2/pkg/progress"
38-
"github.com/docker/compose/v2/pkg/utils"
35+
cliopts "github.com/docker/cli/opts"
3936
"github.com/docker/docker/builder/remotecontext/urlutil"
37+
"github.com/docker/go-units"
4038
bclient "github.com/moby/buildkit/client"
4139
"github.com/moby/buildkit/session"
4240
"github.com/moby/buildkit/session/auth/authprovider"
@@ -46,6 +44,11 @@ import (
4644
specs "github.com/opencontainers/image-spec/specs-go/v1"
4745
"github.com/sirupsen/logrus"
4846

47+
"github.com/docker/compose/v2/internal/tracing"
48+
"github.com/docker/compose/v2/pkg/api"
49+
"github.com/docker/compose/v2/pkg/progress"
50+
"github.com/docker/compose/v2/pkg/utils"
51+
4952
// required to get default driver registered
5053
_ "github.com/docker/buildx/driver/docker"
5154
)
@@ -407,11 +410,24 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
407410
Labels: imageLabels,
408411
NetworkMode: service.Build.Network,
409412
ExtraHosts: service.Build.ExtraHosts.AsList(),
413+
Ulimits: toUlimitOpt(service.Build.Ulimits),
410414
Session: sessionConfig,
411415
Allow: allow,
412416
}, nil
413417
}
414418

419+
func toUlimitOpt(ulimits map[string]*types.UlimitsConfig) *cliopts.UlimitOpt {
420+
ref := map[string]*units.Ulimit{}
421+
for _, limit := range toUlimits(ulimits) {
422+
ref[limit.Name] = &units.Ulimit{
423+
Name: limit.Name,
424+
Hard: limit.Hard,
425+
Soft: limit.Soft,
426+
}
427+
}
428+
return cliopts.NewUlimitOpt(&ref)
429+
}
430+
415431
func flatten(in types.MappingWithEquals) types.Mapping {
416432
out := types.Mapping{}
417433
if len(in) == 0 {

pkg/compose/convergence.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ func (s *composeService) createMobyContainer(ctx context.Context,
623623
}
624624

625625
err = s.injectSecrets(ctx, project, service, created.ID)
626+
if err != nil {
627+
return created, err
628+
}
629+
630+
err = s.injectConfigs(ctx, project, service, created.ID)
626631
return created, err
627632
}
628633

pkg/compose/create.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,14 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
521521
})
522522
}
523523

524-
for name, u := range s.Ulimits {
524+
ulimits := toUlimits(s.Ulimits)
525+
resources.Ulimits = ulimits
526+
return resources
527+
}
528+
529+
func toUlimits(m map[string]*types.UlimitsConfig) []*units.Ulimit {
530+
var ulimits []*units.Ulimit
531+
for name, u := range m {
525532
soft := u.Single
526533
if u.Soft != 0 {
527534
soft = u.Soft
@@ -530,13 +537,13 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
530537
if u.Hard != 0 {
531538
hard = u.Hard
532539
}
533-
resources.Ulimits = append(resources.Ulimits, &units.Ulimit{
540+
ulimits = append(ulimits, &units.Ulimit{
534541
Name: name,
535542
Hard: int64(hard),
536543
Soft: int64(soft),
537544
})
538545
}
539-
return resources
546+
return ulimits
540547
}
541548

542549
func setReservations(reservations *types.Resource, resources *container.Resources) {
@@ -812,6 +819,10 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
812819
return nil, errors.New("Docker Compose does not support configs.*.template_driver")
813820
}
814821

822+
if definedConfig.Environment != "" || definedConfig.Content != "" {
823+
continue
824+
}
825+
815826
bindMount, err := buildMount(p, types.ServiceVolumeConfig{
816827
Type: types.VolumeTypeBind,
817828
Source: definedConfig.File,

pkg/compose/secrets.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje
3939
if !ok {
4040
return fmt.Errorf("environment variable %q required by secret %q is not set", secret.Environment, secret.Name)
4141
}
42-
b, err := createTar(env, config)
42+
b, err := createTar(env, types.FileReferenceConfig(config))
4343
if err != nil {
4444
return err
4545
}
@@ -54,7 +54,37 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje
5454
return nil
5555
}
5656

57-
func createTar(env string, config types.ServiceSecretConfig) (bytes.Buffer, error) {
57+
func (s *composeService) injectConfigs(ctx context.Context, project *types.Project, service types.ServiceConfig, id string) error {
58+
for _, config := range service.Configs {
59+
secret := project.Configs[config.Source]
60+
content := secret.Content
61+
if secret.Environment != "" {
62+
env, ok := project.Environment[secret.Environment]
63+
if !ok {
64+
return fmt.Errorf("environment variable %q required by secret %q is not set", secret.Environment, secret.Name)
65+
}
66+
content = env
67+
}
68+
if content == "" {
69+
continue
70+
}
71+
72+
b, err := createTar(content, types.FileReferenceConfig(config))
73+
if err != nil {
74+
return err
75+
}
76+
77+
err = s.apiClient().CopyToContainer(ctx, id, "/", &b, moby.CopyToContainerOptions{
78+
CopyUIDGID: config.UID != "" || config.GID != "",
79+
})
80+
if err != nil {
81+
return err
82+
}
83+
}
84+
return nil
85+
}
86+
87+
func createTar(env string, config types.FileReferenceConfig) (bytes.Buffer, error) {
5888
value := []byte(env)
5989
b := bytes.Buffer{}
6090
tarWriter := tar.NewWriter(&b)

pkg/e2e/configs_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"testing"
21+
22+
"gotest.tools/v3/icmd"
23+
)
24+
25+
func TestConfigFromEnv(t *testing.T) {
26+
c := NewParallelCLI(t)
27+
28+
t.Run("config from file", func(t *testing.T) {
29+
res := icmd.RunCmd(c.NewDockerComposeCmd(t, "-f", "./fixtures/configs/compose.yaml", "run", "from_file"))
30+
res.Assert(t, icmd.Expected{Out: "This is my config file"})
31+
})
32+
33+
t.Run("config from env", func(t *testing.T) {
34+
res := icmd.RunCmd(c.NewDockerComposeCmd(t, "-f", "./fixtures/configs/compose.yaml", "run", "from_env"),
35+
func(cmd *icmd.Cmd) {
36+
cmd.Env = append(cmd.Env, "CONFIG=config")
37+
})
38+
res.Assert(t, icmd.Expected{Out: "config"})
39+
})
40+
41+
t.Run("config inlined", func(t *testing.T) {
42+
res := icmd.RunCmd(c.NewDockerComposeCmd(t, "-f", "./fixtures/configs/compose.yaml", "run", "inlined"),
43+
func(cmd *icmd.Cmd) {
44+
cmd.Env = append(cmd.Env, "CONFIG=config")
45+
})
46+
res.Assert(t, icmd.Expected{Out: "This is my config"})
47+
})
48+
}

pkg/e2e/fixtures/configs/compose.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
from_env:
3+
image: alpine
4+
configs:
5+
- source: from_env
6+
target: /from_env
7+
command: cat /from_env
8+
9+
from_file:
10+
image: alpine
11+
configs:
12+
- source: from_file
13+
target: /from_file
14+
command: cat /from_file
15+
16+
inlined:
17+
image: alpine
18+
configs:
19+
- source: inlined
20+
target: /inlined
21+
command: cat /inlined
22+
23+
configs:
24+
from_env:
25+
environment: CONFIG
26+
from_file:
27+
file: config.txt
28+
inlined:
29+
content: This is my $CONFIG

pkg/e2e/fixtures/configs/config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is my config file

0 commit comments

Comments
 (0)