Skip to content

Commit 865a64a

Browse files
committed
introduce --all-resources to _not_ exclude resources not used by services
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 29692b5 commit 865a64a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

cmd/compose/compose.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type ProjectOptions struct {
132132
Compatibility bool
133133
Progress string
134134
Offline bool
135+
All bool
135136
}
136137

137138
// ProjectFunc does stuff within a types.Project
@@ -175,6 +176,7 @@ func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) {
175176
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)")
176177
f.BoolVar(&o.Compatibility, "compatibility", false, "Run compose in backward compatibility mode")
177178
f.StringVar(&o.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of progress output (%s)`, strings.Join(printerModes, ", ")))
179+
f.BoolVar(&o.All, "all-resources", false, "Include all resources, even those not used by services")
178180
_ = f.MarkHidden("workdir")
179181
}
180182

@@ -231,9 +233,8 @@ func (o *ProjectOptions) ToModel(ctx context.Context, dockerCli command.Cli, ser
231233
return options.LoadModel(ctx)
232234
}
233235

234-
func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, tracing.Metrics, error) {
236+
func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, tracing.Metrics, error) { //nolint:gocyclo
235237
var metrics tracing.Metrics
236-
237238
remotes := o.remoteLoaders(dockerCli)
238239
for _, r := range remotes {
239240
po = append(po, cli.WithResourceLoader(r))
@@ -300,7 +301,9 @@ func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, s
300301
project.Services[name] = s
301302
}
302303

303-
project = project.WithoutUnnecessaryResources()
304+
if !o.All {
305+
project = project.WithoutUnnecessaryResources()
306+
}
304307

305308
project, err = project.WithSelectedServices(services)
306309
return project, metrics, err

cmd/compose/up.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service, ex
125125

126126
up.validateNavigationMenu(dockerCli, experiments)
127127

128+
if !p.All && len(project.Services) == 0 {
129+
return fmt.Errorf("no service selected")
130+
}
131+
128132
return runUp(ctx, dockerCli, backend, create, up, build, project, services)
129133
}),
130134
ValidArgsFunction: completeServiceNames(dockerCli, p),
@@ -205,10 +209,6 @@ func runUp(
205209
project *types.Project,
206210
services []string,
207211
) error {
208-
if len(project.Services) == 0 {
209-
return fmt.Errorf("no service selected")
210-
}
211-
212212
err := createOptions.Apply(project)
213213
if err != nil {
214214
return err

docs/reference/compose.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Define and run multi-container applications with Docker
4343

4444
| Name | Type | Default | Description |
4545
|:-----------------------|:--------------|:--------|:----------------------------------------------------------------------------------------------------|
46+
| `--all-resources` | | | Include all resources, even those not used by services |
4647
| `--ansi` | `string` | `auto` | Control when to print ANSI control characters ("never"\|"always"\|"auto") |
4748
| `--compatibility` | | | Run compose in backward compatibility mode |
4849
| `--dry-run` | | | Execute command in dry run mode |

docs/reference/docker_compose.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ clink:
208208
- docker_compose_wait.yaml
209209
- docker_compose_watch.yaml
210210
options:
211+
- option: all-resources
212+
value_type: bool
213+
default_value: "false"
214+
description: Include all resources, even those not used by services
215+
deprecated: false
216+
hidden: false
217+
experimental: false
218+
experimentalcli: false
219+
kubernetes: false
220+
swarm: false
211221
- option: ansi
212222
value_type: string
213223
default_value: auto

0 commit comments

Comments
 (0)