mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-10 05:11:09 +01:00
[VAULT-39160] actions(hcp): add support for testing custom images on HCP (#9345) Add support for running the `cloud` scenario with a custom image in the int HCP environment. We support two new tags that trigger new functionality. If the `hcp/build-image` tag is present on a PR at the time of `build`, we'll automatically trigger a custom build for the int environment. If the `hcp/test` tag is present, we'll trigger a custom build and run the `cloud` scenario with the resulting image. * Fix a bug in our custom build pattern to handle prerelease versions. * pipeline(hcp): add `--github-output` support to `show image` and `wait image` commands. * enos(hcp/create_vault_cluster): use a unique identifier for HVN and vault clusters. * actions(enos-cloud): add workflow to execute the `cloud` enos scenario. * actions(build): add support for triggering a custom build and running the `enos-cloud` scenario. * add more debug logging and query without a status * add shim build-hcp-image for CE workflows Signed-off-by: Ryan Cragun <me@ryan.ec> Co-authored-by: Ryan Cragun <me@ryan.ec>
77 lines
2.7 KiB
Go
77 lines
2.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/vault/tools/pipeline/internal/pkg/hcp"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var showHCPImageReq = &hcp.ShowImageReq{
|
|
Req: &hcp.GetLatestProductVersionReq{},
|
|
}
|
|
|
|
func newHCPShowImageCmd() *cobra.Command {
|
|
availability := ""
|
|
|
|
showHCPImage := &cobra.Command{
|
|
Use: "image",
|
|
Short: "Show details of an HCP image",
|
|
Long: "Show details of an HCP image",
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
showHCPImageReq.Req.Availability = hcp.GetLatestProductVersionAvailability(availability)
|
|
},
|
|
RunE: runHCPImageShowLatestCmd,
|
|
}
|
|
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.Req.ProductName, "product-name", "p", "vault", "The product or component of the image")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.Req.ProductVersionConstraint, "product-version-constraint", "v", "", "A comma seperated list of constraints. If left unset the latest will be returned")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.Req.HostManagerVersionConstraint, "host-manager-version-constraint", "m", "", "A semver string. If left unset the latest will be used")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.Req.CloudProvider, "cloud", "c", "aws", "The cloud provider you wish to search. E.g. aws, azure")
|
|
showHCPImage.PersistentFlags().StringVarP(&showHCPImageReq.Req.CloudRegion, "region", "r", "us-west-2", "The cloud region you wish to search")
|
|
showHCPImage.PersistentFlags().StringVarP(&availability, "availability", "a", "public", "The image availability")
|
|
showHCPImage.PersistentFlags().BoolVarP(&showHCPImageReq.Req.ExcludeReleaseCandidates, "exclude-release-candidates", "x", false, "Exclude release candidates")
|
|
showHCPImage.PersistentFlags().BoolVar(&showHCPImageReq.WriteToGithubOutput, "github-output", false, "Whether or not to write 'show-image' to $GITHUB_OUTPUT")
|
|
|
|
return showHCPImage
|
|
}
|
|
|
|
func runHCPImageShowLatestCmd(cmd *cobra.Command, args []string) error {
|
|
cmd.SilenceUsage = true // Don't spam the usage on failure
|
|
|
|
res, err := showHCPImageReq.Run(context.TODO(), hcpCmdState.client)
|
|
if err != nil {
|
|
return fmt.Errorf("showing HCP image: %w", err)
|
|
}
|
|
|
|
switch rootCfg.format {
|
|
case "json":
|
|
b, err := res.Res.ToJSON()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(string(b))
|
|
case "markdown":
|
|
tbl := res.Res.ToTable()
|
|
tbl.SetTitle("HCP Image")
|
|
fmt.Println(tbl.RenderMarkdown())
|
|
default:
|
|
fmt.Println(res.Res.ToTable().Render())
|
|
}
|
|
|
|
if showHCPImageReq.WriteToGithubOutput {
|
|
output, err := res.ToGithubOutput()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return writeToGithubOutput("show-image", output)
|
|
}
|
|
|
|
return nil
|
|
}
|