Compare commits

..

3 Commits

Author SHA1 Message Date
Ulysses Souza
34f420040c Add ddev's e2e test
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
2022-03-28 14:55:17 +02:00
Randy Fay
9d07ce415f Fix problems with ddev e2e test and minor cleanup, add tmate (#27)
* Add tmate for debugging
* Use -parallel=1 for standaone tests

Signed-off-by: Randy Fay <randy@randyfay.com>
2022-03-28 14:50:33 +02:00
Ulysses Souza
c7560259a5 Add ddev's e2e test
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
2022-03-28 14:50:33 +02:00
71 changed files with 325 additions and 757 deletions

View File

@@ -7,10 +7,10 @@ jobs:
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/generate-artifacts')
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Checkout code into the Go module directory
@@ -42,12 +42,6 @@ jobs:
name: docker-compose-linux-amd64
path: ${{ github.workspace }}/bin/docker-compose-linux-amd64
- name: Upload linux-ppc64le binary
uses: actions/upload-artifact@v2
with:
name: docker-compose-linux-ppc64le
path: ${{ github.workspace }}/bin/docker-compose-linux-ppc64le
- name: Upload windows-amd64 binary
uses: actions/upload-artifact@v2
with:

View File

@@ -19,10 +19,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Checkout code into the Go module directory
@@ -46,10 +46,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Checkout code into the Go module directory
@@ -71,10 +71,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Setup docker CLI
@@ -107,10 +107,10 @@ jobs:
env:
GO111MODULE: "on"
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Setup docker CLI
@@ -139,7 +139,4 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
- name: E2E Test in standalone mode
run: |
rm -f /usr/local/bin/docker-compose
cp bin/docker-compose /usr/local/bin
make e2e-compose-standalone
run: make e2e-compose-standalone

View File

@@ -1,22 +0,0 @@
name: dispatch release event to downstream repositories
on:
workflow_dispatch:
jobs:
dispatch_release_version:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_DOC_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'docker',
repo: 'docker.github.io',
workflow_id: 'compose_release',
ref: 'compose-api-upstream',
inputs: {
release: ${{ GITHUB_REF }},
},
})

View File

