Skip to content

Commit 113fb67

Browse files
authored
schema: add support for tmpfs.mode in mount definition (docker#10031)
See compose-spec/compose-go#325 for the acutal spec change. This propagates it to the Engine API object and adds an E2E test via Cucumber 🥒 Fixes docker#9873. Signed-off-by: Milas Bowman <[email protected]>
1 parent b9e5f9e commit 113fb67

File tree

8 files changed

+59
-533
lines changed

8 files changed

+59
-533
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Volume: tmpfs
2+
3+
Background:
4+
Given a compose file
5+
"""
6+
services:
7+
svc:
8+
image: busybox
9+
volumes:
10+
- type: tmpfs
11+
target: /volumes/tmpfs
12+
tmpfs:
13+
size: 2M
14+
mode: 0o647
15+
"""
16+
17+
Scenario: tmpfs Permissions Set
18+
When I run "compose run --rm svc stat -c "%a" /volumes/tmpfs"
19+
Then the output contains "647"
20+
21+
Scenario: tmpfs Size Set
22+
When I run "compose run --rm svc sh -c 'df /volumes/tmpfs | tail -n1 | awk '"'"'{print $4}'"'"'' "
23+
Then the output contains "2048"

e2e/cucumber_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import (
2626

2727
"github.com/cucumber/godog"
2828
"github.com/cucumber/godog/colors"
29-
"github.com/docker/compose/v2/pkg/e2e"
29+
"github.com/mattn/go-shellwords"
3030
"gotest.tools/v3/icmd"
31+
32+
"github.com/docker/compose/v2/pkg/e2e"
3133
)
3234

3335
func TestCucumber(t *testing.T) {
@@ -113,8 +115,12 @@ func (th *testHelper) exitCodeIs(exitCode int) error {
113115
}
114116

115117
func (th *testHelper) runComposeCommand(command string) error {
116-
commandArgs := []string{"-f", "-"}
117-
commandArgs = append(commandArgs, strings.Split(command, " ")...)
118+
commandArgs, err := shellwords.Parse(command)
119+
if err != nil {
120+
return err
121+
}
122+
commandArgs = append([]string{"-f", "-"}, commandArgs...)
123+
118124
cmd := th.CLI.NewDockerComposeCmd(th.T, commandArgs...)
119125
cmd.Stdin = strings.NewReader(th.ComposeFile)
120126
res := icmd.RunCmd(cmd)

e2e/go.mod

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@ require (
1515
require (
1616
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
1717
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
18-
github.com/Masterminds/semver v1.5.0 // indirect
1918
github.com/Microsoft/go-winio v0.5.2 // indirect
2019
github.com/beorn7/perks v1.0.1 // indirect
2120
github.com/buger/goterm v1.0.4 // indirect
2221
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
2322
github.com/cespare/xxhash/v2 v2.1.2 // indirect
24-
github.com/cnabio/cnab-go v0.23.0 // indirect
25-
github.com/cnabio/cnab-to-oci v0.3.1-beta1 // indirect
26-
github.com/compose-spec/compose-go v1.7.0 // indirect
23+
github.com/compose-spec/compose-go v1.8.0 // indirect
2724
github.com/containerd/console v1.0.3 // indirect
2825
github.com/containerd/containerd v1.6.10 // indirect
2926
github.com/containerd/continuity v0.3.0 // indirect
3027
github.com/containerd/ttrpc v1.1.0 // indirect
3128
github.com/containerd/typeurl v1.0.2 // indirect
3229
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
3330
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
34-
github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 // indirect
3531
github.com/davecgh/go-spew v1.1.1 // indirect
3632
github.com/distribution/distribution/v3 v3.0.0-20221108081720-e9a25da7a47e // indirect
3733
github.com/docker/buildx v0.9.1 // indirect
@@ -74,7 +70,7 @@ require (
7470
github.com/mattn/go-colorable v0.1.12 // indirect
7571
github.com/mattn/go-isatty v0.0.16 // indirect
7672
github.com/mattn/go-runewidth v0.0.14 // indirect
77-
github.com/mattn/go-shellwords v1.0.12 // indirect
73+
github.com/mattn/go-shellwords v1.0.12
7874
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
7975
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
8076
github.com/miekg/pkcs11 v1.1.1 // indirect
@@ -100,8 +96,6 @@ require (
10096
github.com/prometheus/client_model v0.2.0 // indirect
10197
github.com/prometheus/common v0.32.1 // indirect
10298
github.com/prometheus/procfs v0.7.3 // indirect
103-
github.com/qri-io/jsonpointer v0.1.1 // indirect
104-
github.com/qri-io/jsonschema v0.2.2-0.20210831022256-780655b2ba0e // indirect
10599
github.com/rivo/uniseg v0.2.0 // indirect
106100
github.com/serialx/hashring v0.0.0-20190422032157-8b2912629002 // indirect
107101
github.com/sirupsen/logrus v1.9.0 // indirect
@@ -154,13 +148,10 @@ require (
154148
)
155149

156150
require (
157-
github.com/gobuffalo/logger v1.0.3 // indirect
158-
github.com/gobuffalo/packd v1.0.0 // indirect
159-
github.com/gobuffalo/packr/v2 v2.8.0 // indirect
160-
github.com/karrick/godirwalk v1.15.3 // indirect
161-
github.com/markbates/errx v1.1.0 // indirect
162-
github.com/markbates/oncer v1.0.0 // indirect
163-
github.com/markbates/safe v1.0.1 // indirect
151+
github.com/hashicorp/hcl v1.0.0 // indirect
152+
github.com/magiconair/properties v1.8.0 // indirect
153+
github.com/spf13/cast v1.3.0 // indirect
154+
github.com/spf13/jwalterweatherman v1.0.0 // indirect
164155
)
165156

166157
replace (

e2e/go.sum

Lines changed: 3 additions & 497 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.6
77
github.com/buger/goterm v1.0.4
8-
github.com/compose-spec/compose-go v1.7.0
8+
github.com/compose-spec/compose-go v1.8.0
99
github.com/containerd/console v1.0.3
1010
github.com/containerd/containerd v1.6.10
1111
github.com/distribution/distribution/v3 v3.0.0-20221108081720-e9a25da7a47e

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
115115
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
116116
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
117117
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
118-
github.com/compose-spec/compose-go v1.7.0 h1:70HzJ/g81pdxF1ao9L7W2fgje/9FxNKH/davgvusEKc=
119-
github.com/compose-spec/compose-go v1.7.0/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
118+
github.com/compose-spec/compose-go v1.8.0 h1:fD2b8YDZVcSicKM0EEXsUdy+97PKza6+bjuXfSloNdM=
119+
github.com/compose-spec/compose-go v1.8.0/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
120120
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
121121
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
122122
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=

pkg/compose/create.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"strconv"
2828
"strings"
2929

30-
"github.com/compose-spec/compose-go/types"
3130
moby "github.com/docker/docker/api/types"
3231
"github.com/docker/docker/api/types/blkiodev"
3332
"github.com/docker/docker/api/types/container"
@@ -42,6 +41,8 @@ import (
4241
"github.com/pkg/errors"
4342
"github.com/sirupsen/logrus"
4443

44+
"github.com/compose-spec/compose-go/types"
45+
4546
"github.com/docker/compose/v2/pkg/api"
4647
"github.com/docker/compose/v2/pkg/progress"
4748
"github.com/docker/compose/v2/pkg/utils"
@@ -989,7 +990,7 @@ func buildMountOptions(project types.Project, volume types.ServiceVolumeConfig)
989990
logrus.Warnf("mount of type `bind` should not define `volume` option")
990991
}
991992
if volume.Tmpfs != nil {
992-
logrus.Warnf("mount of type `tmpfs` should not define `tmpfs` option")
993+
logrus.Warnf("mount of type `bind` should not define `tmpfs` option")
993994
}
994995
return buildBindOption(volume.Bind), nil, nil
995996
case "volume":
@@ -1044,7 +1045,7 @@ func buildTmpfsOptions(tmpfs *types.ServiceVolumeTmpfs) *mount.TmpfsOptions {
10441045
}
10451046
return &mount.TmpfsOptions{
10461047
SizeBytes: int64(tmpfs.Size),
1047-
// Mode: , // FIXME missing from model ?
1048+
Mode: os.FileMode(tmpfs.Mode),
10481049
}
10491050
}
10501051

pkg/e2e/framework.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"io"
2222
"net/http"
2323
"os"
24-
"path"
2524
"path/filepath"
2625
"runtime"
2726
"strings"
@@ -129,7 +128,7 @@ func initializePlugins(t testing.TB, configDir string) {
129128

130129
require.NoError(t, os.MkdirAll(filepath.Join(configDir, "cli-plugins"), 0o755),
131130
"Failed to create cli-plugins directory")
132-
composePlugin, err := findExecutable(DockerComposeExecutableName, []string{"../../bin/build", "../../../bin/build"})
131+
composePlugin, err := findExecutable(DockerComposeExecutableName)
133132
if os.IsNotExist(err) {
134133
t.Logf("WARNING: docker-compose cli-plugin not found")
135134
}
@@ -149,17 +148,17 @@ func dirContents(dir string) []string {
149148
return res
150149
}
151150

152-
func findExecutable(executableName string, paths []string) (string, error) {
153-
for _, p := range paths {
154-
bin, err := filepath.Abs(path.Join(p, executableName))
155-
if err != nil {
156-
return "", err
157-
}
151+
func findExecutable(executableName string) (string, error) {
152+
_, filename, _, _ := runtime.Caller(0)
153+
root := filepath.Join(filepath.Dir(filename), "..", "..")
154+
buildPath := filepath.Join(root, "bin", "build")
158155

159-
if _, err := os.Stat(bin); os.IsNotExist(err) {
160-
continue
161-
}
156+
bin, err := filepath.Abs(filepath.Join(buildPath, executableName))
157+
if err != nil {
158+
return "", err
159+
}
162160

161+
if _, err := os.Stat(bin); err == nil {
163162
return bin, nil
164163
}
165164

@@ -302,7 +301,7 @@ func ComposeStandalonePath(t testing.TB) string {
302301
if !composeStandaloneMode {
303302
require.Fail(t, "Not running in standalone mode")
304303
}
305-
composeBinary, err := findExecutable(DockerComposeExecutableName, []string{"../../bin/build", "../../../bin/build"})
304+
composeBinary, err := findExecutable(DockerComposeExecutableName)
306305
require.NoError(t, err, "Could not find standalone Compose binary (%q)",
307306
DockerComposeExecutableName)
308307
return composeBinary

0 commit comments

Comments
 (0)