Skip to content

Commit

Permalink
add --image flag for image only deploy (#1446)
Browse files Browse the repository at this point in the history
* add --image flag for image only deploy

* don't send tarball on image only

* image only deploy works

* image only deploy works

* fix lint

* add errors
  • Loading branch information
sunkickr committed Jan 17, 2024
1 parent 8e71f51 commit 6e6ed2e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cloud/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type InputDeploy struct {
DeploymentName string
Prompt bool
Dags bool
Image bool
WaitForStatus bool
DagsPath string
Description string
Expand Down Expand Up @@ -238,7 +239,6 @@ func Deploy(deployInput InputDeploy, corePlatformClient astroplatformcore.CoreCl
if err != nil {
return err
}

resp, err := createDeploy(deployInfo.organizationID, deployInfo.deploymentID, deployInput.Description, "", deployInput.Dags, coreClient)
if err != nil {
return err
Expand Down Expand Up @@ -333,7 +333,7 @@ func Deploy(deployInput InputDeploy, corePlatformClient astroplatformcore.CoreCl
return fmt.Errorf("%w %s", envFileMissing, deployInput.EnvFile)
}

if deployInfo.dagDeployEnabled && len(dagFiles) == 0 && config.CFG.ShowWarnings.GetBool() {
if deployInfo.dagDeployEnabled && len(dagFiles) == 0 && config.CFG.ShowWarnings.GetBool() && !deployInput.Image {
i, _ := input.Confirm("Warning: No DAGs found. This will delete any existing DAGs. Are you sure you want to deploy?")

if !i {
Expand Down Expand Up @@ -373,12 +373,30 @@ func Deploy(deployInput InputDeploy, corePlatformClient astroplatformcore.CoreCl
}

if deployInfo.dagDeployEnabled && len(dagFiles) > 0 {
dagTarballVersion, err = deployDags(deployInput.Path, dagsPath, dagsUploadURL, deployInfo.deploymentType)
if !deployInput.Image {
dagTarballVersion, err = deployDags(deployInput.Path, dagsPath, deployInfo.deploymentType, dagsUploadURL)
if err != nil {
return err
}
} else {
if !deployInfo.dagDeployEnabled {
return fmt.Errorf(enableDagDeployMsg, deployInfo.deploymentID) //nolint
}
fmt.Println("Image Deploy only. Skipping deploying DAG...")
}
}
// finish deploy
if deployInput.Image {
coreDeployment, err := deployment.CoreGetDeployment(deployInfo.workspaceID, deployInfo.organizationID, deployInfo.deploymentID, coreClient)
if err != nil {
return err
}
if coreDeployment.CurrentDagTarballVersion != nil {
dagTarballVersion = *coreDeployment.CurrentDagTarballVersion
} else {
dagTarballVersion = ""
}
}
// finish deploy
err = updateDeploy(deployID, deployInfo.deploymentID, deployInfo.organizationID, dagTarballVersion, deployInfo.dagDeployEnabled, coreClient)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions cmd/cloud/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
parse bool
dags bool
waitForDeploy bool
image bool
dagsPath string
pytestFile string
envFile string
Expand Down Expand Up @@ -63,6 +64,7 @@ func NewDeployCmd() *cobra.Command {
cmd.Flags().StringVarP(&pytestFile, "test", "t", "", "Location of Pytests or specific Pytest file. All Pytest files must be located in the tests directory")
cmd.Flags().StringVarP(&imageName, "image-name", "i", "", "Name of a custom image to deploy")
cmd.Flags().BoolVarP(&dags, "dags", "d", false, "Push only DAGs to your Astro Deployment")
cmd.Flags().BoolVarP(&image, "image", "", false, "Push only an image to your Astro Deployment. If you have DAG Deploy enabled your DAGs will not be affected.")
cmd.Flags().StringVar(&dagsPath, "dags-path", "", "If set deploy dags from this path instead of the dags from working directory")
cmd.Flags().StringVarP(&deploymentName, "deployment-name", "n", "", "Name of the deployment to deploy to")
cmd.Flags().BoolVar(&parse, "parse", false, "Succeed only if all DAGs in your Astro project parse without errors")
Expand Down Expand Up @@ -104,6 +106,10 @@ func deploy(cmd *cobra.Command, args []string) error {
}
}

if dags && image {
return errors.New("cannot use both --dags and --image together. Run 'astro deploy' to update both your image and dags")
}

// Save deploymentId in config if specified
if len(deploymentID) > 0 && saveDeployConfig {
err := config.CFG.ProjectDeployment.SetProjectString(deploymentID)
Expand Down Expand Up @@ -137,6 +143,7 @@ func deploy(cmd *cobra.Command, args []string) error {
DeploymentName: deploymentName,
Prompt: forcePrompt,
Dags: dags,
Image: image,
WaitForStatus: waitForDeploy,
DagsPath: dagsPath,
Description: deployDescription,
Expand Down

0 comments on commit 6e6ed2e

Please sign in to comment.