push.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/compose"
  18. "github.com/docker/compose-cli/api/progress"
  19. )
  20. type pushOptions struct {
  21. *projectOptions
  22. composeOptions
  23. Ignorefailures bool
  24. }
  25. func pushCommand(p *projectOptions, backend compose.Service) *cobra.Command {
  26. opts := pushOptions{
  27. projectOptions: p,
  28. }
  29. pushCmd := &cobra.Command{
  30. Use: "push [SERVICE...]",
  31. Short: "Push service images",
  32. RunE: func(cmd *cobra.Command, args []string) error {
  33. return runPush(cmd.Context(), backend, opts, args)
  34. },
  35. }
  36. pushCmd.Flags().BoolVar(&opts.Ignorefailures, "ignore-push-failures", false, "Push what it can and ignores images with push failures")
  37. return pushCmd
  38. }
  39. func runPush(ctx context.Context, backend compose.Service, opts pushOptions, services []string) error {
  40. project, err := opts.toProject(services)
  41. if err != nil {
  42. return err
  43. }
  44. _, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
  45. return "", backend.Push(ctx, project, compose.PushOptions{
  46. IgnoreFailures: opts.Ignorefailures,
  47. })
  48. })
  49. return err
  50. }