-
Notifications
You must be signed in to change notification settings - Fork 5.7k
introduce publish (alpha) command #10949
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,18 +26,16 @@ import ( | |
| "strings" | ||
| "syscall" | ||
|
|
||
| buildx "github.com/docker/buildx/util/progress" | ||
|
|
||
| "github.com/compose-spec/compose-go/dotenv" | ||
| "github.com/docker/cli/cli/command" | ||
| "github.com/docker/compose/v2/pkg/remote" | ||
|
|
||
| "github.com/compose-spec/compose-go/cli" | ||
| "github.com/compose-spec/compose-go/dotenv" | ||
| "github.com/compose-spec/compose-go/types" | ||
| composegoutils "github.com/compose-spec/compose-go/utils" | ||
| "github.com/docker/buildx/util/logutil" | ||
| buildx "github.com/docker/buildx/util/progress" | ||
| dockercli "github.com/docker/cli/cli" | ||
| "github.com/docker/cli/cli-plugins/manager" | ||
| "github.com/docker/cli/cli/command" | ||
| "github.com/docker/compose/v2/pkg/remote" | ||
| "github.com/morikuni/aec" | ||
| "github.com/pkg/errors" | ||
| "github.com/sirupsen/logrus" | ||
|
|
@@ -119,6 +117,7 @@ type ProjectOptions struct { | |
| EnvFiles []string | ||
| Compatibility bool | ||
| Progress string | ||
| Offline bool | ||
| } | ||
|
|
||
| // ProjectFunc does stuff within a types.Project | ||
|
|
@@ -128,34 +127,22 @@ type ProjectFunc func(ctx context.Context, project *types.Project) error | |
| type ProjectServicesFunc func(ctx context.Context, project *types.Project, services []string) error | ||
|
|
||
| // WithProject creates a cobra run command from a ProjectFunc based on configured project options and selected services | ||
| func (o *ProjectOptions) WithProject(fn ProjectFunc) func(cmd *cobra.Command, args []string) error { | ||
| return o.WithServices(func(ctx context.Context, project *types.Project, services []string) error { | ||
| func (o *ProjectOptions) WithProject(fn ProjectFunc, dockerCli command.Cli) func(cmd *cobra.Command, args []string) error { | ||
| return o.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error { | ||
| return fn(ctx, project) | ||
| }) | ||
| } | ||
|
|
||
| // WithServices creates a cobra run command from a ProjectFunc based on configured project options and selected services | ||
| func (o *ProjectOptions) WithServices(fn ProjectServicesFunc) func(cmd *cobra.Command, args []string) error { | ||
| func (o *ProjectOptions) WithServices(dockerCli command.Cli, fn ProjectServicesFunc) func(cmd *cobra.Command, args []string) error { | ||
| return Adapt(func(ctx context.Context, args []string) error { | ||
| options := []cli.ProjectOptionsFn{ | ||
| cli.WithResolvedPaths(true), | ||
| cli.WithDiscardEnvFile, | ||
| cli.WithContext(ctx), | ||
| } | ||
|
|
||
| enabled, err := remote.GitRemoteLoaderEnabled() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if enabled { | ||
| git, err := remote.NewGitRemoteLoader() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| options = append(options, cli.WithResourceLoader(git)) | ||
| } | ||
|
|
||
| project, err := o.ToProject(args, options...) | ||
| project, err := o.ToProject(dockerCli, args, options...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -176,11 +163,11 @@ func (o *ProjectOptions) addProjectFlags(f *pflag.FlagSet) { | |
| _ = f.MarkHidden("workdir") | ||
| } | ||
|
|
||
| func (o *ProjectOptions) projectOrName(services ...string) (*types.Project, string, error) { | ||
| func (o *ProjectOptions) projectOrName(dockerCli command.Cli, services ...string) (*types.Project, string, error) { | ||
| name := o.ProjectName | ||
| var project *types.Project | ||
| if len(o.ConfigPaths) > 0 || o.ProjectName == "" { | ||
| p, err := o.ToProject(services, cli.WithDiscardEnvFile) | ||
| p, err := o.ToProject(dockerCli, services, cli.WithDiscardEnvFile) | ||
| if err != nil { | ||
| envProjectName := os.Getenv(ComposeProjectName) | ||
| if envProjectName != "" { | ||
|
|
@@ -194,7 +181,7 @@ func (o *ProjectOptions) projectOrName(services ...string) (*types.Project, stri | |
| return project, name, nil | ||
| } | ||
|
|
||
| func (o *ProjectOptions) toProjectName() (string, error) { | ||
| func (o *ProjectOptions) toProjectName(dockerCli command.Cli) (string, error) { | ||
| if o.ProjectName != "" { | ||
| return o.ProjectName, nil | ||
| } | ||
|
|
@@ -204,14 +191,22 @@ func (o *ProjectOptions) toProjectName() (string, error) { | |
| return envProjectName, nil | ||
| } | ||
|
|
||
| project, err := o.ToProject(nil) | ||
| project, err := o.ToProject(dockerCli, nil) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return project.Name, nil | ||
| } | ||
|
|
||
| func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) { | ||
| func (o *ProjectOptions) ToProject(dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) { | ||
| if !o.Offline { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this was a very elegant solution! ✨ |
||
| var err error | ||
| po, err = o.configureRemoteLoaders(dockerCli, po) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| options, err := o.toProjectOptions(po...) | ||
| if err != nil { | ||
| return nil, compose.WrapComposeError(err) | ||
|
|
@@ -256,6 +251,33 @@ func (o *ProjectOptions) ToProject(services []string, po ...cli.ProjectOptionsFn | |
| return project, err | ||
| } | ||
|
|
||
| func (o *ProjectOptions) configureRemoteLoaders(dockerCli command.Cli, po []cli.ProjectOptionsFn) ([]cli.ProjectOptionsFn, error) { | ||
| enabled, err := remote.GitRemoteLoaderEnabled() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if enabled { | ||
| git, err := remote.NewGitRemoteLoader(o.Offline) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| po = append(po, cli.WithResourceLoader(git)) | ||
| } | ||
|
|
||
| enabled, err = remote.OCIRemoteLoaderEnabled() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if enabled { | ||
| git, err := remote.NewOCIRemoteLoader(dockerCli, o.Offline) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| po = append(po, cli.WithResourceLoader(git)) | ||
| } | ||
| return po, nil | ||
| } | ||
|
|
||
| func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) { | ||
| return cli.NewProjectOptions(o.ConfigPaths, | ||
| append(po, | ||
|
|
@@ -429,32 +451,32 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { // | |
|
|
||
| c.AddCommand( | ||
| upCommand(&opts, dockerCli, backend), | ||
| downCommand(&opts, backend), | ||
| startCommand(&opts, backend), | ||
| restartCommand(&opts, backend), | ||
| stopCommand(&opts, backend), | ||
| downCommand(&opts, dockerCli, backend), | ||
| startCommand(&opts, dockerCli, backend), | ||
| restartCommand(&opts, dockerCli, backend), | ||
| stopCommand(&opts, dockerCli, backend), | ||
| psCommand(&opts, dockerCli, backend), | ||
| listCommand(dockerCli, backend), | ||
| logsCommand(&opts, dockerCli, backend), | ||
| configCommand(&opts, dockerCli, backend), | ||
| killCommand(&opts, backend), | ||
| killCommand(&opts, dockerCli, backend), | ||
| runCommand(&opts, dockerCli, backend), | ||
| removeCommand(&opts, backend), | ||
| removeCommand(&opts, dockerCli, backend), | ||
| execCommand(&opts, dockerCli, backend), | ||
| pauseCommand(&opts, backend), | ||
| unpauseCommand(&opts, backend), | ||
| pauseCommand(&opts, dockerCli, backend), | ||
| unpauseCommand(&opts, dockerCli, backend), | ||
| topCommand(&opts, dockerCli, backend), | ||
| eventsCommand(&opts, dockerCli, backend), | ||
| portCommand(&opts, dockerCli, backend), | ||
| imagesCommand(&opts, dockerCli, backend), | ||
| versionCommand(dockerCli), | ||
| buildCommand(&opts, backend), | ||
| pushCommand(&opts, backend), | ||
| pullCommand(&opts, backend), | ||
| createCommand(&opts, backend), | ||
| copyCommand(&opts, backend), | ||
| waitCommand(&opts, backend), | ||
| alphaCommand(&opts, backend), | ||
| buildCommand(&opts, dockerCli, backend), | ||
| pushCommand(&opts, dockerCli, backend), | ||
| pullCommand(&opts, dockerCli, backend), | ||
| createCommand(&opts, dockerCli, backend), | ||
| copyCommand(&opts, dockerCli, backend), | ||
| waitCommand(&opts, dockerCli, backend), | ||
| alphaCommand(&opts, dockerCli, backend), | ||
| ) | ||
|
|
||
| c.Flags().SetInterspersed(false) | ||
|
|
@@ -477,7 +499,7 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { // | |
| ) | ||
| c.RegisterFlagCompletionFunc( //nolint:errcheck | ||
| "profile", | ||
| completeProfileNames(&opts), | ||
| completeProfileNames(dockerCli, &opts), | ||
| ) | ||
|
|
||
| c.Flags().StringVar(&ansi, "ansi", "auto", `Control when to print ANSI control characters ("never"|"always"|"auto")`) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.