schema: add support for tmpfs.mode in mount definition (#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 #9873.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
Milas Bowman 2022-12-02 11:21:53 -05:00 коммит произвёл GitHub
Родитель b9e5f9e917
Коммит 113fb6732d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 59 добавлений и 533 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -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) {
@ -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)

Просмотреть файл

@ -15,15 +15,12 @@ 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
@ -31,7 +28,6 @@ require (
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
@ -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
@ -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
@ -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 (

Разница между файлами не показана из-за своего большого размера Загрузить разницу

2
go.mod
Просмотреть файл

@ -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

4
go.sum
Просмотреть файл

@ -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=

Просмотреть файл

@ -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"
@ -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"
@ -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":
@ -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),
}
}

Просмотреть файл

@ -21,7 +21,6 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strings"
@ -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")
}
@ -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
}
@ -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