Skip to content

Commit

Permalink
schema: add support for tmpfs.mode in mount definition
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 committed Nov 30, 2022
1 parent 2bef976 commit 422a3f3
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 475 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
16 changes: 4 additions & 12 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ require (
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/cnabio/cnab-go v0.24.1-0.20220907172316-1ca5c8721bf7 // indirect
github.com/cnabio/cnab-to-oci v0.3.7 // indirect
github.com/compose-spec/compose-go v1.7.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/containerd v1.6.10 // indirect
Expand Down Expand Up @@ -74,7 +74,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 Down Expand Up @@ -153,15 +153,7 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

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
)
require github.com/spf13/viper v1.4.0 // indirect

replace (
github.com/docker/cli => github.com/docker/cli v20.10.3-0.20221013132413-1d6c6e2367e2+incompatible // 22.06 master branch
Expand Down
449 changes: 6 additions & 443 deletions e2e/go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,5 @@ replace (
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4
k8s.io/client-go => k8s.io/client-go v0.22.4
)

replace github.com/compose-spec/compose-go => github.com/milas/compose-go v1.2.9-0.20221130191948-29304bf6ced6
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
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/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
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/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
github.com/containerd/btrfs v0.0.0-20201111183144-404b9149801e/go.mod h1:jg2QkJcsabfHugurUvvPhS3E08Oxiuh5W/g1ybB4e0E=
github.com/containerd/cgroups v0.0.0-20190717030353-c4b9ac5c7601/go.mod h1:X9rLEHIqSf/wfK8NsPqxJmeZgW4pcfzdXITDrUSJ6uI=
Expand Down Expand Up @@ -651,6 +649,8 @@ github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WT
github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU=
github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
github.com/milas/compose-go v1.2.9-0.20221130191948-29304bf6ced6 h1:LDjrJG/jzoGUoyNhbm9fd4APmUm3jyBjF4xazOGA80c=
github.com/milas/compose-go v1.2.9-0.20221130191948-29304bf6ced6/go.mod h1:Tb5Ae2PsYN3GTqYqzl2IRbTPiJtPZZjMw8UKUvmehFk=
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
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 422a3f3

Please sign in to comment.