Skip to content

Commit

Permalink
set image override for manual service run if provided (#4156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Jan 17, 2024
1 parent 0615d7c commit b1b8125
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
24 changes: 23 additions & 1 deletion api/server/handlers/porter_app/run_app_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit b1b8125

Please sign in to comment.