Selaa lähdekoodia

add tag override to apply (#4149)

d-g-town 2 vuotta sitten
vanhempi
sitoutus
9221d9bc03

+ 4 - 0
api/client/porter_app.go

@@ -206,6 +206,7 @@ type ValidatePorterAppInput struct {
 	Base64AppOverrides string
 	DeploymentTarget   string
 	CommitSHA          string
+	ImageTagOverride   string
 }
 
 // ValidatePorterApp takes in a base64 encoded app definition that is potentially partial and returns a complete definition
@@ -222,6 +223,7 @@ func (c *Client) ValidatePorterApp(
 		Base64AppOverrides: inp.Base64AppOverrides,
 		DeploymentTargetId: inp.DeploymentTarget,
 		CommitSHA:          inp.CommitSHA,
+		ImageTagOverride:   inp.ImageTagOverride,
 	}
 
 	err := c.postRequest(
@@ -287,6 +289,7 @@ type UpdateAppInput struct {
 	ProjectID          uint
 	ClusterID          uint
 	Name               string
+	ImageTagOverride   string
 	GitSource          porter_app.GitSource
 	DeploymentTargetId string
 	CommitSHA          string
@@ -308,6 +311,7 @@ func (c *Client) UpdateApp(
 		GitSource:          inp.GitSource,
 		DeploymentTargetId: inp.DeploymentTargetId,
 		CommitSHA:          inp.CommitSHA,
+		ImageTagOverride:   inp.ImageTagOverride,
 		AppRevisionID:      inp.AppRevisionID,
 		Base64AppProto:     inp.Base64AppProto,
 		Base64PorterYAML:   inp.Base64PorterYAML,

+ 13 - 4
api/server/handlers/porter_app/update_app.go

@@ -53,6 +53,8 @@ type UpdateAppRequest struct {
 	Deletions Deletions `json:"deletions"`
 	// CommitSHA is the commit sha of the git commit that triggered this update, indicating a source change and triggering a build
 	CommitSHA string `json:"commit_sha"`
+	// ImageTagOverride is the image tag to override the image tag in the porter.yaml (it will override the image tag in the porter.yaml if specified)
+	ImageTagOverride string `json:"image_tag_override"`
 	// PorterYAMLPath is the path to the porter yaml file in the git repo
 	PorterYAMLPath string `json:"porter_yaml_path"`
 	// AppRevisionID is the ID of the revision to perform follow up actions on after the initial apply
@@ -227,6 +229,13 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
+	if request.ImageTagOverride != "" {
+		if appProto.Image == nil {
+			appProto.Image = &porterv1.AppImage{}
+		}
+		appProto.Image.Tag = request.ImageTagOverride
+	}
+
 	updateReq := connect.NewRequest(&porterv1.UpdateAppRequest{
 		ProjectId: int64(project.ID),
 		DeploymentTargetIdentifier: &porterv1.DeploymentTargetIdentifier{
@@ -245,10 +254,10 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 			EnvGroupNames:    request.Deletions.EnvGroupNames,
 			ServiceDeletions: serviceDeletions,
 		},
-		AppOverrides:  overrides,
-		CommitSha:     request.CommitSHA,
-		IsEnvOverride: request.IsEnvOverride,
-		Addons:        addons,
+		AppOverrides:   overrides,
+		CommitSha:      request.CommitSHA,
+		IsEnvOverride:  request.IsEnvOverride,
+		Addons:         addons,
 		AddonOverrides: addonOverrides,
 	})
 

+ 8 - 0
api/server/handlers/porter_app/validate.go

@@ -58,6 +58,7 @@ type ValidatePorterAppRequest struct {
 	Base64AppOverrides string    `json:"b64_app_overrides"`
 	DeploymentTargetId string    `json:"deployment_target_id"`
 	CommitSHA          string    `json:"commit_sha"`
+	ImageTagOverride   string    `json:"image_tag_override"`
 	Deletions          Deletions `json:"deletions"`
 }
 
@@ -162,6 +163,13 @@ func (c *ValidatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		}
 	}
 
+	if request.ImageTagOverride != "" {
+		if appProto.Image == nil {
+			appProto.Image = &porterv1.AppImage{}
+		}
+		appProto.Image.Tag = request.ImageTagOverride
+	}
+
 	validateReq := connect.NewRequest(&porterv1.ValidatePorterAppRequest{
 		ProjectId:          int64(project.ID),
 		DeploymentTargetId: request.DeploymentTargetId,

+ 5 - 2
cli/cmd/commands/apply.go

@@ -40,8 +40,9 @@ import (
 )
 
 var (
-	porterYAML   string
-	previewApply bool
+	porterYAML       string
+	previewApply     bool
+	imageTagOverride string
 )
 
 func registerCommand_Apply(cliConf config.CLIConfig) *cobra.Command {
@@ -107,6 +108,7 @@ applying a configuration:
 
 	applyCmd.PersistentFlags().StringVarP(&porterYAML, "file", "f", "", "path to porter.yaml")
 	applyCmd.PersistentFlags().BoolVarP(&previewApply, "preview", "p", false, "apply as preview environment based on current git branch")
+	applyCmd.PersistentFlags().StringVar(&imageTagOverride, "tag", "", "set the image tag used for the application (overrides field in yaml)")
 	applyCmd.PersistentFlags().BoolVarP(
 		&appWait,
 		"wait",
@@ -147,6 +149,7 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 			Client:                      client,
 			PorterYamlPath:              porterYAML,
 			AppName:                     appName,
+			ImageTagOverride:            imageTagOverride,
 			PreviewApply:                previewApply,
 			WaitForSuccessfulDeployment: appWait,
 		}

+ 3 - 0
cli/cmd/v2/apply.go

@@ -33,6 +33,8 @@ type ApplyInput struct {
 	PorterYamlPath string
 	// AppName is the name of the app
 	AppName string
+	// ImageTagOverride is the image tag to use for the app
+	ImageTagOverride string
 	// PreviewApply is true when Apply should create a new deployment target matching current git branch and apply to that target
 	PreviewApply bool
 	// WaitForSuccessfulDeployment is true when Apply should wait for the update to complete before returning
@@ -165,6 +167,7 @@ func Apply(ctx context.Context, inp ApplyInput) error {
 		Base64AppOverrides: b64AppOverrides,
 		DeploymentTarget:   deploymentTargetID,
 		CommitSHA:          commitSHA,
+		ImageTagOverride:   inp.ImageTagOverride,
 	})
 	if err != nil {
 		return fmt.Errorf("error calling validate endpoint: %w", err)

+ 4 - 1
cli/cmd/v2/update.go

@@ -31,6 +31,8 @@ type UpdateInput struct {
 	PorterYamlPath string
 	// AppName is the name of the app
 	AppName string
+	// ImageTagOverride is the image tag to use for the app revision
+	ImageTagOverride string
 	// PreviewApply is true when Update should create a new deployment target matching current git branch and apply to that target
 	PreviewApply bool
 	// WaitForSuccessfulDeployment is true when Update should wait for the revision deployment to complete (all services deployed successfully)
@@ -106,10 +108,11 @@ func Update(ctx context.Context, inp UpdateInput) error {
 		ProjectID:          cliConf.Project,
 		ClusterID:          cliConf.Cluster,
 		Name:               inp.AppName,
+		ImageTagOverride:   inp.ImageTagOverride,
 		GitSource:          gitSource,
 		DeploymentTargetId: deploymentTargetID,
-		Base64PorterYAML:   b64YAML,
 		CommitSHA:          commitSHA,
+		Base64PorterYAML:   b64YAML,
 	}
 
 	updateResp, err := client.UpdateApp(ctx, updateInput)