-
Notifications
You must be signed in to change notification settings - Fork 67
/
deploy.go
62 lines (51 loc) · 1.82 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd
import (
"fmt"
"github.com/astronomer/astro-cli/airflow"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/messages"
"github.com/astronomer/astro-cli/pkg/git"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
deployCmd = &cobra.Command{
Use: "deploy DEPLOYMENT",
Short: "Deploy an airflow project",
Long: "Deploy an airflow project to a given deployment",
Args: cobra.MaximumNArgs(1),
PreRunE: ensureProjectDir,
RunE: deploy,
Aliases: []string{"airflow deploy"},
}
)
func init() {
RootCmd.AddCommand(deployCmd)
deployCmd.Flags().BoolVarP(&forceDeploy, "force", "f", false, "Force deploy if uncommitted changes")
deployCmd.Flags().BoolVarP(&forcePrompt, "prompt", "p", false, "Force prompt to choose target deployment")
deployCmd.Flags().BoolVarP(&saveDeployConfig, "save", "s", false, "Save deployment in config for future deploys")
deployCmd.Flags().StringVar(&workspaceId, "workspace-id", "", "workspace assigned to deployment")
}
func deploy(cmd *cobra.Command, args []string) error {
ws, err := coalesceWorkspace()
if err != nil {
return errors.Wrap(err, "failed to find a valid workspace")
// fmt.Println("Default workspace id not set, set default workspace id or pass a workspace in via the --workspace-id flag")
}
releaseName := ""
// Get release name from args, if passed
if len(args) > 0 {
releaseName = args[0]
}
// Save release name in config if specified
if len(releaseName) > 0 && saveDeployConfig {
config.CFG.ProjectDeployment.SetProjectString(releaseName)
}
if git.HasUncommitedChanges() && !forceDeploy {
fmt.Println(messages.REGISTRY_UNCOMMITTED_CHANGES)
return nil
}
// Silence Usage as we have now validated command input
cmd.SilenceUsage = true
return airflow.Deploy(config.WorkingPath, releaseName, ws, forcePrompt)
}