up.go 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package compose
  2. import (
  3. "context"
  4. "errors"
  5. "github.com/spf13/cobra"
  6. "github.com/docker/api/client"
  7. "github.com/docker/api/compose"
  8. )
  9. func upCommand() *cobra.Command {
  10. opts := compose.ProjectOptions{}
  11. upCmd := &cobra.Command{
  12. Use: "up",
  13. RunE: func(cmd *cobra.Command, args []string) error {
  14. return runUp(cmd.Context(), opts)
  15. },
  16. }
  17. upCmd.Flags().StringVar(&opts.Name, "name", "", "Project name")
  18. upCmd.Flags().StringVar(&opts.WorkDir, "workdir", ".", "Work dir")
  19. upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
  20. upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
  21. return upCmd
  22. }
  23. func runUp(ctx context.Context, opts compose.ProjectOptions) error {
  24. c, err := client.New(ctx)
  25. if err != nil {
  26. return err
  27. }
  28. composeService := c.ComposeService()
  29. if composeService == nil {
  30. return errors.New("compose not implemented in current context")
  31. }
  32. return composeService.Up(ctx, opts)
  33. }