2
0

update_image.go 814 B

1234567891011121314151617181920212223242526272829303132
  1. package v2
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. api "github.com/porter-dev/porter/api/client"
  7. )
  8. // UpdateImage updates the image of an application
  9. func UpdateImage(ctx context.Context, tag string, client api.Client, projectId, clusterId uint, appName string) (string, error) {
  10. targetResp, err := client.DefaultDeploymentTarget(ctx, projectId, clusterId)
  11. if err != nil {
  12. return "", fmt.Errorf("error calling default deployment target endpoint: %w", err)
  13. }
  14. if targetResp.DeploymentTargetID == "" {
  15. return "", errors.New("deployment target id is empty")
  16. }
  17. if tag == "" {
  18. tag = "latest"
  19. }
  20. resp, err := client.UpdateImage(ctx, projectId, clusterId, appName, targetResp.DeploymentTargetID, tag)
  21. if err != nil {
  22. return "", fmt.Errorf("unable to update image: %w", err)
  23. }
  24. return resp.Tag, nil
  25. }