(ch *cmdutil.Helper)
| 11 | ) |
| 12 | |
| 13 | func CreateCmd(ch *cmdutil.Helper) *cobra.Command { |
| 14 | var project, path, environment string |
| 15 | var editable bool |
| 16 | |
| 17 | createCmd := &cobra.Command{ |
| 18 | Use: "create [<project>] <branch>", |
| 19 | Args: cobra.RangeArgs(1, 2), |
| 20 | Short: "Create a deployment for a specific branch", |
| 21 | RunE: func(cmd *cobra.Command, args []string) error { |
| 22 | var branch string |
| 23 | if len(args) == 1 { |
| 24 | branch = args[0] |
| 25 | } else if len(args) == 2 { |
| 26 | project = args[0] |
| 27 | branch = args[1] |
| 28 | } |
| 29 | |
| 30 | client, err := ch.Client() |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | if project == "" { |
| 36 | project, err = ch.InferProjectName(cmd.Context(), path, "use --project to specify the name") |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | if environment == "prod" { |
| 43 | // editable defaults to true, so only error if it was explicitly requested |
| 44 | if cmd.Flags().Changed("editable") && editable { |
| 45 | return fmt.Errorf("prod deployments cannot be editable") |
| 46 | } |
| 47 | editable = false |
| 48 | } |
| 49 | |
| 50 | if editable { |
| 51 | ch.PrintfWarn("Cloud editing is still in beta. Ensure `cloud_editing` feature flag is set in `rill.yaml`.\n") |
| 52 | } |
| 53 | |
| 54 | ch.PrintfBold("Creating %q deployment for branch %q...\n", environment, branch) |
| 55 | |
| 56 | resp, err := client.CreateDeployment(cmd.Context(), &adminv1.CreateDeploymentRequest{ |
| 57 | Org: ch.Org, |
| 58 | Project: project, |
| 59 | Environment: environment, |
| 60 | Branch: branch, |
| 61 | Editable: editable, |
| 62 | }) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | ch.Printf("Deployment created with branch %q\n", resp.Deployment.Branch) |
| 68 | ch.Printf("Provisioning runtime (this may take a moment)") |
| 69 | |
| 70 | // Poll for deployment status and print result |
no test coverage detected