clouddeploy

package
v0.0.0-...-829e7b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package clouddeploy provides functionality for working with custom render and custom deploy requests and results.

Index

Constants

View Source
const (
	RequestTypeEnvKey        = "CLOUD_DEPLOY_REQUEST_TYPE"
	FeaturesEnvKey           = "CLOUD_DEPLOY_FEATURES"
	ProjectEnvKey            = "CLOUD_DEPLOY_PROJECT"
	LocationEnvKey           = "CLOUD_DEPLOY_LOCATION"
	PipelineEnvKey           = "CLOUD_DEPLOY_DELIVERY_PIPELINE"
	ReleaseEnvKey            = "CLOUD_DEPLOY_RELEASE"
	RolloutEnvKey            = "CLOUD_DEPLOY_ROLLOUT"
	TargetEnvKey             = "CLOUD_DEPLOY_TARGET"
	PhaseEnvKey              = "CLOUD_DEPLOY_PHASE"
	PercentageEnvKey         = "CLOUD_DEPLOY_PERCENTAGE_DEPLOY"
	StorageTypeEnvKey        = "CLOUD_DEPLOY_STORAGE_TYPE"
	InputGCSEnvKey           = "CLOUD_DEPLOY_INPUT_GCS_PATH"
	OutputGCSEnvKey          = "CLOUD_DEPLOY_OUTPUT_GCS_PATH"
	SkaffoldGCSEnvKey        = "CLOUD_DEPLOY_SKAFFOLD_GCS_PATH"
	ManifestGCSEnvKey        = "CLOUD_DEPLOY_MANIFEST_GCS_PATH"
	WorkloadTypeEnvKey       = "CLOUD_DEPLOY_WORKLOAD_TYPE"
	CloudBuildServiceAccount = "CLOUD_DEPLOY_WP_CB_ServiceAccount"
	CloudBuildWorkerPool     = "CLOUD_DEPLOY_WP_CB_WorkerPool"
)

Cloud Deploy environment variable keys.

View Source
const (
	CustomTargetSourceMetadataKey    = "custom-target-source"
	CustomTargetSourceSHAMetadataKey = "custom-target-source-commit-sha"
)

Cloud Deploy known result metadata keys.

Variables

View Source
var GitCommit = "unknown"

GitCommit SHA to be set during build time of the binary.

Functions

func DetermineRequest

func DetermineRequest(ctx context.Context, gcsClient *storage.Client, supportedFeatures []string) (interface{}, error)

DetermineRequest determines the Cloud Deploy request based on the environment variables in the execution environment and returns either a RenderRequest or DeployRequest. If the request includes a feature that is not in provided supported features list then a NOT_SUPPORTED result is uploaded for Cloud Deploy and an error is returned.

func FetchDeployParameters

func FetchDeployParameters() map[string]string

FetchDeployParameters returns a map of all the deploy parameters provided in the execution environment.

Types

type CloudBuildWorkload

type CloudBuildWorkload struct {
	// Service Account used by the Cloud Build.
	ServiceAccount string
	// Worker Pool the Build is running in. Empty if using Cloud Build's default pool.
	WorkerPool string
}

CloudBuildWorkload provides workload execution context when running in Cloud Build.

type DeployRequest

type DeployRequest struct {
	// Cloud Deploy project.
	Project string
	// Cloud Deploy location.
	Location string
	// Cloud Deploy delivery pipeline.
	Pipeline string
	// Cloud Deploy release.
	Release string
	// Cloud Deploy rollout.
	Rollout string
	// Cloud Deploy target for this deploy.
	Target string
	// Cloud Deploy rollout phase.
	Phase string
	// Percentage deployment requested.
	Percentage int
	// The storage type for inputs and outputs. Currently only GCS is supported.
	StorageType string
	// Cloud Storage path where the inputs for the deploy are stored. This is equivalent to the output GCS
	// path for the renderer. If Cloud Deploy performed the render via skaffold instead of this
	// image then the input is the manifest path instead.
	// Example: gs://my-bucket/render/dir/subdir/custom-output
	InputGCSPath string
	// Cloud Storage path for the skaffold config file.
	// Example: gs://my-bucket/dir/render-subdir/skaffold.yaml
	SkaffoldGCSPath string
	// Cloud Storage path for the manifest file. This is either the manifest provided by this images render
	// or the manifest from a skaffold render if the default render was configured.
	// Example: gs//my-bucket/dir/render-subdir/manifest.yaml
	ManifestGCSPath string
	// Cloud Storage path where the outputs for the deploy are expected to be stored by Cloud Deploy. This
	// includes the results.json file and any deploy artifacts Cloud Deploy should populate in its
	// resources.
	// Example: gs/my-bucket/dir/deploy-subdir/custom-output
	OutputGCSPath string
	// The workload type for the execution environment. Currently only "CB" is supported.
	WorkloadType string
	// Information about the Cloud Build workload. Only present when WorkloadType is "CB".
	WorkloadCBInfo CloudBuildWorkload
}

DeployRequest contains the Cloud Deploy values passed into the execution environment for a deploy operation.

func (*DeployRequest) DownloadInput

func (d *DeployRequest) DownloadInput(ctx context.Context, gcsClient *storage.Client, objectSuffix, localPath string) (string, error)

