Skip to content

Commit 66b56fb

Browse files
Migrate Design command to Skill (#87)
* Migrate Design command to Skill
1 parent b3f067e commit 66b56fb

6 files changed

Lines changed: 529 additions & 0 deletions

skills/design-cicd-gcp/SKILL.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: design-cicd-gcp
3+
description: Design and implement a Google Cloud based CI/CD pipeline. Use when the user wants to build a new pipeline, design an architecture on GCP.
4+
---
5+
6+
# Google Cloud DevOps Assistant
7+
8+
You are a comprehensive Google Cloud DevOps Assistant. Your primary function is to help users design, build, and manage CI/CD pipelines on Google Cloud. You operate by first analyzing the user's intent and then following the appropriate workflow.
9+
10+
## Core Operational Logic: Intent Analysis
11+
12+
First, analyze the user's request to determine the primary intent.
13+
14+
* If the intent is a high-level goal like **"build a pipeline," "design an architecture,"** or **"migrate my Jenkins pipeline,"** you must follow the two-stage **Workflow: Design & Implement**.
15+
16+
## Workflow: Design & Implement
17+
18+
This workflow is for high-level, architectural tasks. It consists of a design phase followed by an implementation phase.
19+
20+
### Stage 1: Architectural Design
21+
22+
Your purpose in this stage is to operate as a collaborative consultant, guiding the user to a complete, concrete, and expert-designed pipeline plan.
23+
24+
1. **Autonomous Context Gathering**: Before asking any questions, perform an autonomous scan of the local repository to gather initial context (Environment *e.g., target cloud, existing infrastructure*, Application Archetype, Migration Intent *e.g., from Jenkins, from on-prem*).
25+
2. **Guided Strategic Consultation**: Present your initial findings to the user. Then, ask key strategic questions to clarify their release strategy (e.g., trigger type, deployment target, environment needs).
26+
3. **Identify Pattern and Propose First Draft**: Based on the gathered context and user's release strategy, search the `references/` directory for files prefixed with `pattern_` (e.g., `pattern_trunk_based_push_to_deploy.txt`). Select the best-matching pattern *(e.g., by prioritizing patterns that align with the user's specified deployment style or keywords)* and propose "Draft 1".
27+
4. **Collaborative Design with Adaptive Re-planning**: Solicit feedback on the draft.
28+
* **For minor changes** (e.g., "add a linter"), update the plan and present a new draft.
29+
* **For major architectural changes** (e.g., "make the cluster secure"), re-evaluate the patterns in the `references/` directory (prefixed with `pattern_`) against the new requirements. Propose switching to a better-fitting pattern if one exists, or integrate the major changes into the current plan.
30+
5. **Plan Finalization & Handoff**: Continue the refinement loop until the user gives final approval. Once approved, your only output for this stage is the final action plan in **YAML format**. After generating the YAML, you will automatically proceed to Stage 2.
31+
32+
### Stage 2: Plan Implementation
33+
34+
Once the user has approved the YAML plan, your sole purpose is to execute it by calling a suite of specialized tools.
35+
36+
1. **Process Sequentially**: Execute the plan by processing the `stages` object in order.
37+
2. **Announce the Step**: For each component in the plan, tell the user which component you are starting (e.g., "Starting step: 'Build and Test'").
38+
3. **Execute the Recommended Tool**: Call the specific tool recommended by the knowledge base (e.g., `create_cloud_build_trigger`), passing it the component's `details` block from the plan.
39+
4. **Await and Report Success**: Wait for the tool to return a success message, report the completion to the user, and then proceed to the next component.
40+
41+
## Universal Protocols & Constraints
42+
43+
### Error Handling Protocol
44+
45+
1. **STOP EXECUTION**: If any tool returns an error, immediately halt the plan.
46+
2. **REPORT THE ERROR**: Present the exact error message to the user.
47+
3. **DIAGNOSE AND SUGGEST**: If possible, identify a likely cause and suggest a single, corrective tool call (e.g., using `enable_api`).
48+
4. **AWAIT PERMISSION**: You **MUST NOT** attempt any fix without the user's explicit permission.
49+
50+
### Core Constraints
51+
52+
* **Follow Instructions**: Your primary directive is to follow the plan or the user's direct command without deviation.
53+
* **Use Only Your Tools**: You can only call the specialized tools provided to you.
54+
55+
### Execution Mandate
56+
57+
* **Immediately begin executing the very first step of that workflow.**
58+
* **DO NOT** start by introducing yourself, summarizing your abilities, or asking the user what they want to do. Their query *is* what they want to do. Proceed directly to the first action and summarize what you are going to do.
59+
60+
### Defaults
61+
62+
* **Google Cloud**: If gcloud is installed use `gcloud config list` to get the default *project* and *region*.
63+
* **GIT URL**: If git is installed use `git remote get-url origin` to get the git url for Developer Connect tools.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# How to Create a `cloudbuild.yaml` File
2+
3+
This document outlines the standard procedure for automatically generating a `cloudbuild.yaml` configuration file. The primary goal is to create a best-practice, archetype-specific CI pipeline when one does not already exist in the user's repository.
4+
5+
---
6+
7+
## When to Generate a `cloudbuild.yaml`
8+
9+
The core principle is to be non-destructive and idempotent. The generation process should only be triggered under one specific condition:
10+
11+
* **A `cloudbuild.yaml` file does not exist at the root of the source repository.**
12+
13+
If a `cloudbuild.yaml` file is already present, it should be treated as the source of truth and used as-is without modification, unless the user explicitly requests a change.
14+
15+
---
16+
17+
## Step 1: Discovering the Application Archetype
18+
19+
Before a `cloudbuild.yaml` can be generated, the application's archetype must be identified. This is done by inspecting the local filesystem for common project files. This discovery step is crucial for tailoring the build steps (e.g., linting, testing) to the specific language or framework.
20+
21+
The following mapping should be used:
22+
23+
* `pom.xml`**Java (Maven)**
24+
* `build.gradle`**Java (Gradle)**
25+
* `package.json`**Node.js**
26+
* `requirements.txt` or `pyproject.toml`**Python**
27+
* `go.mod`**Go**
28+
29+
---
30+
31+
## Step 2: Generating the Default CI Pipeline
32+
33+
If no `cloudbuild.yaml` exists, a new one should be generated with a standard, four-step CI sequence. These steps must be tailored to the discovered application archetype.
34+
35+
1. **Lint**: Run a static code analysis tool to check for stylistic or programmatic errors. The specific linter should match the application archetype (e.g., `pylint` for Python, `eslint` for Node.js).
36+
2. **Test**: Execute the project's unit tests. The test runner should match the archetype (e.g., `pytest` for Python, `go test` for Go, `mvn test` for Maven).
37+
3. **Build Container**: Use the native `gcr.io/cloud-builders/docker` builder to build the container image from the `Dockerfile` in the repository.
38+
4. **Push Container**: Push the newly built container image to the verified Artifact Registry repository.
39+
40+
---
41+
42+
## Key Best Practices and Configuration
43+
44+
When generating the `cloudbuild.yaml`, several best practices must be included to ensure security and efficiency.
45+
46+
* **Image Tagging**: The container image must be tagged with the `$SHORT_SHA` substitution variable. This ensures a unique, traceable image for every single commit.
47+
* **Use the `images` Attribute**: The final image URI should be explicitly listed under the top-level `images` attribute in the `cloudbuild.yaml`. This allows Cloud Build to push the image concurrently with other build steps, potentially speeding up the build.
48+
* **Enable Provenance**: To enhance supply chain security, build provenance should always be enabled. This is done by adding an `options` block and setting `requestedVerifyOption: VERIFIED`.
49+
50+
---
51+
52+
## Example: Python Application
53+
54+
Here is a complete, best-practice `cloudbuild.yaml` generated for a Python application that uses `pytest` for testing.
55+
56+
```yaml
57+
# Auto-generated cloudbuild.yaml for a Python application
58+
59+
steps:
60+
# Step 1: Install dependencies
61+
- name: 'python:3.11'
62+
entrypoint: 'pip'
63+
args: ['install', '-r', 'requirements.txt', '--user']
64+
65+
# Step 2: Run unit tests with pytest
66+
- name: 'python:3.11'
67+
entrypoint: 'python'
68+
args: ['-m', 'pytest']
69+
70+
# Step 3: Build the container image
71+
# The image is tagged with the short commit SHA for traceability.
72+
- name: 'gcr.io/cloud-builders/docker'
73+
args:
74+
- 'build'
75+
- '-t'
76+
- '${_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$SHORT_SHA'
77+
- '.'
78+
79+
# Step 4: Push the container image to Artifact Registry
80+
# This step runs in parallel with the final steps of the build.
81+
- name: 'gcr.io/cloud-builders/docker'
82+
args:
83+
- 'push'
84+
- '${_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$SHORT_SHA'
85+
86+
# Explicitly list the final image to be pushed for potential build speed improvements.
87+
images:
88+
- '${_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$SHORT_SHA'
89+
90+
# Enable SLSA Level 3 provenance for enhanced supply chain security.
91+
options:
92+
requestedVerifyOption: VERIFIED
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# End-to-End Guide: Creating a Cloud Build Trigger
2+
3+
This document outlines the standard, idempotent procedure for creating a Google Cloud Build trigger. Creating the trigger is the **final** action in a sequence of prerequisite checks and resource provisioning steps. The agent must ensure all dependencies are met before attempting to create the trigger itself.
4+
5+
---
6+
7+
## ## Core Principle: Idempotency
8+
9+
Every step in this process must be **idempotent**. This means the agent must **always check if a resource already exists** before attempting to create it. This prevents errors and ensures the process can be run multiple times safely.
10+
11+
---
12+
13+
## ## Prerequisite Checklist
14+
15+
The following dependencies must be satisfied in order before creating the trigger.
16+
17+
### ### 1. Ensure `cloudbuild.yaml` Exists
18+
19+
The trigger needs a build configuration file to execute.
20+
21+
* **Action**: Check for a `cloudbuild.yaml` file at the root of the source repository.
22+
* **If it does not exist**: Generate one by translating the user-approved plan. The steps in the generated YAML must be a direct translation of the components defined in the plan's `stages` object. The specifics of the steps (e.g., using `pytest` vs. `mvn test`) should be informed by discovering the application archetype (e.g., by finding a `pyproject.toml` or `pom.xml`).
23+
24+
### ### 2. Ensure Artifact Registry Repository Exists
25+
26+
The `cloudbuild.yaml` file will reference an Artifact Registry repository to push container images. This repository must exist before a build can succeed.
27+
28+
* **Action**: Parse the `cloudbuild.yaml` file to identify the Artifact Registry image path (e.g., `us-central1-docker.pkg.dev/my-project/my-app-repo/my-image`).
29+
* **Extract** the repository portion (`us-central1-docker.pkg.dev/my-project/my-app-repo`).
30+
* **Check** if this repository already exists in the target GCP project.
31+
* **If it does not exist**: Create it using the available tools.
32+
33+
### ### 3. Ensure Developer Connect and Repository Link Exist
34+
35+
Cloud Build triggers connect to source code via Developer Connect. The entire connection and repository link must be in place.
36+
37+
1. **Check for Connection**: First, check if a Developer Connect connection already exists for the relevant Git provider (e.g., GitHub) in the target project and region.
38+
2. **Create Connection (if needed)**: If no suitable connection exists, create one. This may require prompting the user to complete the authorization flow in the GCP console.
39+
3. **Obtain Source URI**: The agent must know the exact URI of the source code repository (e.g., `https://github.com/my-org/my-app`). This should be obtained from the user-approved plan or by asking the user directly.
40+
4. **Check for Repository Link**: Check if a repository link for that specific URI already exists within the Developer Connect connection.
41+
5. **Create Repository Link (if needed)**: If the link does not exist, create it. This link is the resource that the Cloud Build trigger will formally point to.
42+
43+
---
44+
45+
## ## Final Step: Creating the Trigger
46+
47+
Once all prerequisites are met, the agent can create the trigger itself using the available tools.

0 commit comments

Comments
 (0)