Skip to content

Commit e4850d9

Browse files
gferonndeloof
authored andcommitted
Add --include-deps to push command
Signed-off-by: Gabriel Féron <[email protected]>
1 parent 8c39b5b commit e4850d9

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

cmd/compose/pull.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323

24+
"github.com/compose-spec/compose-go/types"
2425
"github.com/morikuni/aec"
2526
"github.com/spf13/cobra"
2627

@@ -67,23 +68,29 @@ func pullCommand(p *projectOptions, backend api.Service) *cobra.Command {
6768
return cmd
6869
}
6970

71+
func FilterServices(project *types.Project, services []string) error {
72+
enabled, err := project.GetServices(services...)
73+
if err != nil {
74+
return err
75+
}
76+
for _, s := range project.Services {
77+
if !utils.StringContains(services, s.Name) {
78+
project.DisabledServices = append(project.DisabledServices, s)
79+
}
80+
}
81+
project.Services = enabled
82+
83+
return nil
84+
}
85+
7086
func runPull(ctx context.Context, backend api.Service, opts pullOptions, services []string) error {
7187
project, err := opts.toProject(services)
7288
if err != nil {
7389
return err
7490
}
7591

7692
if !opts.includeDeps {
77-
enabled, err := project.GetServices(services...)
78-
if err != nil {
79-
return err
80-
}
81-
for _, s := range project.Services {
82-
if !utils.StringContains(services, s.Name) {
83-
project.DisabledServices = append(project.DisabledServices, s)
84-
}
85-
}
86-
project.Services = enabled
93+
FilterServices(project, services)
8794
}
8895

8996
return backend.Pull(ctx, project, api.PullOptions{

cmd/compose/push.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
type pushOptions struct {
2828
*projectOptions
2929
composeOptions
30-
30+
IncludeDeps bool
3131
Ignorefailures bool
3232
Quiet bool
3333
}
@@ -45,6 +45,7 @@ func pushCommand(p *projectOptions, backend api.Service) *cobra.Command {
4545
ValidArgsFunction: completeServiceNames(p),
4646
}
4747
pushCmd.Flags().BoolVar(&opts.Ignorefailures, "ignore-push-failures", false, "Push what it can and ignores images with push failures")
48+
pushCmd.Flags().BoolVar(&opts.IncludeDeps, "include-deps", false, "Also push images of services declared as dependencies")
4849
pushCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Push without printing progress information")
4950

5051
return pushCmd
@@ -56,6 +57,10 @@ func runPush(ctx context.Context, backend api.Service, opts pushOptions, service
5657
return err
5758
}
5859

60+
if !opts.IncludeDeps {
61+
FilterServices(project, services)
62+
}
63+
5964
return backend.Push(ctx, project, api.PushOptions{
6065
IgnoreFailures: opts.Ignorefailures,
6166
Quiet: opts.Quiet,

docs/reference/compose_push.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Push service images
88
| Name | Type | Default | Description |
99
| --- | --- | --- | --- |
1010
| `--ignore-push-failures` | | | Push what it can and ignores images with push failures |
11+
| `--include-deps` | | | Also push images of services declared as dependencies |
1112
| `-q`, `--quiet` | | | Push without printing progress information |
1213

1314

docs/reference/docker_compose_push.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ options:
3333
experimentalcli: false
3434
kubernetes: false
3535
swarm: false
36+
- option: include-deps
37+
value_type: bool
38+
default_value: "false"
39+
description: Also push images of services declared as dependencies
40+
deprecated: false
41+
hidden: false
42+
experimental: false
43+
experimentalcli: false
44+
kubernetes: false
45+
swarm: false
3646
- option: quiet
3747
shorthand: q
3848
value_type: bool

0 commit comments

Comments
 (0)