2
0

rollback.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package v2
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/fatih/color"
  6. api "github.com/porter-dev/porter/api/client"
  7. "github.com/porter-dev/porter/cli/cmd/config"
  8. )
  9. // RollbackInput is the input for the Rollback function
  10. type RollbackInput struct {
  11. // CLIConfig is the CLI configuration
  12. CLIConfig config.CLIConfig
  13. // Client is the Porter API client
  14. Client api.Client
  15. // AppName is the name of the app to rollback
  16. AppName string
  17. // DeploymentTargetName is the name of the deployment target to rollback
  18. DeploymentTargetName string
  19. }
  20. // Rollback deploys the previous successful revision of an app
  21. func Rollback(ctx context.Context, inp RollbackInput) error {
  22. color.New(color.FgGreen).Printf("Rolling back to last deployed revision ...\n") // nolint:errcheck,gosec
  23. rollbackResp, err := inp.Client.RollbackRevision(ctx, inp.CLIConfig.Project, inp.CLIConfig.Cluster, inp.AppName, inp.DeploymentTargetName)
  24. if err != nil {
  25. return fmt.Errorf("error calling rollback revision endpoint: %w", err)
  26. }
  27. color.New(color.FgGreen).Printf("Successfully rolled back to revision %d\n", rollbackResp.TargetRevisionNumber) // nolint:errcheck,gosec
  28. return nil
  29. }