update_image.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package v2
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/fatih/color"
  7. api "github.com/porter-dev/porter/api/client"
  8. )
  9. // UpdateImageInput is the input for the UpdateImage function
  10. type UpdateImageInput struct {
  11. ProjectID uint
  12. ClusterID uint
  13. AppName string
  14. DeploymentTargetName string
  15. Tag string
  16. Client api.Client
  17. }
  18. // UpdateImage updates the image of an application
  19. func UpdateImage(ctx context.Context, input UpdateImageInput) (string, error) {
  20. if input.DeploymentTargetName == "" {
  21. return "", errors.New("please provide a deployment target")
  22. }
  23. tag := input.Tag
  24. if tag == "" {
  25. tag = "latest"
  26. }
  27. resp, err := input.Client.UpdateImage(ctx, input.ProjectID, input.ClusterID, input.AppName, input.DeploymentTargetName, tag)
  28. if err != nil {
  29. return "", fmt.Errorf("unable to update image: %w", err)
  30. }
  31. triggeredBackgroundColor := color.FgGreen
  32. _, _ = color.New(triggeredBackgroundColor).Printf("Updated application %s to use tag \"%s\"\n", input.AppName, tag)
  33. return resp.RevisionID, nil
  34. }