| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package v2
- import (
- "context"
- "encoding/base64"
- "fmt"
- "github.com/fatih/color"
- api "github.com/porter-dev/porter/api/client"
- )
- // UpdateImageInput is the input for the UpdateImage function
- type UpdateImageInput struct {
- ProjectID uint
- ClusterID uint
- AppName string
- DeploymentTargetName string
- Tag string
- Description string
- Client api.Client
- WaitForSuccessfulDeployment bool
- }
- // UpdateImage updates the image of an application
- func UpdateImage(ctx context.Context, input UpdateImageInput) error {
- tag := input.Tag
- if tag == "" {
- tag = "latest"
- }
- var base64Description string
- if input.Description != "" {
- base64Description = base64.StdEncoding.EncodeToString([]byte(input.Description))
- }
- resp, err := input.Client.UpdateImage(ctx, input.ProjectID, input.ClusterID, input.AppName, input.DeploymentTargetName, tag, base64Description)
- if err != nil {
- return fmt.Errorf("unable to update image: %w", err)
- }
- triggeredBackgroundColor := color.FgGreen
- _, _ = color.New(triggeredBackgroundColor).Printf("Updated application %s to use tag \"%s\"\n", input.AppName, tag)
- if input.WaitForSuccessfulDeployment {
- return waitForAppRevisionStatus(ctx, waitForAppRevisionStatusInput{
- ProjectID: input.ProjectID,
- ClusterID: input.ClusterID,
- AppName: input.AppName,
- RevisionID: resp.RevisionID,
- Client: input.Client,
- })
- }
- return nil
- }
|