Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions skills/cloud-deploy-pipelines/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
name: cloud-deploy-pipelines
description: >
Design Cloud Deploy delivery pipelines and manage releases when deploying applications to Cloud Run and Google Kubernetes Engine (GKE). Use when users want to deploy their applications to multiple environments (e.g. dev and prod), leverage deployment strategies (i.e. canary), or enable automatic rollbacks when there are issues with the rollout. Should also be used if the user is already using Cloud Deploy and wants to create releases, promote releases across environments, or debug release failures.
---

# Cloud Deploy Pipelines

## Overview

This skill encompasses the entire lifecycle of Cloud Deploy for a user, from designing and creating delivery pipelines to managing releases and debugging release failures.

## Workflow: Designing a Pipeline

This workflow provides steps for designing a Cloud Deploy `DeliveryPipeline`.

### Constraints & Rules

1. **NO PLACEHOLDERS**: Never generate YAML with placeholders like `<PROJECT_ID>`. Ask the user for values first.
2. **Context First**: Always check existing files and conversation context before asking.
3. **Step-by-Step**: Perform the steps one at a time. The goal is to guide the user through designing a delivery pipeline.

### Step 0: Prerequisites

**Required Context**: Before generating ANY configuration for this workflow, you **MUST** have the following values. Ask the user strictly for any missing information:
- **Project ID**: The Google Cloud project ID for the Cloud Deploy resources.
- **Region**: The region for the Cloud Deploy resources (e.g., `us-central1`).
- **Application Name**: The name of the application that will be deployed. Use the application name to generate the names of the Cloud Deploy resources, such as `DeliveryPipeline` and `Target` resources.
- **Runtime**: Either Cloud Run or Google Kubernetes Engine (GKE).
- **If Cloud Run**: The Cloud Run project and location.
- **If GKE**: The GKE cluster name.

### Step 1: Define the target environments

1. Identify the number of environments (e.g., dev, staging, production).
2. Identify if promotions should require user approval.
3. Define each of the environments as Cloud Deploy `Target` resources in a `clouddeploy.yaml` file.
- Use `references/configure-targets.md` as a reference when generating the resource YAML.
- Use the application name provided by the user when naming the Cloud Deploy `Target` resources. For example, if the user wants to deploy an application named "hello-world" to a test and production environment then use "hello-world-test" and "hello-world-prod" as the `Target` IDs.

### Step 2: Define the delivery pipeline

1. Identify whether the user wants to use a canary deployment strategy for any of the target environments.
2. Define the Cloud Deploy `DeliveryPipeline` in the `clouddeploy.yaml` file.
- Use `references/configure-pipelines.md` as a reference when generating the resource YAML.
- Use application name as the `DeliveryPipeline` ID.

### Step 3: Define automations

1. Identify whether the user wants to automatically rollback if any failures occur during the rollout.
2. **If the user specified multiple environments in the previous step**
- Identify if they want automatic promotions between environments.
3. **If the user specified a canary deployment strategy in the previous step**
- Identify if they want to automatically advance the rollout through the phases after a wait period.
4. Define the Cloud Deploy `Automation` resources in the `clouddeploy.yaml` file.
- Use `references/configure-automations.md` as a reference when generating the resource YAML.

### Step 4: Validate the clouddeploy.yaml file

Ensure that the `clouddeploy.yaml` file is valid. See https://docs.cloud.google.com/deploy/docs/config-files for the schema.

### Step 5: Create the delivery pipeline

Run the following command to create the Cloud Deploy `DeliveryPipeline` and associated resources, using the values collected in Step 0:

```bash
gcloud deploy apply --file=clouddeploy.yaml --region=<REGION> --project=<PROJECT_ID>
```

### Step 6: Create a skaffold.yaml file and runtime manifests

**Required Context**: Before generating a `skaffold.yaml` file, you **MUST** know if the user has manifests for the runtime they are deploying to.

1. **If the user does not have runtime manifests**: Generate some basic ones based on the runtime.
- **If Cloud Run**: Generate a Cloud Run manifest. Use `references/basic-cloudrun-manifests.md` as a reference.
- **If GKE**: Generate a Kubernetes `Deployment` and `Service`manifest. Use `references/basic-k8s-manifests.md` as a reference.
2. Create a `skaffold.yaml` file required to create a Cloud Deploy `Release` for the `DeliveryPipeline`.
- Use `references/configure-skaffold.md` as a reference when generating the `skaffold.yaml` file.

## Release Management

