Kaynağa Gözat

set image override for manual service run if provided (#4156)

ianedwards 2 yıl önce
ebeveyn
işleme
b1b81254c7
3 değiştirilmiş dosya ile 26 ekleme ve 4 silme
  1. 23 1
      api/server/handlers/porter_app/run_app_job.go
  2. 1 1
      go.mod
  3. 2 2
      go.sum

+ 23 - 1
api/server/handlers/porter_app/run_app_job.go

@@ -42,6 +42,10 @@ func NewRunAppJobHandler(
 type RunAppJobRequest struct {
 	ServiceName        string `json:"service_name"`
 	DeploymentTargetID string `json:"deployment_target_id"`
+	// Optional field to override the default run command for the job
+	RunCommand string `json:"run_command"`
+	// Image is an optional field to override the image used for the job
+	Image Image `json:"image,omitempty"`
 }
 
 // RunAppJobResponse is the response object for the /apps/{porter_app_name}/run endpoint
@@ -86,11 +90,29 @@ func (c *RunAppJobHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	}
 	telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "deployment-target-id", Value: request.DeploymentTargetID})
 
+	var commandOptional *string
+	if request.RunCommand != "" {
+		commandOptional = &request.RunCommand
+	}
+
+	var imageOverrideOptional *porterv1.AppImage
+	if request.Image.Tag != "" {
+		telemetry.WithAttributes(span,
+			telemetry.AttributeKV{Key: "image-override-repo", Value: request.Image.Repository},
+			telemetry.AttributeKV{Key: "image-override-tag", Value: request.Image.Tag},
+		)
+		imageOverrideOptional = &porterv1.AppImage{
+			Repository: request.Image.Repository,
+			Tag:        request.Image.Tag,
+		}
+	}
+
 	manualServiceRunReq := connect.NewRequest(&porterv1.ManualServiceRunRequest{
 		ProjectId:   int64(project.ID),
 		AppName:     appName,
 		ServiceName: request.ServiceName,
-		Command:     nil, // use default command for job
+		Command:     commandOptional,
+		Image:       imageOverrideOptional,
 		DeploymentTargetIdentifier: &porterv1.DeploymentTargetIdentifier{
 			Id: request.DeploymentTargetID,
 		},

+ 1 - 1
go.mod

@@ -83,7 +83,7 @@ require (
 	github.com/matryer/is v1.4.0
 	github.com/nats-io/nats.go v1.24.0
 	github.com/open-policy-agent/opa v0.44.0
-	github.com/porter-dev/api-contracts v0.2.85
+	github.com/porter-dev/api-contracts v0.2.86
 	github.com/riandyrn/otelchi v0.5.1
 	github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
 	github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d

+ 2 - 2
go.sum

@@ -1523,8 +1523,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
-github.com/porter-dev/api-contracts v0.2.85 h1:9GakgkflrPiuH9R+/zG5NFlIGL7GjzX1OS4FfhO5qqQ=
-github.com/porter-dev/api-contracts v0.2.85/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.2.86 h1:uH6beKklp1YCzLBrtuuFVDwWfvQnlBWbxZBtDsO3+AI=
+github.com/porter-dev/api-contracts v0.2.86/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
 github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
 github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=