DownloadInput downloads the deploy input with the specified objectSuffix from Cloud Storage to the provided local path. Returns the Cloud Storage URI of the downloaded input.

func (*DeployRequest) DownloadManifest

func (d *DeployRequest) DownloadManifest(ctx context.Context, gcsClient *storage.Client, localPath string) (string, error)

DownloadManifest downloads the manifest to the provided local path. Returns the Cloud Storage URI of the downloaded manifest.

func (*DeployRequest) UploadArtifact

func (d *DeployRequest) UploadArtifact(ctx context.Context, gcsClient *storage.Client, objectSuffix string, content *GCSUploadContent) (string, error)

UploadArtifact uploads the provided content as a deploy artifact. The objectSuffix must be provided to determine the Cloud Storage URI to use for the object, the URI is returned.

func (*DeployRequest) UploadResult

func (d *DeployRequest) UploadResult(ctx context.Context, gcsClient *storage.Client, deployResult *DeployResult) (string, error)

UploadResult uploads the provided deploy result to the Cloud Storage path where Cloud Deploy expects it. Returns the Cloud Storage URI of the uploaded result.

type DeployResult

type DeployResult struct {
	ResultStatus   DeployStatus      `json:"resultStatus"`
	ArtifactFiles  []string          `json:"artifactFiles,omitempty"`
	FailureMessage string            `json:"failureMessage,omitempty"`
	SkipMessage    string            `json:"skipMessage,omitempty"`
	Metadata       map[string]string `json:"metadata,omitempty"`
}

DeployResult represents the json data expected in the results file by Cloud Deploy for a deploy operation.

type DeployStatus

type DeployStatus string

DeployStatus represents the valid result status for a deploy request.

const (
	DeploySucceeded    DeployStatus = "SUCCEEDED"
	DeployFailed       DeployStatus = "FAILED"
	DeploySkipped      DeployStatus = "SKIPPED"
	DeployNotSupported DeployStatus = "NOT_SUPPORTED"
)

type GCSUploadContent

type GCSUploadContent struct {
	// Content is this byte array.
	Data []byte
	// Content is in the file at this local path.
	LocalPath string
}

GCSUploadContent is used as a parameter for the various GCS upload functions that points to the source of the content to upload.

type RenderRequest

type RenderRequest struct {
	// Cloud Deploy project.
	Project string
	// Cloud Deploy location.
	Location string
	// Cloud Deploy delivery pipeline.
	Pipeline string
	// Cloud Deploy release.
	Release string
	// Cloud Deploy target for this render.
	Target string
	// Cloud Deploy rollout phase.
	Phase string
	// Percentage deployment requested.
	Percentage int
	// The storage type for inputs and outputs. Currently only "GCS" is supported.
	StorageType string
	// Cloud Storage path to the tar.gz archive provided at the time of release creation in Cloud Deploy.
	// Example: gs://my-bucket/dir/subdir/source.tar.gz
	InputGCSPath string
	// Cloud Storage path where the outputs for the deploy are expected to be stored by Cloud Deploy. This
	// includes the results.json file and any rendered artifacts that need to be accessible at
	// deploy time.
	// Example: gs/my-bucket/dir/render-subdir/custom-output
	OutputGCSPath string
	// The workload type for the execution environment. Currently only "CB" is supported.
	WorkloadType string
	// Information about the Cloud Build workload. Only present when WorkloadType is "CB".
	WorkloadCBInfo CloudBuildWorkload
}

RenderRequest contains the Cloud Deploy values passed into the execution environment for a render operation.

func (*RenderRequest) DownloadAndUnarchiveInput

func (r *RenderRequest) DownloadAndUnarchiveInput(ctx context.Context, gcsClient *storage.Client, localArchivePath, localUnarchivePath string) (string, error)

DownloadAndUnarchiveInput downloads the release archive and unarchives it to the provided path. Returns the Cloud Storage URI of the downloaded archive.

func (*RenderRequest) UploadArtifact

func (r *RenderRequest) UploadArtifact(ctx context.Context, gcsClient *storage.Client, objectSuffix string, content *GCSUploadContent) (string, error)

UploadArtifact uploads the provided content as a rendered artifact. The objectSuffix must be provided to determine the Cloud Storage URI to use for the object, the URI is returned.

func (*RenderRequest) UploadResult

func (r *RenderRequest) UploadResult(ctx context.Context, gcsClient *storage.Client, renderResult *RenderResult) (string, error)

UploadResult uploads the provided render result to the Cloud Storage path where Cloud Deploy expects it. Returns the Cloud Storage URI of the uploaded result.

type RenderResult

type RenderResult struct {
	ResultStatus   RenderStatus      `json:"resultStatus"`
	ManifestFile   string            `json:"manifestFile"`
	FailureMessage string            `json:"failureMessage,omitempty"`
	Metadata       map[string]string `json:"metadata,omitempty"`
}

RenderResult represents the json data expected in the results file by Cloud Deploy for a render operation.

type RenderStatus

type RenderStatus string

RenderStatus represents the valid result status for a render request.

const (
	RenderSucceeded    RenderStatus = "SUCCEEDED"
	RenderFailed       RenderStatus = "FAILED"
	RenderNotSupported RenderStatus = "NOT_SUPPORTED"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL