Compare commits

...

9 Commits

Author SHA1 Message Date
Nicolas De Loof
3394bf031b propagate target docker host set by --host to Bake
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-06-24 15:51:45 +02:00
dependabot[bot]
832a08f579 build(deps): bump github.com/moby/buildkit from 0.23.0 to 0.23.1
Bumps [github.com/moby/buildkit](https://github.com/moby/buildkit) from 0.23.0 to 0.23.1.
- [Release notes](https://github.com/moby/buildkit/releases)
- [Commits](https://github.com/moby/buildkit/compare/v0.23.0...v0.23.1)

---
updated-dependencies:
- dependency-name: github.com/moby/buildkit
  dependency-version: 0.23.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-24 15:39:44 +02:00
Nicolas De Loof
aadce87b16 inject secrets/config just before container is started
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-06-24 12:26:46 +02:00
Nicolas De Loof
b3207c455d setting buildOptions.Services triggers image to be always rebuilt
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-06-24 11:26:52 +02:00
Guillaume Lours
769b7391ba don't create from run command during dependencies creation process
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
2025-06-24 11:26:52 +02:00
Guillaume Lours
149b882ebf don't create from run command during dependencies creation process
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
2025-06-24 11:26:52 +02:00
Sebastiaan van Stijn
c97e40e2b8 pkg/compose: remove uses of ExecOptions.Detach
This field was added in [moby@5130fe5d38837302e], which
added it for use as intermediate struct when parsing CLI flags (through
`runconfig.ParseExec`) in [moby@c786a8ee5e9db8f5f].

Commit [moby@9d9dff3d0d9e92adf] rewrote the CLI to use
Cobra, and as part of this introduced a separate `execOptions` type in
`api/client/container`, however the ExecOptions.Detach field was still
used as intermediate field to store the flag's value.

Given that the client doesn't use this field, let's remove its use to
prevent giving the impression that it's used anywhere.

[moby@5130fe5d38837302e]: 5130fe5d38
[moby@c786a8ee5e9db8f5f]: c786a8ee5e
[moby@9d9dff3d0d9e92adf]: 9d9dff3d0d

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-06-23 21:05:38 +02:00
Nicolas De Loof
22e23bd4dc networkMode
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-06-22 20:50:35 +02:00
Nicolas De Loof
2dde5faeb8 add support for cache_to with bake
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-06-22 07:44:38 +02:00
8 changed files with 51 additions and 32 deletions

View File

@@ -282,7 +282,7 @@ func runRun(ctx context.Context, backend api.Service, project *types.Project, op
var buildForRun *api.BuildOptions
if !createOpts.noBuild {
bo, err := buildOpts.toAPIBuildOptions(project.ServiceNames())
bo, err := buildOpts.toAPIBuildOptions(nil)
if err != nil {
return err
}

4
go.mod
View File

@@ -9,7 +9,7 @@ require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/buger/goterm v1.0.4
github.com/compose-spec/compose-go/v2 v2.6.5
github.com/containerd/containerd/v2 v2.1.2
github.com/containerd/containerd/v2 v2.1.3
github.com/containerd/errdefs v1.0.0
github.com/containerd/platforms v1.0.0-rc.1
github.com/davecgh/go-spew v1.1.1
@@ -29,7 +29,7 @@ require (
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-ps v1.0.0
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/buildkit v0.23.0
github.com/moby/buildkit v0.23.1
github.com/moby/go-archive v0.1.0
github.com/moby/patternmatcher v0.6.0
github.com/moby/sys/atomicwriter v0.1.0

8
go.sum
View File

@@ -88,8 +88,8 @@ github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/q
github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/containerd/containerd/api v1.9.0 h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=
github.com/containerd/containerd/api v1.9.0/go.mod h1:GhghKFmTR3hNtyznBoQ0EMWr9ju5AqHjcZPsSpTKutI=
github.com/containerd/containerd/v2 v2.1.2 h1:4ZQxB+FVYmwXZgpBcKfar6ieppm3KC5C6FRKvtJ6DRU=
github.com/containerd/containerd/v2 v2.1.2/go.mod h1:8C5QV9djwsYDNhxfTCFjWtTBZrqjditQ4/ghHSYjnHM=
github.com/containerd/containerd/v2 v2.1.3 h1:eMD2SLcIQPdMlnlNF6fatlrlRLAeDaiGPGwmRKLZKNs=
github.com/containerd/containerd/v2 v2.1.3/go.mod h1:8C5QV9djwsYDNhxfTCFjWtTBZrqjditQ4/ghHSYjnHM=
github.com/containerd/continuity v0.4.5 h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=
github.com/containerd/continuity v0.4.5/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
@@ -317,8 +317,8 @@ github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/z
github.com/mitchellh/mapstructure v0.0.0-20150613213606-2caf8efc9366/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
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/moby/buildkit v0.23.0 h1:HV+u7xM2IZhAjVautFR2l5FNhkxFR0jhF5ILXyc3398=
github.com/moby/buildkit v0.23.0/go.mod h1:v5jMDvQgUyidk3wu3NvVAAd5JJo83nfet9Gf/o0+EAQ=
github.com/moby/buildkit v0.23.1 h1:CZtFmPRF+IFG1C8QfPnktGO1Dzzt5JSwtQ5eDqIh+ag=
github.com/moby/buildkit v0.23.1/go.mod h1:keNXljNmKX1T0AtM0bMObc8OV6mA9cOuquVbPcRpU/Y=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ=

View File

@@ -213,8 +213,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
Labels: build.Labels,
Tags: append(build.Tags, api.GetImageNameOrDefault(service, project.Name)),
CacheFrom: build.CacheFrom,
// CacheTo: TODO
CacheFrom: build.CacheFrom,
CacheTo: build.CacheTo,
NetworkMode: build.Network,
Platforms: build.Platforms,
Target: build.Target,
Secrets: toBakeSecrets(project, build.Secrets),
@@ -302,7 +303,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
cmd.Env = replace(cmd.Env, socket.EnvKey, server.Addr().String())
}
cmd.Env = append(cmd.Env, fmt.Sprintf("DOCKER_CONTEXT=%s", s.dockerCli.CurrentContext()))
cmd.Env = append(cmd.Env,
fmt.Sprintf("DOCKER_CONTEXT=%s", s.dockerCli.CurrentContext()),
fmt.Sprintf("DOCKER_HOST=%s", s.dockerCli.DockerEndpoint().Host),
)
// propagate opentelemetry context to child process, see https://github.com/open-telemetry/oteps/blob/main/text/0258-env-context-baggage-carriers.md
carrier := propagation.MapCarrier{}

View File

@@ -756,14 +756,7 @@ func (s *composeService) createMobyContainer(ctx context.Context,
}
}
}
err = s.injectSecrets(ctx, project, service, created.ID)
if err != nil {
return created, err
}
err = s.injectConfigs(ctx, project, service, created.ID)
return created, err
return created, nil
}
// getLinks mimics V1 compose/service.py::Service::_get_links()
@@ -897,6 +890,17 @@ func (s *composeService) startService(ctx context.Context,
if ctr.State == ContainerRunning {
continue
}
err = s.injectSecrets(ctx, project, service, ctr.ID)
if err != nil {
return err
}
err = s.injectConfigs(ctx, project, service, ctr.ID)
if err != nil {
return err
}
eventName := getContainerProgressName(ctr)
w.Event(progress.StartingEvent(eventName))
err = s.apiClient().ContainerStart(ctx, ctr.ID, containerType.StartOptions{})

View File

@@ -48,7 +48,6 @@ func (s composeService) runHook(ctx context.Context, ctr container.Summary, serv
Env: ToMobyEnv(hook.Environment),
WorkingDir: hook.WorkingDir,
Cmd: hook.Command,
Detach: detached,
AttachStdout: !detached,
AttachStderr: !detached,
})

View File

@@ -127,7 +127,14 @@ func (s *composeService) prepareRun(ctx context.Context, project *types.Project,
if err != nil {
return "", err
}
return created.ID, nil
err = s.injectSecrets(ctx, project, service, created.ID)
if err != nil {
return created.ID, err
}
err = s.injectConfigs(ctx, project, service, created.ID)
return created.ID, err
}
func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts api.RunOptions) {
@@ -176,18 +183,9 @@ func applyRunOptions(project *types.Project, service *types.ServiceConfig, opts
}
func (s *composeService) startDependencies(ctx context.Context, project *types.Project, options api.RunOptions) error {
var dependencies []string
for name := range project.Services {
if name != options.Service {
dependencies = append(dependencies, name)
}
}
project = project.WithServicesDisabled(options.Service)
project, err := project.WithSelectedServices(dependencies)
if err != nil {
return err
}
err = s.Create(ctx, project, api.CreateOptions{
err := s.Create(ctx, project, api.CreateOptions{
Build: options.Build,
IgnoreOrphans: options.IgnoreOrphans,
RemoveOrphans: options.RemoveOrphans,
@@ -197,7 +195,7 @@ func (s *composeService) startDependencies(ctx context.Context, project *types.P
return err
}
if len(dependencies) > 0 {
if len(project.Services) > 0 {
return s.Start(ctx, project.Name, api.StartOptions{
Project: project,
})

View File

@@ -196,4 +196,18 @@ func TestLocalComposeRun(t *testing.T) {
"front", "env")
res.Assert(t, icmd.Expected{Out: "FOO=BAR"})
})
t.Run("compose run -rm with stop signal", func(t *testing.T) {
projectName := "run-test"
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "-f", "./fixtures/ps-test/compose.yaml", "run", "--rm", "-d", "nginx")
res.Assert(t, icmd.Success)
res = c.RunDockerCmd(t, "ps", "--quiet", "--filter", "name=run-test-nginx")
containerID := strings.TrimSpace(res.Stdout())
res = c.RunDockerCmd(t, "stop", containerID)
res.Assert(t, icmd.Success)
res = c.RunDockerCmd(t, "ps", "--all", "--filter", "name=run-test-nginx", "--format", "'{{.Names}}'")
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test-nginx"), res.Stdout())
})
}