Skip to content

Commit 1823da2

Browse files
authored
add --image flag for image only deploy (#1446)
* 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
1 parent 7d5337e commit 1823da2

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

cloud/deploy/deploy.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type InputDeploy struct {
105105
DeploymentName string
106106
Prompt bool
107107
Dags bool
108+
Image bool
108109
WaitForStatus bool
109110
DagsPath string
110111
Description string
@@ -235,7 +236,6 @@ func Deploy(deployInput InputDeploy, client astro.Client, coreClient astrocore.C
235236
if err != nil {
236237
return err
237238
}
238-
239239
resp, err := createDeploy(deployInfo.organizationID, deployInfo.deploymentID, deployInput.Description, "", deployInput.Dags, coreClient)
240240
if err != nil {
241241
return err
@@ -326,7 +326,7 @@ func Deploy(deployInput InputDeploy, client astro.Client, coreClient astrocore.C
326326
return fmt.Errorf("%w %s", envFileMissing, deployInput.EnvFile)
327327
}
328328

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

332332
if !i {
@@ -366,12 +366,30 @@ func Deploy(deployInput InputDeploy, client astro.Client, coreClient astrocore.C
366366
}
367367

368368
if deployInfo.dagDeployEnabled && len(dagFiles) > 0 {
369-
dagTarballVersion, err = deployDags(deployInput.Path, dagsPath, deployInfo.deploymentType, dagsUploadURL)
369+
if !deployInput.Image {
370+
dagTarballVersion, err = deployDags(deployInput.Path, dagsPath, deployInfo.deploymentType, dagsUploadURL)
371+
if err != nil {
372+
return err
373+
}
374+
} else {
375+
if !deployInfo.dagDeployEnabled {
376+
return fmt.Errorf(enableDagDeployMsg, deployInfo.deploymentID) //nolint
377+
}
378+
fmt.Println("Image Deploy only. Skipping deploying DAG...")
379+
}
380+
}
381+
// finish deploy
382+
if deployInput.Image {
383+
coreDeployment, err := deployment.CoreGetDeployment(deployInfo.workspaceID, deployInfo.organizationID, deployInfo.deploymentID, coreClient)
370384
if err != nil {
371385
return err
372386
}
387+
if coreDeployment.CurrentDagTarballVersion != nil {
388+
dagTarballVersion = *coreDeployment.CurrentDagTarballVersion
389+
} else {
390+
dagTarballVersion = ""
391+
}
373392
}
374-
// finish deploy
375393
err = updateDeploy(deployID, deployInfo.deploymentID, deployInfo.organizationID, dagTarballVersion, deployInfo.dagDeployEnabled, coreClient)
376394
if err != nil {
377395
return err
@@ -412,7 +430,6 @@ func getDeploymentInfo(deploymentID, wsID, deploymentName string, prompt bool, c
412430
if err != nil {
413431
return deploymentInfo{}, err
414432
}
415-
416433
return deploymentInfo{
417434
currentDeployment.ID,
418435
currentDeployment.ReleaseName,

cmd/cloud/deploy.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
parse bool
2121
dags bool
2222
waitForDeploy bool
23+
image bool
2324
dagsPath string
2425
pytestFile string
2526
envFile string
@@ -63,6 +64,7 @@ func NewDeployCmd() *cobra.Command {
6364
cmd.Flags().StringVarP(&pytestFile, "test", "t", "", "Location of Pytests or specific Pytest file. All Pytest files must be located in the tests directory")
6465
cmd.Flags().StringVarP(&imageName, "image-name", "i", "", "Name of a custom image to deploy")
6566
cmd.Flags().BoolVarP(&dags, "dags", "d", false, "Push only DAGs to your Astro Deployment")
67+
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.")
6668
cmd.Flags().StringVar(&dagsPath, "dags-path", "", "If set deploy dags from this path instead of the dags from working directory")
6769
cmd.Flags().StringVarP(&deploymentName, "deployment-name", "n", "", "Name of the deployment to deploy to")
6870
cmd.Flags().BoolVar(&parse, "parse", false, "Succeed only if all DAGs in your Astro project parse without errors")
@@ -104,6 +106,10 @@ func deploy(cmd *cobra.Command, args []string) error {
104106
}
105107
}
106108

109+
if dags && image {
110+
return errors.New("cannot use both --dags and --image together. Run 'astro deploy' to update both your image and dags")
111+
}
112+
107113
// Save deploymentId in config if specified
108114
if len(deploymentID) > 0 && saveDeployConfig {
109115
err := config.CFG.ProjectDeployment.SetProjectString(deploymentID)
@@ -137,6 +143,7 @@ func deploy(cmd *cobra.Command, args []string) error {
137143
DeploymentName: deploymentName,
138144
Prompt: forcePrompt,
139145
Dags: dags,
146+
Image: image,
140147
WaitForStatus: waitForDeploy,
141148
DagsPath: dagsPath,
142149
Description: deployDescription,

0 commit comments

Comments
 (0)