Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --include-deps to push command #10044

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions cmd/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"

"github.com/compose-spec/compose-go/types"
"github.com/morikuni/aec"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -67,23 +68,32 @@ func pullCommand(p *projectOptions, backend api.Service) *cobra.Command {
return cmd
}

func withSelectedServicesOnly(project *types.Project, services []string) error {
enabled, err := project.GetServices(services...)
if err != nil {
return err
}
for _, s := range project.Services {
if !utils.StringContains(services, s.Name) {
project.DisabledServices = append(project.DisabledServices, s)
}
}
project.Services = enabled

return nil
}

func runPull(ctx context.Context, backend api.Service, opts pullOptions, services []string) error {
project, err := opts.toProject(services)
if err != nil {
return err
}

if !opts.includeDeps {
enabled, err := project.GetServices(services...)
err := withSelectedServicesOnly(project, services)
if err != nil {
return err
}
for _, s := range project.Services {
if !utils.StringContains(services, s.Name) {
project.DisabledServices = append(project.DisabledServices, s)
}
}
project.Services = enabled
}

return backend.Pull(ctx, project, api.PullOptions{
Expand Down
10 changes: 9 additions & 1 deletion cmd/compose/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
type pushOptions struct {
*projectOptions
composeOptions

IncludeDeps bool
Ignorefailures bool
Quiet bool
}
Expand All @@ -45,6 +45,7 @@ func pushCommand(p *projectOptions, backend api.Service) *cobra.Command {
ValidArgsFunction: completeServiceNames(p),
}
pushCmd.Flags().BoolVar(&opts.Ignorefailures, "ignore-push-failures", false, "Push what it can and ignores images with push failures")
pushCmd.Flags().BoolVar(&opts.IncludeDeps, "include-deps", false, "Also push images of services declared as dependencies")
pushCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Push without printing progress information")

return pushCmd
Expand All @@ -56,6 +57,13 @@ func runPush(ctx context.Context, backend api.Service, opts pushOptions, service
return err
}

if !opts.IncludeDeps {
err := withSelectedServicesOnly(project, services)
if err != nil {
return err
}
}

return backend.Push(ctx, project, api.PushOptions{
IgnoreFailures: opts.Ignorefailures,
Quiet: opts.Quiet,
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compose_push.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Push service images
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `--ignore-push-failures` | | | Push what it can and ignores images with push failures |
| `--include-deps` | | | Also push images of services declared as dependencies |
| `-q`, `--quiet` | | | Push without printing progress information |


Expand Down
10 changes: 10 additions & 0 deletions docs/reference/docker_compose_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: include-deps
value_type: bool
default_value: "false"
description: Also push images of services declared as dependencies
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: quiet
shorthand: q
value_type: bool
Expand Down