This section covers the various aspects of managing Cloud Deploy `Release` resources.

### Constraints & Rules

In order to manage releases, a `DeliveryPipeline` MUST already be defined and configured in Cloud Deploy. Determine whether a delivery pipeline is defined by checking for a `clouddeploy.yaml` file and checking if the resources exist in Cloud Deploy or ask the user directly.

**Required Context**:
- **Project ID**: The Google Cloud project ID of the `DeliveryPipeline`.
- **Region**: The region of the `DeliveryPipeline` (e.g., `us-central1`).
- **Delivery Pipeline ID**: The `DeliveryPipeline` ID.

### Create a release

**Required Context**: Before creating a `Release`, you **MUST** know whether the users runtime manifests are using a placeholder for the container image and the value of the placeholder. This is **CRITICAL** for build artifact substitution in Cloud Deploy. Check the users runtime manifests or ask the user directly. See examples in `references/basic-cloudrun-manifests.md` and `references/basic-k8s-manifests.md`.

Run the following command to create a `Release` for the `DeliveryPipeline`:

```bash
gcloud deploy releases create release-$DATE-$TIME --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID>
```

If the user is leveraging build artifact substitution with a placeholder in the image field of the runtime manifests then use the `--images` flag:

```bash
gcloud deploy releases create release-$DATE-$TIME --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID> --images <IMAGE_PLACEHOLDER>=<IMAGE_URI>
```

**CRITICAL**: If the `skaffold.yaml` is not in the current directory, use the `--source` flag to specify the directory where the `skaffold.yaml` file is located.

Reference documenation for `gcloud deploy releases create`: https://docs.cloud.google.com/sdk/gcloud/reference/deploy/releases/create.

### Promote a release

Run the following command to promote a `Release` to the next target in the `DeliveryPipeline` progression sequence:

```bash
gcloud deploy promote --release=<RELEASE_ID> --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID>
```

Reference documentation for `gcloud deploy releases promote`: https://docs.cloud.google.com/sdk/gcloud/reference/deploy/releases/promote.

### Monitor a release

Monitoring a release across a delivery pipeline consists of checking the status of both the `Release` resource and its child `Rollout` resource(s). Always ensure that the `Release` has completed successfully before checking the status of the `Rollout`.

### Troubleshoot

#### Release failed

Get the release to determine which of the target renders failed and inspect the failure message and failure cause. Additionally the target renders contain a Cloud Build reference where the target render was executed. Retrieve the build logs to determine the root cause of the failure.

#### Rollout failed

Get the rollout to determine which of the jobs failed and inspect the failure message and failure cause. Additionally the `Rollout` contains a Cloud Build reference where the failed job was executed. Retrieve the build logs to determine the root cause of the failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Basic Cloud Run manifests

This document provides examples for generating Cloud Run resource manifests that are used with Cloud Deploy to deploy to Cloud Run.

The examples in this file use placeholders between `<` and `>`, e.g. `<SERVICE_NAME>`. Replace these placeholders with the actual values when generating the YAML.

Cloud Deploy performs build artifact substitutions on the image field so a placeholder like `app-image` is used. When a Cloud Deploy `Release` is created the user supplies the actual image and associates it with the `app-image` key.

## Cloud Run Service

```yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: <SERVICE_NAME>
spec:
template:
spec:
containers:
- image: app-image
```

## Cloud Run Worker Pool

```yaml
apiVersion: run.googleapis.com/v1
kind: WorkerPool
metadata:
name: <WORKER_POOL_NAME>
spec:
template:
spec:
containers:
- image: app-image
```
49 changes: 49 additions & 0 deletions skills/cloud-deploy-pipelines/references/basic-k8s-manifests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Basic Kubernetes manifests

This document provides examples for generating Kubernetes `Deployment` and `Service` resource manifests that are used with Cloud Deploy to deploy to GKE.

The examples in this file use placeholders between `<` and `>`, e.g. `<DEPLOYMENT_NAME>`. Replace these placeholders with the actual values when generating the YAML.

Cloud Deploy performs build artifact substitutions on the image field so a placeholder like `app-image` is used. When a Cloud Deploy `Release` is created the user supplies the actual image and associates it with the `app-image` key.

