Skip to content

Commit 84bd305

Browse files
committed
use compose-go PR to run tests on CI
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 32cef96 commit 84bd305

6 files changed

Lines changed: 41 additions & 30 deletions

File tree

cmd/compose/run.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,12 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen
187187
return err
188188
}
189189

190-
project, _, err := p.ToProject(ctx, dockerCli, backend, nil, composecli.WithoutEnvironmentResolution)
190+
project, _, err := p.ToProject(ctx, dockerCli, backend, []string{options.ServiceOrJob}, composecli.WithoutEnvironmentResolution)
191191
if err != nil {
192192
return err
193193
}
194194

195195
isJob := isJobName(project, options.ServiceOrJob)
196-
if isJob {
197-
project, err = project.WithSelectedJob(options.ServiceOrJob)
198-
} else {
199-
project, err = project.WithSelectedServices([]string{options.ServiceOrJob})
200-
}
201-
if err != nil {
202-
return err
203-
}
204196

205197
project, err = project.WithServicesEnvironmentResolved(true)
206198
if err != nil {

docs/reference/compose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Define and run multi-container applications with Docker
3535
| [`push`](compose_push.md) | Push service images |
3636
| [`restart`](compose_restart.md) | Restart service containers |
3737
| [`rm`](compose_rm.md) | Removes stopped service containers |
38-
| [`run`](compose_run.md) | Run a one-off command on a service |
38+
| [`run`](compose_run.md) | Run a one-off command on a service or job |
3939
| [`scale`](compose_scale.md) | Scale services |
4040
| [`start`](compose_start.md) | Start services |
4141
| [`stats`](compose_stats.md) | Display a live stream of container(s) resource usage statistics |

docs/reference/docker_compose_run.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
command: docker compose run
2-
short: Run a one-off command on a service
2+
short: Run a one-off command on a service or job
33
long: |-
44
Runs a one-time command against a service.
55
@@ -54,7 +54,7 @@ long: |-
5454
5555
This runs a database upgrade script, and removes the container when finished running, even if a restart policy is
5656
specified in the service configuration.
57-
usage: docker compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]
57+
usage: docker compose run [OPTIONS] SERVICE|JOB [COMMAND] [ARGS...]
5858
pname: docker compose
5959
plink: docker_compose.yaml
6060
options:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ require (
147147
gopkg.in/yaml.v3 v3.0.1 // indirect
148148
)
149149

150-
replace github.com/compose-spec/compose-go/v2 => /Users/nicolas/go/src/github.com/compose-spec/compose-go
150+
replace github.com/compose-spec/compose-go/v2 => github.com/ndeloof/compose-go/v2 v2.0.1-0.20260417132041-a0f7078b3027
151151

152152
exclude (
153153
// FIXME(thaJeztah): remove this once kubernetes updated their dependencies to no longer need this.

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
272272
github.com/morikuni/aec v1.1.0/go.mod h1:xDRgiq/iw5l+zkao76YTKzKttOp2cwPEne25HDkJnBw=
273273
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
274274
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
275-
github.com/ndeloof/compose-go/v2 v2.0.1-0.20260417075248-f37d49c3e808 h1:j9xyZ+njAa42UU2nW8d9tGAtg/Sh/v/t1nG7heRytWw=
276-
github.com/ndeloof/compose-go/v2 v2.0.1-0.20260417075248-f37d49c3e808/go.mod h1:ZU6zlcweCZKyiB7BVfCizQT9XmkEIMFE+PRZydVcsZg=
275+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20260417132041-a0f7078b3027 h1:djnpaPpekm8X6oSswGFeFk/8jB4hgXZCP6KqZ8WZXe0=
276+
github.com/ndeloof/compose-go/v2 v2.0.1-0.20260417132041-a0f7078b3027/go.mod h1:ZU6zlcweCZKyiB7BVfCizQT9XmkEIMFE+PRZydVcsZg=
277277
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
278278
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
279279
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=

pkg/compose/loader.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,28 @@ func (s *composeService) postProcessProject(project *types.Project, options api.
122122
return nil, errors.New("project name can't be empty. Use ProjectName option to set a valid name")
123123
}
124124

125+
// When the target is a job, skip service-oriented processing (profiles, service selection)
126+
// and only select the job's service dependencies.
127+
if len(options.Services) == 1 && project.Jobs != nil {
128+
if _, ok := project.Jobs[options.Services[0]]; ok {
129+
s.addCustomLabels(project, options)
130+
project, err := project.WithSelectedJob(options.Services[0])
131+
if err != nil {
132+
return nil, err
133+
}
134+
if !options.All {
135+
project = project.WithoutUnnecessaryResources()
136+
}
137+
return project, nil
138+
}
139+
}
140+
125141
project, err := project.WithServicesEnabled(options.Services...)
126142
if err != nil {
127143
return nil, err
128144
}
129145

130-
// Add custom labels
131-
for name, s := range project.Services {
132-
s.CustomLabels = map[string]string{
133-
api.ProjectLabel: project.Name,
134-
api.ServiceLabel: name,
135-
api.VersionLabel: api.ComposeVersion,
136-
api.WorkingDirLabel: project.WorkingDir,
137-
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
138-
api.OneoffLabel: "False",
139-
}
140-
if len(options.EnvFiles) != 0 {
141-
s.CustomLabels[api.EnvironmentFileLabel] = strings.Join(options.EnvFiles, ",")
142-
}
143-
project.Services[name] = s
144-
}
146+
s.addCustomLabels(project, options)
145147

146148
project, err = project.WithSelectedServices(options.Services)
147149
if err != nil {
@@ -155,3 +157,20 @@ func (s *composeService) postProcessProject(project *types.Project, options api.
155157

156158
return project, nil
157159
}
160+
161+
func (s *composeService) addCustomLabels(project *types.Project, options api.ProjectLoadOptions) {
162+
for name, svc := range project.Services {
163+
svc.CustomLabels = map[string]string{
164+
api.ProjectLabel: project.Name,
165+
api.ServiceLabel: name,
166+
api.VersionLabel: api.ComposeVersion,
167+
api.WorkingDirLabel: project.WorkingDir,
168+
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
169+
api.OneoffLabel: "False",
170+
}
171+
if len(options.EnvFiles) != 0 {
172+
svc.CustomLabels[api.EnvironmentFileLabel] = strings.Join(options.EnvFiles, ",")
173+
}
174+
project.Services[name] = svc
175+
}
176+
}

0 commit comments

Comments
 (0)