Add --include-deps to push command

Signed-off-by: Gabriel Féron <g@leirbag.net>
This commit is contained in:
Gabriel Féron 2022-12-09 17:42:46 +01:00 committed by Nicolas De loof
parent 8c39b5b7fd
commit e4850d9c48
4 changed files with 34 additions and 11 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/compose-spec/compose-go/types"
"github.com/morikuni/aec" "github.com/morikuni/aec"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -67,6 +68,21 @@ func pullCommand(p *projectOptions, backend api.Service) *cobra.Command {
return cmd return cmd
} }
func FilterServices(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 { func runPull(ctx context.Context, backend api.Service, opts pullOptions, services []string) error {
project, err := opts.toProject(services) project, err := opts.toProject(services)
if err != nil { if err != nil {
@ -74,16 +90,7 @@ func runPull(ctx context.Context, backend api.Service, opts pullOptions, service
} }
if !opts.includeDeps { if !opts.includeDeps {
enabled, err := project.GetServices(services...) FilterServices(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{ return backend.Pull(ctx, project, api.PullOptions{

View File

@ -27,7 +27,7 @@ import (
type pushOptions struct { type pushOptions struct {
*projectOptions *projectOptions
composeOptions composeOptions
IncludeDeps bool
Ignorefailures bool Ignorefailures bool
Quiet bool Quiet bool
} }
@ -45,6 +45,7 @@ func pushCommand(p *projectOptions, backend api.Service) *cobra.Command {
ValidArgsFunction: completeServiceNames(p), 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.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") pushCmd.Flags().BoolVarP(&opts.Quiet, "quiet", "q", false, "Push without printing progress information")
return pushCmd return pushCmd
@ -56,6 +57,10 @@ func runPush(ctx context.Context, backend api.Service, opts pushOptions, service
return err return err
} }
if !opts.IncludeDeps {
FilterServices(project, services)
}
return backend.Push(ctx, project, api.PushOptions{ return backend.Push(ctx, project, api.PushOptions{
IgnoreFailures: opts.Ignorefailures, IgnoreFailures: opts.Ignorefailures,
Quiet: opts.Quiet, Quiet: opts.Quiet,

View File

@ -8,6 +8,7 @@ Push service images
| Name | Type | Default | Description | | Name | Type | Default | Description |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| `--ignore-push-failures` | | | Push what it can and ignores images with push failures | | `--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 | | `-q`, `--quiet` | | | Push without printing progress information |

View File

@ -33,6 +33,16 @@ options:
experimentalcli: false experimentalcli: false
kubernetes: false kubernetes: false
swarm: 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 - option: quiet
shorthand: q shorthand: q
value_type: bool value_type: bool