Skip to content

Commit

Permalink
schema: add support for tmpfs.mode in mount definition (#10031)
Browse files Browse the repository at this point in the history
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 #9873.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
  • Loading branch information
milas authored Dec 2, 2022
1 parent b9e5f9e commit 113fb67
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 533 deletions.
23 changes: 23 additions & 0 deletions e2e/cucumber-features/volume-tmpfs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Volume: tmpfs

Background:
Given a compose file
"""
services:
svc:
image: busybox
volumes:
- type: tmpfs
target: /volumes/tmpfs
tmpfs:
size: 2M
mode: 0o647
"""

Scenario: tmpfs Permissions Set
When I run "compose run --rm svc stat -c "%a" /volumes/tmpfs"
Then the output contains "647"

Scenario: tmpfs Size Set
When I run "compose run --rm svc sh -c 'df /volumes/tmpfs | tail -n1 | awk '"'"'{print $4}'"'"'' "
Then the output contains "2048"
12 changes: 9 additions & 3 deletions e2e/cucumber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (

"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
"github.com/docker/compose/v2/pkg/e2e"
"github.com/mattn/go-shellwords"
"gotest.tools/v3/icmd"

"github.com/docker/compose/v2/pkg/e2e"
)

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

func (th *testHelper) runComposeCommand(command string) error {
commandArgs := []string{"-f", "-"}
commandArgs = append(commandArgs, strings.Split(command, " ")...)
commandArgs, err := shellwords.Parse(command)
if err != nil {
return err
}
commandArgs = append([]string{"-f", "-"}, commandArgs...)

cmd := th.CLI.NewDockerComposeCmd(th.T, commandArgs...)
cmd.Stdin = strings.NewReader(th.ComposeFile)
res := icmd.RunCmd(cmd)
Expand Down
21 changes: 6 additions & 15 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ require (
require (
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/goterm v1.0.4 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cnabio/cnab-go v0.23.0 // indirect
github.com/cnabio/cnab-to-oci v0.3.1-beta1 // indirect
github.com/compose-spec/compose-go v1.7.0 // indirect
github.com/compose-spec/compose-go v1.8.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/containerd v1.6.10 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/ttrpc v1.1.0 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/distribution/v3 v3.0.0-20221108081720-e9a25da7a47e // indirect
github.com/docker/buildx v0.9.1 // indirect
Expand Down Expand Up @@ -74,7 +70,7 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mattn/go-shellwords v1.0.12
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
Expand All @@ -100,8 +96,6 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/qri-io/jsonpointer v0.1.1 // indirect
github.com/qri-io/jsonschema v0.2.2-0.20210831022256-780655b2ba0e // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/serialx/hashring v0.0.0-20190422032157-8b2912629002 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand Down Expand Up @@ -154,13 +148,10 @@ require (
)

require (
github.com/gobuffalo/logger v1.0.3 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gobuffalo/packr/v2 v2.8.0 // indirect
github.com/karrick/godirwalk v1.15.3 // indirect
github.com/markbates/errx v1.1.0 // indirect
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
)

replace (
Expand Down
500 changes: 3 additions & 497 deletions e2e/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go v1.7.0
github.com/compose-spec/compose-go v1.8.0
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.10
github.com/distribution/distribution/v3 v3.0.0-20221108081720-e9a25da7a47e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/compose-spec/compose-go v1.7.0 h1:70HzJ/g81pdxF1ao9L7W2fgje/9FxNKH/davgvusEKc=
github.com/compose-spec/compose-go v1.7.0/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
github.com/compose-spec/compose-go v1.8.0 h1:fD2b8YDZVcSicKM0EEXsUdy+97PKza6+bjuXfSloNdM=
github.com/compose-spec/compose-go v1.8.0/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
Expand Down
7 changes: 4 additions & 3 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strconv"
"strings"

"github.com/compose-spec/compose-go/types"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/blkiodev"
"github.com/docker/docker/api/types/container"
Expand All @@ -42,6 +41,8 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/compose-spec/compose-go/types"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils"
Expand Down Expand Up @@ -989,7 +990,7 @@ func buildMountOptions(project types.Project, volume types.ServiceVolumeConfig)
logrus.Warnf("mount of type `bind` should not define `volume` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `tmpfs` should not define `tmpfs` option")
logrus.Warnf("mount of type `bind` should not define `tmpfs` option")
}
return buildBindOption(volume.Bind), nil, nil
case "volume":
Expand Down Expand Up @@ -1044,7 +1045,7 @@ func buildTmpfsOptions(tmpfs *types.ServiceVolumeTmpfs) *mount.TmpfsOptions {
}
return &mount.TmpfsOptions{
SizeBytes: int64(tmpfs.Size),
// Mode: , // FIXME missing from model ?
Mode: os.FileMode(tmpfs.Mode),
}
}

Expand Down
23 changes: 11 additions & 12 deletions pkg/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -129,7 +128,7 @@ func initializePlugins(t testing.TB, configDir string) {

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

func findExecutable(executableName string, paths []string) (string, error) {
for _, p := range paths {
bin, err := filepath.Abs(path.Join(p, executableName))
if err != nil {
return "", err
}
func findExecutable(executableName string) (string, error) {
_, filename, _, _ := runtime.Caller(0)
root := filepath.Join(filepath.Dir(filename), "..", "..")
buildPath := filepath.Join(root, "bin", "build")

if _, err := os.Stat(bin); os.IsNotExist(err) {
continue
}
bin, err := filepath.Abs(filepath.Join(buildPath, executableName))
if err != nil {
return "", err
}

if _, err := os.Stat(bin); err == nil {
return bin, nil
}

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

0 comments on commit 113fb67

Please sign in to comment.