push.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "context"
  16. "github.com/spf13/cobra"
  17. "github.com/docker/compose-cli/api/client"
  18. "github.com/docker/compose-cli/api/compose"
  19. "github.com/docker/compose-cli/api/progress"
  20. )
  21. type pushOptions struct {
  22. *projectOptions
  23. composeOptions
  24. Ignorefailures bool
  25. }
  26. func pushCommand(p *projectOptions) *cobra.Command {
  27. opts := pushOptions{
  28. projectOptions: p,
  29. }
  30. pushCmd := &cobra.Command{
  31. Use: "push [SERVICE...]",
  32. Short: "Push service images",
  33. RunE: func(cmd *cobra.Command, args []string) error {
  34. return runPush(cmd.Context(), opts, args)
  35. },
  36. }
  37. pushCmd.Flags().BoolVar(&opts.Ignorefailures, "ignore-push-failures", false, "Push what it can and ignores images with push failures")
  38. return pushCmd
  39. }
  40. func runPush(ctx context.Context, opts pushOptions, services []string) error {
  41. c, err := client.NewWithDefaultLocalBackend(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. project, err := opts.toProject(services)
  46. if err != nil {
  47. return err
  48. }
  49. _, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
  50. return "", c.ComposeService().Push(ctx, project, compose.PushOptions{
  51. IgnoreFailures: opts.Ignorefailures,
  52. })
  53. })
  54. return err
  55. }