update_image.go 1.3 KB

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