## Kubernetes Deployment

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: <DEPLOYMENT_NAME>
labels:
app: <APPLICATION_NAME>
spec:
replicas: 1
selector:
matchLabels:
app: <APPLICATION_NAME>
template:
metadata:
labels:
app: <APPLICATION_NAME>
spec:
containers:
- name: <APPLICATION_NAME>
image: app-image
```

## Kubernetes Service

```yaml
apiVersion: v1
kind: Service
metadata:
name: <SERVICE_NAME>
labels:
app: <APPLICATION_NAME>
spec:
selector:
app: <APPLICATION_NAME>
ports:
- protocol: TCP
port: 80
type: LoadBalancer
```
118 changes: 118 additions & 0 deletions skills/cloud-deploy-pipelines/references/configure-automations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Configure Automations

This document provides examples for configuring Cloud Deploy `Automation` resources. The examples are in YAML format and are intended to be used with the `gcloud deploy apply` command to create or update the resource. Use these examples if it fits the users requirements.

The examples in this file use placeholders between `<` and `>`, e.g. `<AUTOMATION_ID>`. Replace these placeholders with the actual values when generating the YAML.

**CRITICAL**:
- The `metadata.name` field for an `Automation` resource is made up of the `DeliveryPipeline` ID and the `Automation` ID, separated by a forward slash. For example, if the `DeliveryPipeline` ID is "hello-world" and the `Automation` ID is "promote" then the `metadata.name` field should be "hello-world/promote".
- Automations **require** a service account to run as. Use the Compute Engine default service account if the user doesn't provide one. The format is:

```
<PROJECT_NUMBER>-compute@developer.gserviceaccount.com
```

## Automatic Rollbacks

This `Automation` will rollback for any `Target` in the `DeliveryPipeline` progression sequence if the `Rollout` fails.

The `*` in the `selector.targets.id` field means that this `Automation` will apply to all `Target` resources in the `DeliveryPipeline`.

```yaml
apiVersion: deploy.cloud.google.com/v1
kind: Automation
metadata:
name: <PIPELINE_ID>/<AUTOMATION_ID>
serviceAccount: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com
selector:
targets:
- id: "*"
rules:
- repairRolloutRule:
id: "repair-rule"
repairPhases:
- rollback: {}
```

## Automatic Rollbacks with Retry

This `Automation` will attempt to retry the failed `Rollout` job up to 3 times with a 1 minute wait between attempts. If the `Rollout` still fails after the retries then it will be rolled back.

```yaml
apiVersion: deploy.cloud.google.com/v1
kind: Automation
metadata:
name: <PIPELINE_ID>/<AUTOMATION_ID>
serviceAccount: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com
selector:
targets:
- id: "*"
rules:
- repairRolloutRule:
id: "repair-rule"
repairPhases:
- retry:
attempts: 3
wait: 1m
- rollback: {}
```

## Automatic Promotions on a Schedule

This `Automation` will automatically promote a release to the next `Target` in the `DeliveryPipeline` progression sequence every Monday at 12:00 PM New York time.

```yaml
apiVersion: deploy.cloud.google.com/v1
kind: Automation
metadata:
name: <PIPELINE_ID>/<AUTOMATION_ID>
serviceAccount: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com
selector:
targets:
- id: <FROM_TARGET_ID>
rules:
- timedPromoteReleaseRule:
id: "timed-promote-rule"
schedule: "0 12 * * 1" # Cron format.
timeZone: "America/New_York" # IANA format.
destinationTargetId: "@next" # promote to the next `Target` in the `DeliveryPipeline` progression sequence.
```

## Automatic Promotion after a Delay

This `Automation` will automatically promote a release to the next `Target` in the `DeliveryPipeline` after 3 hours has passed since the release was rolled out to the previous `Target`.

```yaml
apiVersion: deploy.cloud.google.com/v1
kind: Automation
metadata:
name: <PIPELINE_ID>/<AUTOMATION_ID>
serviceAccount: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com
selector:
targets:
- id: <FROM_TARGET_ID>
rules:
- promoteReleaseRule:
id: "promote-rule"
wait: 3h
destinationTargetId: "@next" # promote to the next `Target` in the `DeliveryPipeline` progression sequence.
```

## Automatic Canary Advance

This `Automation` will automatically advance through each phase of a canary `Rollout` for a specific `Target` after 1 hour has passed since the previous phase completed.

```yaml
apiVersion: deploy.cloud.google.com/v1
kind: Automation
metadata:
name: <PIPELINE_ID>/<AUTOMATION_ID>
serviceAccount: <PROJECT_NUMBER>-compute@developer.gserviceaccount.com
selector:
targets:
- id: <TARGET_ID>
rules:
- advanceRolloutRule:
id: "advance-rule"
wait: 1h
```
Loading