@@ -11,10 +11,10 @@ jobs:
upload-release:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.18
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.18.2
go-version: 1.17
id: go
- name: Setup docker CLI
@@ -36,7 +36,7 @@ jobs:
run: make GIT_TAG=${{ github.event.inputs.tag }} -f builder.Makefile cross
- name: Compute checksums
run: cd bin; for f in *; do shasum --binary --algorithm 256 $f | tee -a checksums.txt > $f.sha256; done
run: cd bin; for f in *; do shasum --algorithm 256 $f > $f.sha256; done
- name: License
run: cp packaging/* bin/

View File

@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG GO_VERSION=1.18.2-alpine
ARG GO_VERSION=1.17-alpine
ARG GOLANGCI_LINT_VERSION=v1.40.1-alpine
ARG PROTOC_GEN_GO_VERSION=v1.4.3
@@ -88,7 +88,7 @@ RUN --mount=target=. \
make -f builder.Makefile test
FROM base AS check-license-headers
RUN go install github.com/kunalkushwaha/ltag@latest
RUN go get -u github.com/kunalkushwaha/ltag
RUN --mount=target=. \
make -f builder.Makefile check-license-headers

View File

@@ -48,6 +48,8 @@ e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName
.PHONY: e2e-compose-standalone
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
rm -f /usr/local/bin/docker-compose
cp bin/docker-compose /usr/local/bin
docker-compose version
go test $(TEST_FLAGS) -v -count=1 -parallel=1 --tags=standalone ./pkg/e2e

View File

@@ -47,7 +47,6 @@ compose-plugin:
.PHONY: cross
cross:
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-x86_64 ./cmd
GOOS=linux GOARCH=ppc64le $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-ppc64le ./cmd
GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-aarch64 ./cmd
GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 ./cmd
GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 ./cmd

View File

@@ -23,7 +23,6 @@ import (
"strings"
"github.com/compose-spec/compose-go/cli"
"github.com/compose-spec/compose-go/loader"
"github.com/compose-spec/compose-go/types"
buildx "github.com/docker/buildx/util/progress"
"github.com/docker/compose/v2/pkg/utils"
@@ -41,28 +40,6 @@ type buildOptions struct {
args []string
noCache bool
memory string
ssh string
}
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
var SSHKeys []types.SSHKey
var err error
if opts.ssh != "" {
SSHKeys, err = loader.ParseShortSSHSyntax(opts.ssh)
if err != nil {
return api.BuildOptions{}, err
}
}
return api.BuildOptions{
Pull: opts.pull,
Progress: opts.progress,
Args: types.NewMappingWithEquals(opts.args),
NoCache: opts.noCache,
Quiet: opts.quiet,
Services: services,
SSHs: SSHKeys,
}, nil
}
var printerModes = []string{
@@ -96,10 +73,7 @@ func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
}
return nil
}),
RunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("ssh") && opts.ssh == "" {
opts.ssh = "default"
}
RunE: Adapt(func(ctx context.Context, args []string) error {
return runBuild(ctx, backend, opts, args)
}),
ValidArgsFunction: serviceCompletion(p),
@@ -108,7 +82,6 @@ func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
cmd.Flags().BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image.")
cmd.Flags().StringVar(&opts.progress, "progress", buildx.PrinterModeAuto, fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
cmd.Flags().StringArrayVar(&opts.args, "build-arg", []string{}, "Set build-time variables for services.")
cmd.Flags().StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)")
cmd.Flags().Bool("parallel", true, "Build images in parallel. DEPRECATED")
cmd.Flags().MarkHidden("parallel") //nolint:errcheck
cmd.Flags().Bool("compress", true, "Compress the build context using gzip. DEPRECATED")
@@ -130,9 +103,12 @@ func runBuild(ctx context.Context, backend api.Service, opts buildOptions, servi
return err
}
apiBuildOptions, err := opts.toAPIBuildOptions(services)
if err != nil {
return err
}
return backend.Build(ctx, project, apiBuildOptions)
return backend.Build(ctx, project, api.BuildOptions{
Pull: opts.pull,
Progress: opts.progress,
Args: types.NewMappingWithEquals(opts.args),
NoCache: opts.noCache,
Quiet: opts.quiet,
Services: services,
})
}

View File

@@ -89,6 +89,9 @@ func Adapt(fn Command) func(cmd *cobra.Command, args []string) error {
})
}
// Warning is a global warning to be displayed to user on command failure
var Warning string
type projectOptions struct {
ProjectName string
Profiles []string
@@ -129,8 +132,8 @@ func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) {
f.StringVarP(&o.ProjectName, "project-name", "p", "", "Project name")
f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
f.StringVar(&o.EnvFile, "env-file", "", "Specify an alternate environment file.")
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the, first specified, Compose file)")
f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the, first specified, Compose file)")
f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the Compose file)")
f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the Compose file)")
f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
_ = f.MarkHidden("workdir")
}
@@ -140,11 +143,6 @@ func (o *projectOptions) toProjectName() (string, error) {
return o.ProjectName, nil
}
envProjectName := os.Getenv("COMPOSE_PROJECT_NAME")
if envProjectName != "" {
return envProjectName, nil
}
project, err := o.toProject(nil)
if err != nil {
return "", err
@@ -169,10 +167,7 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
ef := o.EnvFile
if ef != "" && !filepath.IsAbs(ef) {
ef, err = filepath.Abs(ef)
if err != nil {
return nil, err
}
ef = filepath.Join(project.WorkingDir, o.EnvFile)
}
for i, s := range project.Services {
s.CustomLabels = map[string]string{
@@ -213,9 +208,9 @@ func (o *projectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.Proj
return cli.NewProjectOptions(o.ConfigPaths,
append(po,
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithOsEnv,
cli.WithEnvFile(o.EnvFile),
cli.WithDotEnv,
cli.WithOsEnv,
cli.WithConfigFileEnv,
cli.WithDefaultConfigPath,
cli.WithName(o.ProjectName))...)

View File

@@ -55,7 +55,7 @@ func copyCommand(p *projectOptions, backend api.Service) *cobra.Command {
}
return nil
}),
RunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
RunE: Adapt(func(ctx context.Context, args []string) error {
opts.source = args[0]
opts.destination = args[1]
return runCopy(ctx, backend, opts)
@@ -64,10 +64,8 @@ func copyCommand(p *projectOptions, backend api.Service) *cobra.Command {
}
flags := copyCmd.Flags()
flags.IntVar(&opts.index, "index", 0, "Index of the container if there are multiple instances of a service .")
flags.IntVar(&opts.index, "index", 1, "Index of the container if there are multiple instances of a service [default: 1].")
flags.BoolVar(&opts.all, "all", false, "Copy to all the containers of the service.")
flags.MarkHidden("all") //nolint:errcheck
flags.MarkDeprecated("all", "By default all the containers of the service will get the source file/directory to be copied.") //nolint:errcheck
flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH")
flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)")

View File

@@ -59,7 +59,6 @@ func downCommand(p *projectOptions, backend api.Service) *cobra.Command {
RunE: Adapt(func(ctx context.Context, args []string) error {
return runDown(ctx, backend, opts)
}),
Args: cobra.NoArgs,
ValidArgsFunction: noCompletion(),
}
flags := downCmd.Flags()

View File

@@ -150,7 +150,7 @@ func runCommand(p *projectOptions, dockerCli command.Cli, backend api.Service) *
flags.StringArrayVarP(&opts.environment, "env", "e", []string{}, "Set environment variables")
flags.StringArrayVarP(&opts.labels, "label", "l", []string{}, "Add or override a label")
flags.BoolVar(&opts.Remove, "rm", false, "Automatically remove the container when it exits")
flags.BoolVarP(&opts.noTty, "no-TTY", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-TTY allocation (default: auto-detected).")
flags.BoolVarP(&opts.noTty, "no-TTY", "T", !dockerCli.Out().IsTerminal(), "Disable pseudo-noTty allocation (default: auto-detected).")
flags.StringVar(&opts.name, "name", "", " Assign a name to the container")
flags.StringVarP(&opts.user, "user", "u", "", "Run as specified username or uid")
flags.StringVarP(&opts.workdir, "workdir", "w", "", "Working directory inside the container")

View File

@@ -185,9 +185,6 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions
if upOptions.attachDependencies {
attachTo = project.ServiceNames()
}
if len(attachTo) == 0 {
attachTo = project.ServiceNames()
}
create := api.CreateOptions{
Services: services,
@@ -207,7 +204,6 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions
return backend.Up(ctx, project, api.UpOptions{
Create: create,
Start: api.StartOptions{
Project: project,
Attach: consumer,
AttachTo: attachTo,
ExitCodeFrom: upOptions.exitCodeFrom,

View File

@@ -79,7 +79,7 @@ func (l *logConsumer) Log(container, service, message string) {
}
p := l.getPresenter(container)
for _, line := range strings.Split(message, "\n") {
fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line) // nolint:errcheck
fmt.Fprintf(l.writer, "%s %s\n", p.prefix, line) // nolint:errcheck
}
}
@@ -118,5 +118,5 @@ type presenter struct {
}
func (p *presenter) setPrefix(width int) {
p.prefix = p.colors(fmt.Sprintf("%-"+strconv.Itoa(width)+"s | ", p.name))
p.prefix = p.colors(fmt.Sprintf("%-"+strconv.Itoa(width)+"s |", p.name))
}

View File

@@ -32,6 +32,11 @@ import (
"github.com/docker/compose/v2/pkg/compose"
)
func init() {
commands.Warning = "The new 'docker compose' command is currently experimental. " +
"To provide feedback or request new features please open issues at https://github.com/docker/compose"
}
func pluginMain() {
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
lazyInit := api.NewServiceProxy()

View File

@@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG GO_VERSION=1.18.2
ARG GO_VERSION=1.17
ARG FORMATS=md,yaml
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS docsgen

View File

@@ -44,7 +44,7 @@ Docker Compose
| `-f`, `--file` | `stringArray` | | Compose configuration files |
| `--profile` | `stringArray` | | Specify a profile to enable |
| `--project-directory` | `string` | | Specify an alternate working directory
(default: the path of the, first specified, Compose file) |
(default: the path of the Compose file) |
| `-p`, `--project-name` | `string` | | Project name |

View File

@@ -12,7 +12,6 @@ Build or rebuild services
| `--progress` | `string` | `auto` | Set type of progress output (auto, tty, plain, quiet) |
| `--pull` | | | Always attempt to pull a newer version of the image. |
| `-q`, `--quiet` | | | Don't print anything to STDOUT |
| `--ssh` | `string` | | Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent) |
<!---MARKER_GEN_END-->

View File

@@ -7,9 +7,10 @@ Copy files/folders between a service container and the local filesystem
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `--all` | | | Copy to all the containers of the service. |
| `-a`, `--archive` | | | Archive mode (copy all uid/gid information) |
| `-L`, `--follow-link` | | | Always follow symbol link in SRC_PATH |
| `--index` | `int` | `0` | Index of the container if there are multiple instances of a service . |
| `--index` | `int` | `1` | Index of the container if there are multiple instances of a service [default: 1]. |
<!---MARKER_GEN_END-->

View File

@@ -13,7 +13,7 @@ Run a one-off command on a service.
| `-i`, `--interactive` | | | Keep STDIN open even if not attached. |
| `-l`, `--label` | `stringArray` | | Add or override a label |
| `--name` | `string` | | Assign a name to the container |
| `-T`, `--no-TTY` | | | Disable pseudo-TTY allocation (default: auto-detected). |
| `-T`, `--no-TTY` | | | Disable pseudo-noTty allocation (default: auto-detected). |
| `--no-deps` | | | Don't start linked services. |
| `-p`, `--publish` | `stringArray` | | Publish a container's port(s) to the host. |
| `--quiet-pull` | | | Pull without printing progress information. |

View File

@@ -222,7 +222,7 @@ options:
value_type: string
description: |-
Specify an alternate working directory
(default: the path of the, first specified, Compose file)
(default: the path of the Compose file)
deprecated: false
hidden: false
experimental: false
@@ -265,7 +265,7 @@ options:
description: |-
DEPRECATED! USE --project-directory INSTEAD.
Specify an alternate working directory
(default: the path of the, first specified, Compose file)
(default: the path of the Compose file)
deprecated: false
hidden: true
experimental: false

View File

@@ -117,16 +117,6 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: ssh
value_type: string
description: |
Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
experimental: false
experimentalcli: false

View File

@@ -10,8 +10,8 @@ options:
value_type: bool
default_value: "false"
description: Copy to all the containers of the service.
deprecated: true
hidden: true
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
@@ -40,9 +40,9 @@ options:
swarm: false
- option: index
value_type: int
default_value: "0"
default_value: "1"
description: |
Index of the container if there are multiple instances of a service .
Index of the container if there are multiple instances of a service [default: 1].
deprecated: false
hidden: false
experimental: false

View File

@@ -125,7 +125,7 @@ options:
shorthand: T
value_type: bool
default_value: "true"
description: 'Disable pseudo-TTY allocation (default: auto-detected).'
description: 'Disable pseudo-noTty allocation (default: auto-detected).'
deprecated: false
hidden: false
experimental: false

10
go.mod
View File

@@ -1,14 +1,14 @@
module github.com/docker/compose/v2
go 1.18
go 1.17
require (
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/buger/goterm v1.0.4
github.com/cnabio/cnab-to-oci v0.3.1-beta1
github.com/compose-spec/compose-go v1.2.6
github.com/compose-spec/compose-go v1.2.1
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.2
github.com/containerd/containerd v1.6.1
github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e
github.com/docker/buildx v0.8.1 // when updating, also update the replace rules accordingly
github.com/docker/cli v20.10.12+incompatible
@@ -35,7 +35,7 @@ require (
github.com/theupdateframework/notary v0.6.1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gotest.tools v2.2.0+incompatible
gotest.tools/v3 v3.2.0
gotest.tools/v3 v3.1.0
)
require (
@@ -78,7 +78,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/signal v0.6.0 // indirect
github.com/moby/sys/symlink v0.2.0 // indirect

20
go.sum
View File

@@ -259,6 +259,7 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -301,8 +302,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codahale/hdrhistogram v0.0.0-20160425231609-f8ad88b59a58/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/compose-spec/compose-go v1.0.8/go.mod h1:REnCbBugoIdHB7S1sfkN/aJ7AJpNApGNjNiVjA9L8x4=
github.com/compose-spec/compose-go v1.2.6 h1:9l2Y/yNn/OSngnkUBP8h8CchTmMcf1MW4BeUEaZXy8k=
github.com/compose-spec/compose-go v1.2.6/go.mod h1:cg8yTeI+7rfQsEW9XHOLx0sNVjGKEXr6XwVB4fxmG3A=
github.com/compose-spec/compose-go v1.2.1 h1:8+DAP7Mt/Ohl5y6YbZdilLMvIhMxvuSZcNZyywjQmJE=
github.com/compose-spec/compose-go v1.2.1/go.mod h1:pAy7Mikpeft4pxkFU565/DRHEbDfR84G6AQuiL+Hdg8=
github.com/compose-spec/godotenv v1.1.1/go.mod h1:zF/3BOa18Z24tts5qnO/E9YURQanJTBUf7nlcCTNsyc=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
@@ -347,9 +348,8 @@ github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoT
github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTVn7dJnIOwtYR4g=
github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c=
github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s=
github.com/containerd/containerd v1.6.1 h1:oa2uY0/0G+JX4X7hpGCYvkp9FjUancz56kSNnb1sG3o=
github.com/containerd/containerd v1.6.1/go.mod h1:1nJz5xCZPusx6jJU8Frfct988y0NpumIq9ODB0kLtoE=
github.com/containerd/containerd v1.6.2 h1:pcaPUGbYW8kBw6OgIZwIVIeEhdWVrBzsoCfVJ5BjrLU=
github.com/containerd/containerd v1.6.2/go.mod h1:sidY30/InSE1j2vdD1ihtKoJz+lWdaXMdiAeIupaf+s=
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
@@ -1032,8 +1032,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/moby/buildkit v0.8.1/go.mod h1:/kyU1hKy/aYCuP39GZA9MaKioovHku57N6cqlKZIaiQ=
github.com/moby/buildkit v0.10.0-rc2.0.20220308185020-fdecd0ae108b h1:plbnJxjht8Z6D3c/ga79D1+VaA/IUfNVp08J3lcDgI8=
@@ -1474,6 +1474,7 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/contrib v0.20.0 h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0=
go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0/go.mod h1:vEhqr0m4eTc+DWxfsXoXue2GBgV2uUwVznkGIHW/e5w=
@@ -1490,6 +1491,7 @@ go.opentelemetry.io/otel v1.4.0/go.mod h1:jeAqMFKy2uLIxCtKxoFj0FAL5zAPKQagc3+GtB
go.opentelemetry.io/otel v1.4.1 h1:QbINgGDDcoQUoMJa2mMaWno49lja9sHwp6aoa2n3a4g=
go.opentelemetry.io/otel v1.4.1/go.mod h1:StM6F/0fSwpd8dKWDCdRr7uRvEPYdW0hBSlbdTiUde4=
go.opentelemetry.io/otel/exporters/jaeger v1.4.1/go.mod h1:ZW7vkOu9nC1CxsD8bHNHCia5JUbwP39vxgd1q4Z5rCI=
go.opentelemetry.io/otel/exporters/otlp v0.20.0 h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg=
go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.3.0/go.mod h1:VpP4/RMn8bv8gNo9uK7/IMY4mtWLELsS+JIP0inH0h4=
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.1/go.mod h1:VpP4/RMn8bv8gNo9uK7/IMY4mtWLELsS+JIP0inH0h4=
@@ -2145,8 +2147,8 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
gotest.tools/v3 v3.2.0 h1:I0DwBVMGAx26dttAj1BtJLAkVGncrkkUXfJLC4Flt/I=
gotest.tools/v3 v3.2.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A=
gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk=
gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ=
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -2191,6 +2193,7 @@ k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8
k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
@@ -2229,6 +2232,7 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyz
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06 h1:zD2IemQ4LmOcAumeiyDWXKUI2SO0NYDe3H6QGvPOVgU=
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18=
sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=

View File

@@ -32,9 +32,9 @@ type Service interface {
// Push executes the equivalent ot a `compose push`
Push(ctx context.Context, project *types.Project, options PushOptions) error
// Pull executes the equivalent of a `compose pull`
Pull(ctx context.Context, project *types.Project, options PullOptions) error
Pull(ctx context.Context, project *types.Project, opts PullOptions) error
// Create executes the equivalent to a `compose create`
Create(ctx context.Context, project *types.Project, options CreateOptions) error
Create(ctx context.Context, project *types.Project, opts CreateOptions) error
// Start executes the equivalent to a `compose start`
Start(ctx context.Context, projectName string, options StartOptions) error
// Restart restarts containers
@@ -54,25 +54,25 @@ type Service interface {
// Convert translate compose model into backend's native format
Convert(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
// Kill executes the equivalent to a `compose kill`
Kill(ctx context.Context, projectName string, options KillOptions) error
Kill(ctx context.Context, project string, options KillOptions) error
// RunOneOffContainer creates a service oneoff container and starts its dependencies
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
// Remove executes the equivalent to a `compose rm`
Remove(ctx context.Context, projectName string, options RemoveOptions) error
Remove(ctx context.Context, project string, options RemoveOptions) error
// Exec executes a command in a running service container
Exec(ctx context.Context, projectName string, options RunOptions) (int, error)
Exec(ctx context.Context, project string, opts RunOptions) (int, error)
// Copy copies a file/folder between a service container and the local filesystem
Copy(ctx context.Context, projectName string, options CopyOptions) error
Copy(ctx context.Context, project string, options CopyOptions) error
// Pause executes the equivalent to a `compose pause`
Pause(ctx context.Context, projectName string, options PauseOptions) error
Pause(ctx context.Context, project string, options PauseOptions) error
// UnPause executes the equivalent to a `compose unpause`
UnPause(ctx context.Context, projectName string, options PauseOptions) error
UnPause(ctx context.Context, project string, options PauseOptions) error
// Top executes the equivalent to a `compose top`
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
// Events executes the equivalent to a `compose events`
Events(ctx context.Context, projectName string, options EventsOptions) error
Events(ctx context.Context, project string, options EventsOptions) error
// Port executes the equivalent to a `compose port`
Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error)
Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error)
// Images executes the equivalent of a `compose images`
Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
}
@@ -91,8 +91,6 @@ type BuildOptions struct {
Quiet bool
// Services passed in the command line to be built
Services []string
// Ssh authentications passed in the command line
SSHs []types.SSHKey
}
// CreateOptions group options of the Create API
@@ -117,8 +115,6 @@ type CreateOptions struct {
// StartOptions group options of the Start API
type StartOptions struct {
// Project is the compose project used to define this app. Might be nil if user ran `start` just with project name
Project *types.Project
// Attach to container and forward logs if not nil
Attach LogConsumer
// AttachTo set the services to attach to

View File

@@ -219,11 +219,11 @@ func (s *ServiceProxy) Convert(ctx context.Context, project *types.Project, opti
}
// Kill implements Service interface
func (s *ServiceProxy) Kill(ctx context.Context, projectName string, options KillOptions) error {
func (s *ServiceProxy) Kill(ctx context.Context, project string, options KillOptions) error {
if s.KillFn == nil {
return ErrNotImplemented
}
return s.KillFn(ctx, projectName, options)
return s.KillFn(ctx, project, options)
}
// RunOneOffContainer implements Service interface
@@ -238,43 +238,43 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr
}
// Remove implements Service interface
func (s *ServiceProxy) Remove(ctx context.Context, projectName string, options RemoveOptions) error {
func (s *ServiceProxy) Remove(ctx context.Context, project string, options RemoveOptions) error {
if s.RemoveFn == nil {
return ErrNotImplemented
}
return s.RemoveFn(ctx, projectName, options)
return s.RemoveFn(ctx, project, options)
}
// Exec implements Service interface
func (s *ServiceProxy) Exec(ctx context.Context, projectName string, options RunOptions) (int, error) {
func (s *ServiceProxy) Exec(ctx context.Context, project string, options RunOptions) (int, error) {
if s.ExecFn == nil {
return 0, ErrNotImplemented
}
return s.ExecFn(ctx, projectName, options)
return s.ExecFn(ctx, project, options)
}
// Copy implements Service interface
func (s *ServiceProxy) Copy(ctx context.Context, projectName string, options CopyOptions) error {
func (s *ServiceProxy) Copy(ctx context.Context, project string, options CopyOptions) error {
if s.CopyFn == nil {
return ErrNotImplemented
}
return s.CopyFn(ctx, projectName, options)
return s.CopyFn(ctx, project, options)
}
// Pause implements Service interface
func (s *ServiceProxy) Pause(ctx context.Context, projectName string, options PauseOptions) error {
func (s *ServiceProxy) Pause(ctx context.Context, project string, options PauseOptions) error {
if s.PauseFn == nil {
return ErrNotImplemented
}
return s.PauseFn(ctx, projectName, options)
return s.PauseFn(ctx, project, options)
}
// UnPause implements Service interface
func (s *ServiceProxy) UnPause(ctx context.Context, projectName string, options PauseOptions) error {
func (s *ServiceProxy) UnPause(ctx context.Context, project string, options PauseOptions) error {
if s.UnPauseFn == nil {
return ErrNotImplemented
}
return s.UnPauseFn(ctx, projectName, options)
return s.UnPauseFn(ctx, project, options)
}
// Top implements Service interface
@@ -286,19 +286,19 @@ func (s *ServiceProxy) Top(ctx context.Context, project string, services []strin
}
// Events implements Service interface
func (s *ServiceProxy) Events(ctx context.Context, projectName string, options EventsOptions) error {
func (s *ServiceProxy) Events(ctx context.Context, project string, options EventsOptions) error {
if s.EventsFn == nil {
return ErrNotImplemented
}
return s.EventsFn(ctx, projectName, options)
return s.EventsFn(ctx, project, options)
}
// Port implements Service interface
func (s *ServiceProxy) Port(ctx context.Context, projectName string, service string, port int, options PortOptions) (string, int, error) {
func (s *ServiceProxy) Port(ctx context.Context, project string, service string, port int, options PortOptions) (string, int, error) {
if s.PortFn == nil {
return "", 0, ErrNotImplemented
}
return s.PortFn(ctx, projectName, service, port, options)
return s.PortFn(ctx, project, service, port, options)
}
// Images implements Service interface

View File

@@ -48,7 +48,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
fmt.Printf("Attaching to %s\n", strings.Join(names, ", "))
for _, container := range containers {
err := s.attachContainer(ctx, container, listener)
err := s.attachContainer(ctx, container, listener, project)
if err != nil {
return nil, err
}
@@ -56,9 +56,13 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
return containers, err
}
func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener api.ContainerEventListener) error {
func (s *composeService) attachContainer(ctx context.Context, container moby.Container, listener api.ContainerEventListener, project *types.Project) error {
serviceName := container.Labels[api.ServiceLabel]
containerName := getContainerNameWithoutProject(container)
service, err := project.GetService(serviceName)
if err != nil {
return err
}
listener(api.ContainerEvent{
Type: api.ContainerEventAttach,
@@ -74,13 +78,7 @@ func (s *composeService) attachContainer(ctx context.Context, container moby.Con
Line: line,
})
})
inspect, err := s.dockerCli.Client().ContainerInspect(ctx, container.ID)
if err != nil {
return err
}
_, _, err = s.attachContainerStreams(ctx, container.ID, inspect.Config.Tty, nil, w, w)
_, _, err = s.attachContainerStreams(ctx, container.ID, service.Tty, nil, w, w)
return err
}

View File

@@ -31,8 +31,6 @@ import (
bclient "github.com/moby/buildkit/client"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/auth/authprovider"
"github.com/moby/buildkit/session/secrets/secretsprovider"
"github.com/moby/buildkit/session/sshforward/sshprovider"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/compose/v2/pkg/api"
@@ -64,7 +62,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
if service.Build != nil {
imageName := getImageName(service, project.Name)
imagesToBuild = append(imagesToBuild, imageName)
buildOptions, err := s.toBuildOptions(project, service, imageName, options.SSHs)
buildOptions, err := s.toBuildOptions(project, service, imageName)
if err != nil {
return err
}
@@ -82,6 +80,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
Attrs: map[string]string{"ref": image},
})
}
opts[imageName] = buildOptions
}
}
@@ -160,7 +159,7 @@ func (s *composeService) getBuildOptions(project *types.Project, images map[stri
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
continue
}
opt, err := s.toBuildOptions(project, service, imageName, []types.SSHKey{})
opt, err := s.toBuildOptions(project, service, imageName)
if err != nil {
return nil, err
}
@@ -210,7 +209,7 @@ func (s *composeService) doBuild(ctx context.Context, project *types.Project, op
return s.doBuildBuildkit(ctx, project, opts, mode)
}
func (s *composeService) toBuildOptions(project *types.Project, service types.ServiceConfig, imageTag string, sshKeys []types.SSHKey) (build.Options, error) {
func (s *composeService) toBuildOptions(project *types.Project, service types.ServiceConfig, imageTag string) (build.Options, error) {
var tags []string
tags = append(tags, imageTag)
@@ -244,41 +243,6 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
return build.Options{}, err
}
sessionConfig := []session.Attachable{
authprovider.NewDockerAuthProvider(s.stderr()),
}
if len(sshKeys) > 0 || len(service.Build.SSH) > 0 {
sshAgentProvider, err := sshAgentProvider(append(service.Build.SSH, sshKeys...))
if err != nil {
return build.Options{}, err
}
sessionConfig = append(sessionConfig, sshAgentProvider)
}
if len(service.Build.Secrets) > 0 {
var sources []secretsprovider.Source
for _, secret := range service.Build.Secrets {
config := project.Secrets[secret.Source]
if config.File == "" {
return build.Options{}, fmt.Errorf("build.secrets only supports file-based secrets: %q", secret.Source)
}
sources = append(sources, secretsprovider.Source{
ID: secret.Source,
FilePath: config.File,
})
}
store, err := secretsprovider.NewStore(sources)
if err != nil {
return build.Options{}, err
}
p := secretsprovider.NewSecretProvider(store)
sessionConfig = append(sessionConfig, p)
}
if len(service.Build.Tags) > 0 {
tags = append(tags, service.Build.Tags...)
}
return build.Options{
Inputs: build.Inputs{
ContextPath: service.Build.Context,
@@ -295,8 +259,10 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
Platforms: plats,
Labels: service.Build.Labels,
NetworkMode: service.Build.Network,
ExtraHosts: service.Build.ExtraHosts.AsList(),
Session: sessionConfig,
ExtraHosts: service.Build.ExtraHosts,
Session: []session.Attachable{
authprovider.NewDockerAuthProvider(s.stderr()),
},
}, nil
}
@@ -330,14 +296,3 @@ func dockerFilePath(context string, dockerfile string) string {
}
return filepath.Join(context, dockerfile)
}
func sshAgentProvider(sshKeys types.SSHConfig) (session.Attachable, error) {
sshConfig := make([]sshprovider.AgentConfig, 0, len(sshKeys))
for _, sshKey := range sshKeys {
sshConfig = append(sshConfig, sshprovider.AgentConfig{
ID: sshKey.ID,
Paths: []string{sshKey.Path},
})
}
return sshprovider.NewSSHAgentProvider(sshConfig)
}

View File

@@ -143,8 +143,17 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
return "", err
}
// if up to this point nothing has set the context then we must have another
// way for sending it(streaming) and set the context to the Dockerfile
if dockerfileCtx != nil && buildCtx == nil {
buildCtx = dockerfileCtx
}
progressOutput := streamformatter.NewProgressOutput(progBuff)
body := progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")
var body io.Reader
if buildCtx != nil {
body = progress.NewProgressReader(buildCtx, progressOutput, 0, "", "Sending build context to Docker daemon")
}
configFile := s.configFile()
creds, err := configFile.GetAllCredentials()

View File

@@ -18,13 +18,14 @@ package compose
import (
"context"
"fmt"
"sort"
"strconv"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
)
// Containers is a set of moby Container
@@ -40,7 +41,17 @@ const (
func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, stopped bool, selectedServices ...string) (Containers, error) {
var containers Containers
f := getDefaultFilters(project, oneOff, selectedServices...)
f := []filters.KeyValuePair{projectFilter(project)}
if len(selectedServices) == 1 {
f = append(f, serviceFilter(selectedServices[0]))
}
switch oneOff {
case oneOffOnly:
f = append(f, oneOffFilter(true))
case oneOffExclude:
f = append(f, oneOffFilter(false))
case oneOffInclude:
}
containers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs(f...),
All: stopped,
@@ -54,40 +65,6 @@ func (s *composeService) getContainers(ctx context.Context, project string, oneO
return containers, nil
}
func getDefaultFilters(projectName string, oneOff oneOff, selectedServices ...string) []filters.KeyValuePair {
f := []filters.KeyValuePair{projectFilter(projectName)}
if len(selectedServices) == 1 {
f = append(f, serviceFilter(selectedServices[0]))
}
switch oneOff {
case oneOffOnly:
f = append(f, oneOffFilter(true))
case oneOffExclude:
f = append(f, oneOffFilter(false))
case oneOffInclude:
}
return f
}
func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName string, oneOff oneOff, stopped bool, serviceName string, containerIndex int) (moby.Container, error) {
defaultFilters := getDefaultFilters(projectName, oneOff, serviceName)
defaultFilters = append(defaultFilters, containerNumberFilter(containerIndex))
containers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs(
defaultFilters...,
),
All: stopped,
})
if err != nil {
return moby.Container{}, err
}
if len(containers) < 1 {
return moby.Container{}, fmt.Errorf("service %q is not running container #%d", serviceName, containerIndex)
}
container := containers[0]
return container, nil
}
// containerPredicate define a predicate we want container to satisfy for filtering operations
type containerPredicate func(c moby.Container) bool
@@ -110,6 +87,14 @@ func isNotOneOff(c moby.Container) bool {
return !ok || v == "False"
}
func indexed(index int) containerPredicate {
return func(c moby.Container) bool {
number := c.Labels[api.ContainerNumberLabel]
idx, err := strconv.Atoi(number)
return err == nil && index == idx
}
}
// filter return Containers with elements to match predicate
func (containers Containers) filter(predicate containerPredicate) Containers {
var filtered Containers

View File

@@ -42,80 +42,59 @@ const (
acrossServices = fromService | toService
)
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
projectName = strings.ToLower(projectName)
srcService, srcPath := splitCpArg(options.Source)
destService, dstPath := splitCpArg(options.Destination)
func (s *composeService) Copy(ctx context.Context, project string, opts api.CopyOptions) error {
srcService, srcPath := splitCpArg(opts.Source)
destService, dstPath := splitCpArg(opts.Destination)
var direction copyDirection
var serviceName string
var copyFunc func(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error
if srcService != "" {
direction |= fromService
serviceName = srcService
copyFunc = s.copyFromContainer
// copying from multiple containers of a services doesn't make sense.
if options.All {
if opts.All {
return errors.New("cannot use the --all flag when copying from a service")
}
}
if destService != "" {
direction |= toService
serviceName = destService
copyFunc = s.copyToContainer
}
if direction == acrossServices {
return errors.New("copying between services is not supported")
}
if direction == 0 {
return errors.New("unknown copy direction")
}
containers, err := s.listContainersTargetedForCopy(ctx, projectName, options.Index, direction, serviceName)
containers, err := s.getContainers(ctx, project, oneOffExclude, true, serviceName)
if err != nil {
return err
}
if len(containers) < 1 {
return fmt.Errorf("no container found for service %q", serviceName)
}
if !opts.All {
containers = containers.filter(indexed(opts.Index))
}
g := errgroup.Group{}
for _, container := range containers {
containerID := container.ID
g.Go(func() error {
return copyFunc(ctx, containerID, srcPath, dstPath, options)
switch direction {
case fromService:
return s.copyFromContainer(ctx, containerID, srcPath, dstPath, opts)
case toService:
return s.copyToContainer(ctx, containerID, srcPath, dstPath, opts)
case acrossServices:
return errors.New("copying between services is not supported")
default:
return errors.New("unknown copy direction")
}
})
}
return g.Wait()
}
func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, index int, direction copyDirection, serviceName string) (Containers, error) {
var containers Containers
var err error
switch {
case index > 0:
container, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, index)
if err != nil {
return nil, err
}
return append(containers, container), nil
default:
containers, err = s.getContainers(ctx, projectName, oneOffExclude, true, serviceName)
if err != nil {
return nil, err
}
if len(containers) < 1 {
return nil, fmt.Errorf("no container found for service %q", serviceName)
}
if direction == fromService {
return containers[:1], err
}
return containers, err
}
}
func (s *composeService) copyToContainer(ctx context.Context, containerID string, srcPath string, dstPath string, opts api.CopyOptions) error {
var err error
if srcPath != "-" {

View File

@@ -173,10 +173,6 @@ func prepareServicesDependsOn(p *types.Project) error {
dependencies = append(dependencies, spec[0])
}
for _, link := range service.Links {
dependencies = append(dependencies, strings.Split(link, ":")[0])
}
if len(dependencies) == 0 {
continue
}
@@ -375,7 +371,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
DNS: service.DNS,
DNSSearch: service.DNSSearch,
DNSOptions: service.DNSOpts,
ExtraHosts: service.ExtraHosts.AsList(),
ExtraHosts: service.ExtraHosts,
SecurityOpt: securityOpts,
UsernsMode: container.UsernsMode(service.UserNSMode),
Privileged: service.Privileged,
@@ -713,13 +709,11 @@ func (s *composeService) buildContainerVolumes(ctx context.Context, p types.Proj
MOUNTS:
for _, m := range mountOptions {
volumeMounts[m.Target] = struct{}{}
// `Bind` API is used when host path need to be created if missing, `Mount` is preferred otherwise
if m.Type == mount.TypeBind || m.Type == mount.TypeNamedPipe {
// `Mount` is preferred but does not offer option to created host path if missing
// so `Bind` API is used here with raw volume string
// see https://github.com/moby/moby/issues/43483
for _, v := range service.Volumes {
if v.Target == m.Target && v.Bind != nil && v.Bind.CreateHostPath {
binds = append(binds, v.String())
binds = append(binds, fmt.Sprintf("%s:%s:%s", m.Source, m.Target, getBindMode(v.Bind, m.ReadOnly)))
continue MOUNTS
}
}
@@ -729,6 +723,23 @@ MOUNTS:
return volumeMounts, binds, mounts, nil
}
func getBindMode(bind *types.ServiceVolumeBind, readOnly bool) string {
mode := "rw"
if readOnly {
mode = "ro"
}
switch bind.SELinux {
case types.SELinuxShared:
mode += ",z"
case types.SELinuxPrivate:
mode += ",Z"
}
return mode
}
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
var mounts = map[string]mount.Mount{}
if inherit != nil {
@@ -1048,10 +1059,7 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi
for _, ipamConfig := range n.Ipam.Config {
config := network.IPAMConfig{
Subnet: ipamConfig.Subnet,
IPRange: ipamConfig.IPRange,
Gateway: ipamConfig.Gateway,
AuxAddress: ipamConfig.AuxiliaryAddresses,
Subnet: ipamConfig.Subnet,
}
createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
}

View File

@@ -143,6 +143,15 @@ func TestBuildContainerMountOptions(t *testing.T) {
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
}
func TestGetBindMode(t *testing.T) {
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{}, false), "rw")
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{}, true), "ro")
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxShared}, false), "rw,z")
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxPrivate}, false), "rw,Z")
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxShared}, true), "ro,z")
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxPrivate}, true), "ro,Z")
}
func TestGetDefaultNetworkMode(t *testing.T) {
t.Run("returns the network with the highest priority when service has multiple networks", func(t *testing.T) {
service := composetypes.ServiceConfig{

View File

@@ -23,7 +23,6 @@ import (
"time"
"github.com/compose-spec/compose-go/types"
"github.com/docker/cli/cli/registry/client"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/errdefs"
"golang.org/x/sync/errgroup"
@@ -82,7 +81,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
ops := s.ensureNetworksDown(ctx, project, w)
if options.Images != "" {
ops = append(ops, s.ensureImagesDown(ctx, project, options, w)...)
ops = append(ops, s.ensureImagesDown(ctx, projectName, options, w)...)
}
if options.Volumes {
@@ -90,7 +89,7 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
}
if !resourceToRemove && len(ops) == 0 {
fmt.Fprintf(s.stderr(), "Warning: No resource found to remove for project %q.\n", projectName)
w.Event(progress.NewEvent(projectName, progress.Done, "Warning: No resource found to remove"))
}
eg, _ := errgroup.WithContext(ctx)
@@ -114,9 +113,9 @@ func (s *composeService) ensureVolumesDown(ctx context.Context, project *types.P
return ops
}
func (s *composeService) ensureImagesDown(ctx context.Context, project *types.Project, options api.DownOptions, w progress.Writer) []downOp {
func (s *composeService) ensureImagesDown(ctx context.Context, projectName string, options api.DownOptions, w progress.Writer) []downOp {
var ops []downOp
for image := range s.getServiceImages(options, project) {
for image := range s.getServiceImages(options, projectName) {
image := image
ops = append(ops, func() error {
return s.removeImage(ctx, image, w)
@@ -132,11 +131,6 @@ func (s *composeService) ensureNetworksDown(ctx context.Context, project *types.
continue
}
networkName := n.Name
_, err := s.apiClient().NetworkInspect(ctx, networkName, moby.NetworkInspectOptions{})
if client.IsNotFound(err) {
return nil
}
ops = append(ops, func() error {
return s.removeNetwork(ctx, networkName, w)
})
@@ -144,15 +138,15 @@ func (s *composeService) ensureNetworksDown(ctx context.Context, project *types.
return ops
}
func (s *composeService) getServiceImages(options api.DownOptions, project *types.Project) map[string]struct{} {
func (s *composeService) getServiceImages(options api.DownOptions, projectName string) map[string]struct{} {
images := map[string]struct{}{}
for _, service := range project.Services {
for _, service := range options.Project.Services {
image := service.Image
if options.Images == "local" && image != "" {
continue
}
if image == "" {
image = getImageName(service, project.Name)
image = getImageName(service, projectName)
}
images[image] = struct{}{}
}
@@ -238,10 +232,7 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
func (s *composeService) getProjectWithResources(ctx context.Context, containers Containers, projectName string) (*types.Project, error) {
containers = containers.filter(isNotOneOff)
project, err := s.projectFromName(containers, projectName)
if err != nil && !api.IsNotFoundError(err) {
return nil, err
}
project, _ := s.projectFromName(containers, projectName)
volumes, err := s.actualVolumes(ctx, projectName)
if err != nil {

View File

@@ -23,6 +23,7 @@ import (
compose "github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/mocks"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
@@ -59,7 +60,6 @@ func TestDown(t *testing.T) {
api.EXPECT().ContainerRemove(gomock.Any(), "456", moby.ContainerRemoveOptions{Force: true}).Return(nil)
api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil)
api.EXPECT().NetworkInspect(gomock.Any(), "myProject_default", moby.NetworkInspectOptions{}).Return(moby.NetworkResource{Name: "myProject_default"}, nil)
api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil)
err := tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{})
@@ -94,7 +94,6 @@ func TestDownRemoveOrphans(t *testing.T) {
api.EXPECT().ContainerRemove(gomock.Any(), "789", moby.ContainerRemoveOptions{Force: true}).Return(nil)
api.EXPECT().ContainerRemove(gomock.Any(), "321", moby.ContainerRemoveOptions{Force: true}).Return(nil)
api.EXPECT().NetworkInspect(gomock.Any(), "myProject_default", moby.NetworkInspectOptions{}).Return(moby.NetworkResource{Name: "myProject_default"}, nil)
api.EXPECT().NetworkRemove(gomock.Any(), "myProject_default").Return(nil)
err := tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{RemoveOrphans: true})

View File

@@ -29,10 +29,9 @@ import (
"github.com/docker/compose/v2/pkg/utils"
)
func (s *composeService) Events(ctx context.Context, projectName string, options api.EventsOptions) error {
projectName = strings.ToLower(projectName)
func (s *composeService) Events(ctx context.Context, project string, options api.EventsOptions) error {
events, errors := s.apiClient().Events(ctx, moby.EventsOptions{
Filters: filters.NewArgs(projectFilter(projectName)),
Filters: filters.NewArgs(projectFilter(project)),
})
for {
select {

View File

@@ -18,31 +18,31 @@ package compose
import (
"context"
"strings"
"fmt"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command/container"
"github.com/docker/compose/v2/pkg/api"
moby "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
)
func (s *composeService) Exec(ctx context.Context, projectName string, options api.RunOptions) (int, error) {
projectName = strings.ToLower(projectName)
target, err := s.getExecTarget(ctx, projectName, options)
func (s *composeService) Exec(ctx context.Context, project string, opts api.RunOptions) (int, error) {
target, err := s.getExecTarget(ctx, project, opts)
if err != nil {
return 0, err
}
exec := container.NewExecOptions()
exec.Interactive = options.Interactive
exec.TTY = options.Tty
exec.Detach = options.Detach
exec.User = options.User
exec.Privileged = options.Privileged
exec.Workdir = options.WorkingDir
exec.Interactive = opts.Interactive
exec.TTY = opts.Tty
exec.Detach = opts.Detach
exec.User = opts.User
exec.Privileged = opts.Privileged
exec.Workdir = opts.WorkingDir
exec.Container = target.ID
exec.Command = options.Command
for _, v := range options.Environment {
exec.Command = opts.Command
for _, v := range opts.Environment {
err := exec.Env.Set(v)
if err != nil {
return 0, err
@@ -57,5 +57,19 @@ func (s *composeService) Exec(ctx context.Context, projectName string, options a
}
func (s *composeService) getExecTarget(ctx context.Context, projectName string, opts api.RunOptions) (moby.Container, error) {
return s.getSpecifiedContainer(ctx, projectName, oneOffInclude, false, opts.Service, opts.Index)
containers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs(
projectFilter(projectName),
serviceFilter(opts.Service),
containerNumberFilter(opts.Index),
),
})
if err != nil {
return moby.Container{}, err
}
if len(containers) < 1 {
return moby.Container{}, fmt.Errorf("service %q is not running container #%d", opts.Service, opts.Index)
}
container := containers[0]
return container, nil
}

View File

@@ -32,7 +32,6 @@ import (
)
func (s *composeService) Images(ctx context.Context, projectName string, options api.ImagesOptions) ([]api.ImageSummary, error) {
projectName = strings.ToLower(projectName)
allContainers, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
All: true,
Filters: filters.NewArgs(projectFilter(projectName)),

View File

@@ -19,7 +19,6 @@ package compose
import (
"context"
"fmt"
"strings"
moby "github.com/docker/docker/api/types"
"golang.org/x/sync/errgroup"
@@ -28,19 +27,19 @@ import (
"github.com/docker/compose/v2/pkg/progress"
)
func (s *composeService) Kill(ctx context.Context, projectName string, options api.KillOptions) error {
func (s *composeService) Kill(ctx context.Context, project string, options api.KillOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.kill(ctx, strings.ToLower(projectName), options)
return s.kill(ctx, project, options)
})
}
func (s *composeService) kill(ctx context.Context, projectName string, options api.KillOptions) error {
func (s *composeService) kill(ctx context.Context, project string, options api.KillOptions) error {
w := progress.ContextWriter(ctx)
services := options.Services
var containers Containers
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, services...)
containers, err := s.getContainers(ctx, project, oneOffInclude, false, services...)
if err != nil {
return err
}

View File

@@ -19,7 +19,6 @@ package compose
import (
"context"
"io"
"strings"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/utils"
@@ -29,7 +28,6 @@ import (
)
func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
projectName = strings.ToLower(projectName)
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...)
if err != nil {
return err

View File

@@ -18,7 +18,6 @@ package compose
import (
"context"
"strings"
moby "github.com/docker/docker/api/types"
"golang.org/x/sync/errgroup"
@@ -27,9 +26,9 @@ import (
"github.com/docker/compose/v2/pkg/progress"
)
func (s *composeService) Pause(ctx context.Context, projectName string, options api.PauseOptions) error {
func (s *composeService) Pause(ctx context.Context, project string, options api.PauseOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.pause(ctx, strings.ToLower(projectName), options)
return s.pause(ctx, project, options)
})
}
@@ -55,14 +54,14 @@ func (s *composeService) pause(ctx context.Context, project string, options api.
return eg.Wait()
}
func (s *composeService) UnPause(ctx context.Context, projectName string, options api.PauseOptions) error {
func (s *composeService) UnPause(ctx context.Context, project string, options api.PauseOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.unPause(ctx, strings.ToLower(projectName), options)
return s.unPause(ctx, project, options)
})
}
func (s *composeService) unPause(ctx context.Context, projectName string, options api.PauseOptions) error {
containers, err := s.getContainers(ctx, projectName, oneOffExclude, false, options.Services...)
func (s *composeService) unPause(ctx context.Context, project string, options api.PauseOptions) error {
containers, err := s.getContainers(ctx, project, oneOffExclude, false, options.Services...)
if err != nil {
return err
}

View File

@@ -19,7 +19,6 @@ package compose
import (
"context"
"fmt"
"strings"
"github.com/docker/compose/v2/pkg/api"
@@ -27,11 +26,10 @@ import (
"github.com/docker/docker/api/types/filters"
)
func (s *composeService) Port(ctx context.Context, projectName string, service string, port int, options api.PortOptions) (string, int, error) {
projectName = strings.ToLower(projectName)
func (s *composeService) Port(ctx context.Context, project string, service string, port int, options api.PortOptions) (string, int, error) {
list, err := s.apiClient().ContainerList(ctx, moby.ContainerListOptions{
Filters: filters.NewArgs(
projectFilter(projectName),
projectFilter(project),
serviceFilter(service),
containerNumberFilter(options.Index),
),

View File

@@ -19,7 +19,6 @@ package compose
import (
"context"
"sort"
"strings"
"golang.org/x/sync/errgroup"
@@ -27,7 +26,6 @@ import (
)
func (s *composeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
projectName = strings.ToLower(projectName)
oneOff := oneOffExclude
if options.All {
oneOff = oneOffInclude

View File

@@ -36,12 +36,12 @@ import (
"github.com/docker/compose/v2/pkg/progress"
)
func (s *composeService) Pull(ctx context.Context, project *types.Project, options api.PullOptions) error {
if options.Quiet {
return s.pull(ctx, project, options)
func (s *composeService) Pull(ctx context.Context, project *types.Project, opts api.PullOptions) error {
if opts.Quiet {
return s.pull(ctx, project, opts)
}
return progress.Run(ctx, func(ctx context.Context) error {
return s.pull(ctx, project, options)
return s.pull(ctx, project, opts)
})
}
@@ -55,11 +55,6 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
info.IndexServerAddress = registry.IndexServer
}
images, err := s.getLocalImagesDigests(ctx, project)
if err != nil {
return err
}
w := progress.ContextWriter(ctx)
eg, ctx := errgroup.WithContext(ctx)
@@ -74,28 +69,8 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
})
continue
}
switch service.PullPolicy {
case types.PullPolicyNever, types.PullPolicyBuild:
w.Event(progress.Event{
ID: service.Name,
Status: progress.Done,
Text: "Skipped",
})
continue
case types.PullPolicyMissing, types.PullPolicyIfNotPresent:
if _, ok := images[service.Image]; ok {
w.Event(progress.Event{
ID: service.Name,
Status: progress.Done,
Text: "Exists",
})
continue
}
}
eg.Go(func() error {
_, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false)
err := s.pullServiceImage(ctx, service, info, s.configFile(), w, false)
if err != nil {
if !opts.IgnoreFailures {
if service.Build != nil {
@@ -118,7 +93,7 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
return err
}
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) (string, error) {
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPull bool) error {
w.Event(progress.Event{
ID: service.Name,
Status: progress.Working,
@@ -126,12 +101,12 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
})
ref, err := reference.ParseNormalizedNamed(service.Image)
if err != nil {
return "", err
return err
}
repoInfo, err := registry.ParseRepositoryInfo(ref)
if err != nil {
return "", err
return err
}
key := repoInfo.Index.Name
@@ -141,12 +116,12 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
authConfig, err := configFile.GetAuthConfig(key)
if err != nil {
return "", err
return err
}
buf, err := json.Marshal(authConfig)
if err != nil {
return "", err
return err
}
stream, err := s.apiClient().ImagePull(ctx, service.Image, moby.ImagePullOptions{
@@ -159,7 +134,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
Status: progress.Error,
Text: "Error",
})
return "", WrapCategorisedComposeError(err, PullFailure)
return WrapCategorisedComposeError(err, PullFailure)
}
dec := json.NewDecoder(stream)
@@ -169,10 +144,10 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
if err == io.EOF {
break
}
return "", WrapCategorisedComposeError(err, PullFailure)
return WrapCategorisedComposeError(err, PullFailure)
}
if jm.Error != nil {
return "", WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
return WrapCategorisedComposeError(errors.New(jm.Error.Message), PullFailure)
}
if !quietPull {
toPullProgressEvent(service.Name, jm, w)
@@ -183,12 +158,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
Status: progress.Done,
Text: "Pulled",
})
inspected, _, err := s.dockerCli.Client().ImageInspectWithRaw(ctx, service.Image)
if err != nil {
return "", err
}
return inspected.ID, nil
return nil
}
func (s *composeService) pullRequiredImages(ctx context.Context, project *types.Project, images map[string]string, quietPull bool) error {
@@ -225,12 +195,10 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types.
return progress.Run(ctx, func(ctx context.Context) error {
w := progress.ContextWriter(ctx)
eg, ctx := errgroup.WithContext(ctx)
pulledImages := make([]string, len(needPull))
for i, service := range needPull {
i, service := i, service
for _, service := range needPull {
service := service
eg.Go(func() error {
id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
pulledImages[i] = id
err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull)
if err != nil && service.Build != nil {
// image can be built, so we can ignore pull failure
return nil
@@ -238,16 +206,7 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types.
return err
})
}
for i, service := range needPull {
if pulledImages[i] != "" {
images[service.Image] = pulledImages[i]
}
}
err := eg.Wait()
if err != nil {
return err
}
return err
return eg.Wait()
})
}

View File

@@ -30,7 +30,6 @@ import (
)
func (s *composeService) Remove(ctx context.Context, projectName string, options api.RemoveOptions) error {
projectName = strings.ToLower(projectName)
containers, _, err := s.actualState(ctx, projectName, options.Services)
if err != nil {
if api.IsNotFoundError(err) {

View File

@@ -18,7 +18,6 @@ package compose
import (
"context"
"strings"
"github.com/docker/compose/v2/pkg/api"
"golang.org/x/sync/errgroup"
@@ -29,7 +28,7 @@ import (
func (s *composeService) Restart(ctx context.Context, projectName string, options api.RestartOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.restart(ctx, strings.ToLower(projectName), options)
return s.restart(ctx, projectName, options)
})
}

View File

@@ -89,7 +89,7 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
updateServices(&service, observedState)
created, err := s.createContainer(ctx, project, service, service.ContainerName, 1,
opts.AutoRemove, opts.UseNetworkAliases, opts.Interactive)
opts.Detach && opts.AutoRemove, opts.UseNetworkAliases, opts.Interactive)
if err != nil {
return "", err
}

View File

@@ -18,7 +18,6 @@ package compose
import (
"context"
"strings"
"github.com/compose-spec/compose-go/types"
moby "github.com/docker/docker/api/types"
@@ -31,23 +30,20 @@ import (
func (s *composeService) Start(ctx context.Context, projectName string, options api.StartOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.start(ctx, strings.ToLower(projectName), options, nil)
return s.start(ctx, projectName, options, nil)
})
}
func (s *composeService) start(ctx context.Context, projectName string, options api.StartOptions, listener api.ContainerEventListener) error {
project := options.Project
if project == nil {
var containers Containers
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
if err != nil {
return err
}
var containers Containers
containers, err := s.getContainers(ctx, projectName, oneOffExclude, true)
if err != nil {
return err
}
project, err = s.projectFromName(containers, projectName, options.AttachTo...)
if err != nil {
return err
}
project, err := s.projectFromName(containers, projectName, options.AttachTo...)
if err != nil {
return err
}
eg, ctx := errgroup.WithContext(ctx)
@@ -59,12 +55,12 @@ func (s *composeService) start(ctx context.Context, projectName string, options
eg.Go(func() error {
return s.watchContainers(context.Background(), project.Name, options.AttachTo, listener, attached, func(container moby.Container) error {
return s.attachContainer(ctx, container, listener)
return s.attachContainer(ctx, container, listener, project)
})
})
}
err := InDependencyOrder(ctx, project, func(c context.Context, name string) error {
err = InDependencyOrder(ctx, project, func(c context.Context, name string) error {
service, err := project.GetService(name)
if err != nil {
return err

View File

@@ -18,7 +18,6 @@ package compose
import (
"context"
"strings"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
@@ -26,7 +25,7 @@ import (
func (s *composeService) Stop(ctx context.Context, projectName string, options api.StopOptions) error {
return progress.Run(ctx, func(ctx context.Context) error {
return s.stop(ctx, strings.ToLower(projectName), options)
return s.stop(ctx, projectName, options)
})
}

View File

@@ -18,14 +18,12 @@ package compose
import (
"context"
"strings"
"github.com/docker/compose/v2/pkg/api"
"golang.org/x/sync/errgroup"
)
func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]api.ContainerProcSummary, error) {
projectName = strings.ToLower(projectName)
var containers Containers
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false)
if err != nil {

View File

@@ -61,12 +61,12 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
go func() {
<-signalChan
s.Kill(ctx, project.Name, api.KillOptions{ // nolint:errcheck
Services: project.ServiceNames(),
Services: options.Create.Services,
})
}()
return s.Stop(ctx, project.Name, api.StopOptions{
Services: project.ServiceNames(),
Services: options.Create.Services,
})
})
}

View File

@@ -18,7 +18,6 @@ package e2e
import (
"net/http"
"os"
"strings"
"testing"
"time"
@@ -80,57 +79,6 @@ func TestLocalComposeBuild(t *testing.T) {
res.Assert(t, icmd.Expected{Out: `"RESULT": "SUCCESS"`})
})
t.Run("build failed with ssh default value", func(t *testing.T) {
//unset SSH_AUTH_SOCK to be sure we don't have a default value for the SSH Agent
defaultSSHAUTHSOCK := os.Getenv("SSH_AUTH_SOCK")
os.Unsetenv("SSH_AUTH_SOCK") //nolint:errcheck
defer os.Setenv("SSH_AUTH_SOCK", defaultSSHAUTHSOCK) //nolint:errcheck
res := c.RunDockerComposeCmdNoCheck("--project-directory", "fixtures/build-test", "build", "--ssh", "")
res.Assert(t, icmd.Expected{
ExitCode: 1,
Err: "invalid empty ssh agent socket: make sure SSH_AUTH_SOCK is set",
})
})
t.Run("build succeed with ssh from Compose file", func(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test-ssh")
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test/ssh", "build")
c.RunDockerCmd("image", "inspect", "build-test-ssh")
})
t.Run("build succeed with ssh from CLI", func(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test-ssh")
c.RunDockerComposeCmd("-f", "fixtures/build-test/ssh/compose-without-ssh.yaml", "--project-directory",
"fixtures/build-test/ssh", "build", "--no-cache", "--ssh", "fake-ssh=./fixtures/build-test/ssh/fake_rsa")
c.RunDockerCmd("image", "inspect", "build-test-ssh")
})
t.Run("build failed with wrong ssh key id from CLI", func(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test-ssh")
res := c.RunDockerComposeCmdNoCheck("-f", "fixtures/build-test/ssh/compose-without-ssh.yaml",
"--project-directory", "fixtures/build-test/ssh", "build", "--no-cache", "--ssh",
"wrong-ssh=./fixtures/build-test/ssh/fake_rsa")
res.Assert(t, icmd.Expected{
ExitCode: 17,
Err: "failed to solve: rpc error: code = Unknown desc = unset ssh forward key fake-ssh",
})
})
t.Run("build succeed as part of up with ssh from Compose file", func(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test-ssh")
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test/ssh", "up", "-d", "--build")
t.Cleanup(func() {
c.RunDockerComposeCmd("--project-directory", "fixtures/build-test/ssh", "down")
})
c.RunDockerCmd("image", "inspect", "build-test-ssh")
})
t.Run("build as part of up", func(t *testing.T) {
c.RunDockerOrExitError("rmi", "build-test_nginx")
c.RunDockerOrExitError("rmi", "custom-nginx")
@@ -169,36 +117,3 @@ func TestLocalComposeBuild(t *testing.T) {
c.RunDockerCmd("rmi", "custom-nginx")
})
}
func TestBuildSecrets(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
t.Run("build with secrets", func(t *testing.T) {
// ensure local test run does not reuse previously build image
c.RunDockerOrExitError("rmi", "build-test-secret")
res := c.RunDockerComposeCmd("--project-directory", "fixtures/build-test/secrets", "build")
res.Assert(t, icmd.Success)
})
}
func TestBuildTags(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
t.Run("build with tags", func(t *testing.T) {
// ensure local test run does not reuse previously build image
c.RunDockerOrExitError("rmi", "build-test-tags")
c.RunDockerComposeCmd("--project-directory", "./fixtures/build-test/tags", "build", "--no-cache")
res := c.RunDockerCmd("image", "inspect", "build-test-tags")
expectedOutput := `"RepoTags": [
"docker/build-test-tags:1.0.0",
"build-test-tags:latest",
"other-image-name:v1.0.0"
],
`
res.Assert(t, icmd.Expected{Out: expectedOutput})
})
}

View File

@@ -1,34 +0,0 @@
/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"testing"
"gotest.tools/v3/icmd"
)
func TestDown(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
const projectName = "e2e-down"
t.Run("no resource to remove", func(t *testing.T) {
res := c.RunDockerOrExitError("compose", "--project-name", projectName, "down")
res.Assert(t, icmd.Expected{ExitCode: 0, Err: `No resource found to remove for project "e2e-down"`})
})
}

View File

@@ -95,7 +95,7 @@ func TestLocalComposeUp(t *testing.T) {
res := c.RunDockerComposeCmd("-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: `NAME COMMAND SERVICE STATUS PORTS`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 "/dispatcher" web running (healthy) 0.0.0.0:90->80/tcp`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-web-1 "/dispatcher" web running (healthy) 0.0.0.0:90->80/tcp, :::90->80/tcp`})
res.Assert(t, icmd.Expected{Out: `compose-e2e-demo-db-1 "docker-entrypoint.s…" db running 5432/tcp`})
})

View File

@@ -47,18 +47,15 @@ func TestCopy(t *testing.T) {
res.Assert(t, icmd.Expected{Out: `nginx running`})
})
t.Run("copy to container copies the file to the all containers by default", func(t *testing.T) {
t.Run("copy to container copies the file to the first container by default", func(t *testing.T) {
res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/default.txt")
res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/default.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
output = c.RunDockerCmd("exec", projectName+"-nginx-2", "cat", "/tmp/default.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
output = c.RunDockerCmd("exec", projectName+"-nginx-3", "cat", "/tmp/default.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
res = c.RunDockerOrExitError("exec", projectName+"_nginx_2", "cat", "/tmp/default.txt")
res.Assert(t, icmd.Expected{ExitCode: 1})
})
t.Run("copy to container with a given index copies the file to the given container", func(t *testing.T) {
@@ -72,6 +69,20 @@ func TestCopy(t *testing.T) {
res.Assert(t, icmd.Expected{ExitCode: 1})
})
t.Run("copy to container with the all flag copies the file to all containers", func(t *testing.T) {
res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "--all", "./fixtures/cp-test/cp-me.txt", "nginx:/tmp/all.txt")
res.Assert(t, icmd.Expected{ExitCode: 0})
output := c.RunDockerCmd("exec", projectName+"-nginx-1", "cat", "/tmp/all.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
output = c.RunDockerCmd("exec", projectName+"-nginx-2", "cat", "/tmp/all.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
output = c.RunDockerCmd("exec", projectName+"-nginx-3", "cat", "/tmp/all.txt").Stdout()
assert.Assert(t, strings.Contains(output, `hello world`), output)
})
t.Run("copy from a container copies the file to the host from the first container by default", func(t *testing.T) {
res := c.RunDockerComposeCmd("-f", "./fixtures/cp-test/compose.yaml", "-p", projectName, "cp", "nginx:/tmp/default.txt", "./fixtures/cp-test/from-default.txt")
res.Assert(t, icmd.Expected{ExitCode: 0})

View File

@@ -66,6 +66,14 @@ func TestComposeRunDdev(t *testing.T) {
c.RunCmdInDir(dir, "tar", "-xzf", compressedFilename)
c.RunDockerCmd("pull", "drud/ddev-ssh-agent:v1.18.0")
c.RunDockerCmd("pull", "busybox:stable")
c.RunDockerCmd("pull", "phpmyadmin:5")
c.RunDockerCmd("pull", tagged("drud/ddev-router"))
c.RunDockerCmd("pull", tagged("drud/ddev-dbserver-mariadb-10.3"))
c.RunDockerCmd("pull", tagged("drud/ddev-webserver"))
// Create a simple index.php we can test against.
c.RunCmdInDir(dir, "sh", "-c", "echo '<?php\nprint \"ddev is working\";' >index.php")
@@ -84,3 +92,7 @@ func TestComposeRunDdev(t *testing.T) {
fmt.Println(out)
assert.Assert(c.test, strings.Contains(out, "ddev is working"), "Could not start project")
}
func tagged(img string) string {
return fmt.Sprintf("%s:%s", img, ddevVersion)
}

View File

@@ -1,22 +0,0 @@
# syntax=docker/dockerfile:1.2
# Copyright 2020 Docker Compose CLI authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine
RUN echo "foo" > /tmp/expected
RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret > /tmp/actual
RUN diff /tmp/expected /tmp/actual

View File

@@ -1,11 +0,0 @@
services:
ssh:
image: build-test-secret
build:
context: .
secrets:
- mysecret
secrets:
mysecret:
file: ./secret.txt

View File

@@ -1 +0,0 @@
foo

View File

@@ -1,24 +0,0 @@
# syntax=docker/dockerfile:1.2
# Copyright 2020 Docker Compose CLI authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine
RUN apk add --no-cache openssh-client
WORKDIR /compose
COPY fake_rsa.pub /compose/
RUN --mount=type=ssh,id=fake-ssh,required=true diff <(ssh-add -L) <(cat /compose/fake_rsa.pub)

View File

@@ -1,5 +0,0 @@
services:
ssh:
image: build-test-ssh
build:
context: .

View File

@@ -1,7 +0,0 @@
services:
ssh:
image: build-test-ssh
build:
context: .
ssh:
- fake-ssh=./fixtures/build-test/ssh/fake_rsa

View File

@@ -1,49 +0,0 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAgEA7nJ4xAhJ7VwI63tuay3DCHaTXeEY92H6YNZ8ptAIBY0mUn6Gc9ms
94HvcAKemCJkO0fy6U2JOoST+q1YPAJf86NrIU41hZdzrw2QdqG/A3ja4VTAaOJbH9wafK
HpWLs6kyigGti3KSBabm4HARU8lgtRE6AuCC1+mw821FzTsMWMxRp/rKVxgsiMUsdd57WR
KOdn8TRm6NHcEsy7X7zAJ7+Ch/muGGCCk3Z9+YUzoVVtY/wGYmWXXj/NUzxnEq0XLyO8HC
+QU/9dWlh1OLmoMuxN1lYtHRFWWstCboKNsOcIiJsLKfQ1t4z4jXq5P7JTLE5Pngemrr4x
K21RFjVaGQpOjyQgZn1o0wAvy78KORwgN0Elwcb/XIKJepzzezCIyXlSafeXuHP+oMjM2s
2MXNHlMKv6Jwh4QYwUQ61+bAcPkcmIdltiAMNLcxYiqEud85EQQl9ciuhMKa0bZl1OEILw
VSIasEu9BEKVrz52ZZVLGMchqOV/4f1PqPEagnfnRYEttJ6AuaYUaJXvSQP6Zj4AFb6WrP
wEBIFOuAH9i4WtG52QAK6uc1wsPZlHm8J+VnTEBKFuGERu/uJBWPo43Lju8VrHuZU8QeON
ERKfJbc1EI9XpqWi+3VcWT0QJtxEGW2YmD505+cKNc31xwOtcqwogtwT0wnuj0BAf33HY3
8AAAc465v1nOub9ZwAAAAHc3NoLXJzYQAAAgEA7nJ4xAhJ7VwI63tuay3DCHaTXeEY92H6
YNZ8ptAIBY0mUn6Gc9ms94HvcAKemCJkO0fy6U2JOoST+q1YPAJf86NrIU41hZdzrw2Qdq
G/A3ja4VTAaOJbH9wafKHpWLs6kyigGti3KSBabm4HARU8lgtRE6AuCC1+mw821FzTsMWM
xRp/rKVxgsiMUsdd57WRKOdn8TRm6NHcEsy7X7zAJ7+Ch/muGGCCk3Z9+YUzoVVtY/wGYm
WXXj/NUzxnEq0XLyO8HC+QU/9dWlh1OLmoMuxN1lYtHRFWWstCboKNsOcIiJsLKfQ1t4z4
jXq5P7JTLE5Pngemrr4xK21RFjVaGQpOjyQgZn1o0wAvy78KORwgN0Elwcb/XIKJepzzez
CIyXlSafeXuHP+oMjM2s2MXNHlMKv6Jwh4QYwUQ61+bAcPkcmIdltiAMNLcxYiqEud85EQ
Ql9ciuhMKa0bZl1OEILwVSIasEu9BEKVrz52ZZVLGMchqOV/4f1PqPEagnfnRYEttJ6Aua
YUaJXvSQP6Zj4AFb6WrPwEBIFOuAH9i4WtG52QAK6uc1wsPZlHm8J+VnTEBKFuGERu/uJB
WPo43Lju8VrHuZU8QeONERKfJbc1EI9XpqWi+3VcWT0QJtxEGW2YmD505+cKNc31xwOtcq
wogtwT0wnuj0BAf33HY38AAAADAQABAAACAGK7A0YoKHQfp5HZid7XE+ptLpewnKXR69os
9XAcszWZPETsHr/ZYcUaCApZC1Hy642gPPRdJnUUcDFblS1DzncTM0iXGZI3I69X7nkwf+
bwI7EpZoIHN7P5bv4sDHKxE4/bQm/bS/u7abZP2JaaNHvsM6XsrSK1s7aAljNYPE71fVQf
pL3Xwyhj4bZk1n0asQA+0MsO541/V6BxJSR/AxFyOpoSyANP8sEcTw0CGl6zAJhlwj770b
E0uc+9MvCIuxDJuxnwl9Iv6nd+KQtT1FFBhvk4tXVTuG3fu6IGbKTTBLWLfRPiClv2AvSR
3CKDs+ykgFLu2BWCqtlQakLH1IW9DTkPExV4ZjkGCRWHEvmJxxOqL6B48tBjwa5gBuPJRA
aYRi15Z3sprsqCBfp+aHPkMXkkNGSe5ROj8lFFY/f50ZS/9DSlyuUURFLtIGe5XuPNJk7L
xJkYJAdNbgvk4IPgzsU2EuYvSja5mtuo3dVyEIRtsIAN4xl01edDAxHEow6ar4gZCtXnBb
WqeqchEi4zVTdkkuDP3SF362pktdY7Op0mS/yFd8LFrca3VCy2PqNhKvlxClRqM9Tlp9cY
qDuyS9AGT1QO4BMtvSJGFa3P+h76rQsNldC+nGa4wNWvpAUcT5NS8W9QnGp7ah/qOK07t7
fwYYENeRaAK3OItBABAAABAFjyDlnERaZ+/23B+zN0kQhCvmiNS5HE2+ooR5ofX08F3Uar
VPevy9p6s2LA+AlXY1ZZ1k0p5MI+4TkAbcB/VXaxrRUw9633p9rAgyumFGhK3i0M4whOCO
MJxmlp5sz5Qea+YzIa9z0F4ZwwvdHt7cp5joYBZoQ+Kv9OUy4xCs1zZ4ZbEsakGBrtLiTo
H3odXSg0mXQf10Ae3WkvAJ8M1xL/z1ryFeCvyv1sGwEx+5gvmZ6nnuJEEuXUBlpOwhPlST
4X9VL7gmdH9OoHnhUn3q2JEBQdVTegGij9wvoYT1bdzwBN/Amisn29K9w1aNdrNbYUJ6PO
0kE2lotSJ11qD8MAAAEBAP6IRuU25yj7zv0mEsaRWoQ5v3fYKKn4C6Eg3DbzKXybZkLyX7
6QlyO7uWf54SdXM7sQW8KoXaMu9qbo/o+4o3m7YfOY1MYeTz3yICYObVA7Fc9ZHwKzc1PB
dFNzy6/G+2niNQF3Q1Fjp31Ve9LwKJK8Kj/eUYZ3QiUIropkw4ppA8q3h+nkVGS23xSrTM
kGLugBjcnWUfuN0tKx/b5mqziRoyzr5u0qzFDtx97QAyETo/onFrd1bMGED2BHVyrCwtqI
p6SXo2uFzwm/nLtOMlmfpixNcK6dtql/brx3Lsu18a+0a42O5Q/TYRdRq8D60O16rUS/LN
sFOjIYSA3spnUAAAEBAO/Sc3NTarFylk+yhOTE8G9xDt5ndbY0gsfhM9D4byKlY4yYIvs+
yQAq3UHgSoN2f087zNubXSNiLJ8TOIPpbk8MzdvjqcpmnBhHcd4V2FLe9+hC8zEBf8MPPf
Cy1kXdCZ0bDMLTdgONiDTIc/0YXhFLZherXNIF1o/7Pcnu6IPwMDl/gcG3H1ncDxaLqxAm
L29SDXLX2hH9k+YJr9kFaho7PZBAwNYnMooupROSbQ9/lmfCt09ep/83n5G0mo93uGkyV2
1wcQw9X2ZT8eVHZ4ni3ACC6VYbUn2M3Z+e3tpGaYzKXd/yq0YyppoRvEaxM/ewXappUJul
Xsd/RqSc66MAAAAAAQID
-----END OPENSSH PRIVATE KEY-----

View File

@@ -1 +0,0 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDucnjECEntXAjre25rLcMIdpNd4Rj3Yfpg1nym0AgFjSZSfoZz2az3ge9wAp6YImQ7R/LpTYk6hJP6rVg8Al/zo2shTjWFl3OvDZB2ob8DeNrhVMBo4lsf3Bp8oelYuzqTKKAa2LcpIFpubgcBFTyWC1EToC4ILX6bDzbUXNOwxYzFGn+spXGCyIxSx13ntZEo52fxNGbo0dwSzLtfvMAnv4KH+a4YYIKTdn35hTOhVW1j/AZiZZdeP81TPGcSrRcvI7wcL5BT/11aWHU4uagy7E3WVi0dEVZay0Jugo2w5wiImwsp9DW3jPiNerk/slMsTk+eB6auvjErbVEWNVoZCk6PJCBmfWjTAC/Lvwo5HCA3QSXBxv9cgol6nPN7MIjJeVJp95e4c/6gyMzazYxc0eUwq/onCHhBjBRDrX5sBw+RyYh2W2IAw0tzFiKoS53zkRBCX1yK6EwprRtmXU4QgvBVIhqwS70EQpWvPnZllUsYxyGo5X/h/U+o8RqCd+dFgS20noC5phRole9JA/pmPgAVvpas/AQEgU64Af2Lha0bnZAArq5zXCw9mUebwn5WdMQEoW4YRG7+4kFY+jjcuO7xWse5lTxB440REp8ltzUQj1empaL7dVxZPRAm3EQZbZiYPnTn5wo1zfXHA61yrCiC3BPTCe6PQEB/fcdjfw==

View File

@@ -1,17 +0,0 @@
# Copyright 2020 Docker Compose CLI authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM nginx:alpine
RUN echo "SUCCESS"

View File

@@ -1,9 +0,0 @@
services:
nginx:
image: build-test-tags
build:
context: .
tags:
- docker.io/docker/build-test-tags:1.0.0
- other-image-name:v1.0.0

View File

@@ -215,20 +215,17 @@ func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
// RunDockerComposeCmd runs a docker compose command, expects no error and returns a result
func (c *E2eCLI) RunDockerComposeCmd(args ...string) *icmd.Result {
res := c.RunDockerComposeCmdNoCheck(args...)
res.Assert(c.test, icmd.Success)
return res
}
// RunDockerComposeCmdNoCheck runs a docker compose command, don't presume of any expectation and returns a result
func (c *E2eCLI) RunDockerComposeCmdNoCheck(args ...string) *icmd.Result {
if composeStandaloneMode {
composeBinary, err := findExecutable(DockerComposeExecutableName, []string{"../../bin", "../../../bin"})
assert.NilError(c.test, err)
return icmd.RunCmd(c.NewCmd(composeBinary, args...))
res := icmd.RunCmd(c.NewCmd(composeBinary, args...))
res.Assert(c.test, icmd.Success)
return res
}
args = append([]string{"compose"}, args...)
return icmd.RunCmd(c.NewCmd(DockerExecutableName, args...))
res := icmd.RunCmd(c.NewCmd(DockerExecutableName, args...))
res.Assert(c.test, icmd.Success)
return res
}
// StdoutContains returns a predicate on command result expecting a string in stdout

View File

@@ -27,7 +27,7 @@ import (
func TestStartStop(t *testing.T) {
c := NewParallelE2eCLI(t, binDir)
const projectName = "e2e-start-stop-no-dependencies"
const projectName = "e2e-start-stop"
getProjectRegx := func(status string) string {
// match output with random spaces like:
@@ -43,7 +43,7 @@ func TestStartStop(t *testing.T) {
t.Run("Up a project", func(t *testing.T) {
res := c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "up", "-d")
assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop-no-dependencies-simple-1 Started"), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop-simple-1 Started"), res.Combined())
res = c.RunDockerComposeCmd("ls", "--all")
testify.Regexp(t, getProjectRegx("running"), res.Stdout())
@@ -57,13 +57,13 @@ func TestStartStop(t *testing.T) {
c.RunDockerComposeCmd("-f", "./fixtures/start-stop/compose.yaml", "--project-name", projectName, "stop")
res := c.RunDockerComposeCmd("ls")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-no-dependencies"), res.Combined())
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop"), res.Combined())
res = c.RunDockerComposeCmd("ls", "--all")
testify.Regexp(t, getProjectRegx("exited"), res.Stdout())
res = c.RunDockerComposeCmd("--project-name", projectName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-no-dependencies-words-1"), res.Combined())
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-words-1"), res.Combined())
res = c.RunDockerComposeCmd("--project-name", projectName, "ps", "--all")
testify.Regexp(t, getServiceRegx("simple", "exited"), res.Stdout())

View File

@@ -83,10 +83,7 @@ func (w *ttyWriter) Event(e Event) {
last.Status = e.Status
last.Text = e.Text
last.StatusText = e.StatusText
// allow set/unset of parent, but not swapping otherwise prompt is flickering
if last.ParentID == "" || e.ParentID == "" {
last.ParentID = e.ParentID
}
last.ParentID = e.ParentID
w.events[e.ID] = last
} else {
e.startTime = time.Now()