|
| 1 | +--- |
| 2 | +name: cloud-deploy-pipelines |
| 3 | +description: > |
| 4 | + 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 rollback (manually or automatically) when there are issues deploying their application. |
| 5 | +--- |
| 6 | + |
| 7 | +# Cloud Deploy Pipelines |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +## Workflow: Designing a Pipeline |
| 14 | + |
| 15 | +This workflow provides steps for designing a Cloud Deploy `DeliveryPipeline`. |
| 16 | + |
| 17 | +### Constraints & Rules |
| 18 | + |
| 19 | +1. **NO PLACEHOLDERS**: Never generate YAML with placeholders like `<PROJECT_ID>`. Ask the user for values first. |
| 20 | +2. **Context First**: Always check existing files and conversation context before asking. |
| 21 | +3. **Step-by-Step**: Perform the steps one at a time. The goal is to guide the user through designing a delivery pipeline. |
| 22 | + |
| 23 | +### Step 0: Prerequisites |
| 24 | + |
| 25 | +**Required Context**: Before generating ANY configuration for this workflow, you **MUST** have the following values. Ask the user strictly for any missing information: |
| 26 | +- **Project ID**: The Google Cloud project ID for the Cloud Deploy resources. |
| 27 | +- **Region**: The region for the Cloud Deploy resources (e.g., `us-central1`). |
| 28 | +- **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. |
| 29 | +- **Runtime**: Either Cloud Run or Google Kubernetes Engine (GKE). |
| 30 | + - **If Cloud Run**: The Cloud Run project and location. |
| 31 | + - **If GKE**: The GKE cluster name. |
| 32 | + |
| 33 | +### Step 1: Define the target environments |
| 34 | + |
| 35 | +1. Identify the number of deployment environments (e.g., dev, staging, production). |
| 36 | +2. Identify if promotions should require user approval. |
| 37 | +3. Define each of the deployment environments as Cloud Deploy `Target` resources in a `clouddeploy.yaml` file. |
| 38 | + - Use `references/configure-targets.md` as a reference when generating the resource YAML. |
| 39 | + - 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. |
| 40 | + |
| 41 | +### Step 2: Define the delivery pipeline |
| 42 | + |
| 43 | +1. Identify whether the user wants to use a canary deployment strategy for any of the target environments. |
| 44 | +2. Define the Cloud Deploy `DeliveryPipeline` in the `clouddeploy.yaml` file. |
| 45 | + - Use `references/configure-pipelines.md` as a reference when generating the resource YAML. |
| 46 | + - Use application name as the `DeliveryPipeline` ID. |
| 47 | + |
| 48 | +### Step 3: Define automations |
| 49 | + |
| 50 | +1. Identify whether the user wants to automatically rollback if any failures occur during the rollout. |
| 51 | +2. **If the user specified multiple deployment environments in the previous step** |
| 52 | + - Identify if they want automatic promotions between deployment environments. |
| 53 | +3. **If the user specified a canary deployment strategy in the previous step** |
| 54 | + - Identify if they want to automatically advance the rollout through the phases after a wait period. |
| 55 | +4. Define the Cloud Deploy `Automation` resources in the `clouddeploy.yaml` file. |
| 56 | + - Use `references/configure-automations.md` as a reference when generating the resource YAML. |
| 57 | + |
| 58 | +### Step 4: Validate the clouddeploy.yaml file |
| 59 | + |
| 60 | +Ensure that the `clouddeploy.yaml` file is valid. See https://docs.cloud.google.com/deploy/docs/config-files for the schema. |
| 61 | + |
| 62 | +### Step 5: Create the delivery pipeline |
| 63 | + |
| 64 | +Run the following command to create the Cloud Deploy `DeliveryPipeline` and associated resources, using the values collected in Step 0: |
| 65 | + |
| 66 | +```bash |
| 67 | +gcloud deploy apply --file=clouddeploy.yaml --region=<REGION> --project=<PROJECT_ID> |
| 68 | +``` |
| 69 | + |
| 70 | +### Step 6: Create a skaffold.yaml file and runtime manifests |
| 71 | + |
| 72 | +**Required Context**: Before generating a `skaffold.yaml` file, you **MUST** know if the user has manifests for the runtime they are deploying to. |
| 73 | + |
| 74 | +1. **If the user does not have runtime manifests**: Generate some basic ones based on the runtime. |
| 75 | + - **If Cloud Run**: Generate a Cloud Run manifest. Use `references/basic-cloudrun-manifests.md` as a reference. |
| 76 | + - **If GKE**: Generate a Kubernetes `Deployment` and `Service`manifest. Use `references/basic-k8s-manifests.md` as a reference. |
| 77 | +2. Create a `skaffold.yaml` file required to create a Cloud Deploy `Release` for the `DeliveryPipeline`. |
| 78 | + - Use `references/configure-skaffold.md` as a reference when generating the `skaffold.yaml` file. |
| 79 | + |
| 80 | +## Release Management |
| 81 | + |
| 82 | +This section covers the various aspects of managing Cloud Deploy `Release` resources. |
| 83 | + |
| 84 | +### Constraints & Rules |
| 85 | + |
| 86 | +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. |
| 87 | + |
| 88 | +**Required Context**: |
| 89 | + - **Project ID**: The Google Cloud project ID of the `DeliveryPipeline`. |
| 90 | + - **Region**: The region of the `DeliveryPipeline` (e.g., `us-central1`). |
| 91 | + - **Delivery Pipeline ID**: The `DeliveryPipeline` ID. |
| 92 | + |
| 93 | +### Create a release |
| 94 | + |
| 95 | +**Use case**: The user wants to deploy a new version of their application. |
| 96 | + |
| 97 | +**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`. |
| 98 | + |
| 99 | +Run the following command to create a `Release` for the `DeliveryPipeline`: |
| 100 | + |
| 101 | +```bash |
| 102 | +gcloud deploy releases create release-$DATE-$TIME --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID> |
| 103 | +``` |
| 104 | + |
| 105 | +If the user is leveraging build artifact substitution with a placeholder in the image field of the runtime manifests then use the `--images` flag: |
| 106 | + |
| 107 | +```bash |
| 108 | +gcloud deploy releases create release-$DATE-$TIME --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID> --images <IMAGE_PLACEHOLDER>=<IMAGE_URI> |
| 109 | +``` |
| 110 | + |
| 111 | +**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. |
| 112 | + |
| 113 | +Reference documenation for `gcloud deploy releases create`: https://docs.cloud.google.com/sdk/gcloud/reference/deploy/releases/create. |
| 114 | + |
| 115 | +### Promote a release |
| 116 | + |
| 117 | +**Use case**: The user wants to promote the application to the next target environment in the `DeliveryPipeline` progression sequence. |
| 118 | + |
| 119 | +Run the following command to promote a `Release` to the next target in the `DeliveryPipeline` progression sequence: |
| 120 | + |
| 121 | +```bash |
| 122 | +gcloud deploy promote --release=<RELEASE_ID> --delivery-pipeline=<DELIVERY_PIPELINE_ID> --region=<REGION> --project=<PROJECT_ID> |
| 123 | +``` |
| 124 | + |
| 125 | +Reference documentation for `gcloud deploy releases promote`: https://docs.cloud.google.com/sdk/gcloud/reference/deploy/releases/promote. |
| 126 | + |
| 127 | +### Monitor a release |
| 128 | + |
| 129 | +**Use case**: Monitor the status of a release across a `DeliveryPipeline`. |
| 130 | + |
| 131 | +Monitoring a release across a `DeliveryPipeline` 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`. |
| 132 | + |
| 133 | +### Troubleshoot |
| 134 | + |
| 135 | +#### Release failed |
| 136 | + |
| 137 | +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. |
| 138 | + |
| 139 | +#### Rollout failed |
| 140 | + |
| 141 | +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. |
0 commit comments