Skip to content

Commit ebce541

Browse files
committed
fix: improved instruction for following patterns, dockerfile creation, project analysis
1 parent 137dbeb commit ebce541

3 files changed

Lines changed: 184 additions & 67 deletions

File tree

skills/google-cicd-deploy/references/how_to_write_dockerfile.md

Lines changed: 107 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ USER appuser
2626

2727
```
2828

29-
30-
3129
---
3230

3331
## 3. Multi-Stage Builds (The Gold Standard)
@@ -89,13 +87,58 @@ ENTRYPOINT ["/app"]
8987

9088
```
9189

90+
### 💡 Example 3: Python simple application)
91+
92+
# --- Stage 1: Builder Stage ---
93+
# Use a full Python image with build tools
94+
FROM python:3.12-slim AS builder
95+
96+
# Set the working directory inside the container
97+
WORKDIR /app
98+
99+
# Copy the requirements file and install dependencies
100+
COPY requirements.txt .
101+
RUN pip install --no-cache-dir -r requirements.txt
102+
103+
# Copy application code
104+
COPY . .
105+
106+
# --- Stage 2: Final (Runtime) Stage ---
107+
# Use a minimal, slim Python image for the final runtime
108+
FROM python:3.12-slim AS final
109+
110+
# Set the working directory
111+
WORKDIR /app
112+
113+
# Copy the installed packages from the builder stage into the final image
114+
# This is a key step to include only the necessary libraries
115+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
116+
117+
# Copy the application code from the builder stage
118+
COPY --from=builder /app .
119+
120+
# Expose the port the app runs on (adjust if your app uses a different port)
121+
EXPOSE 8000
122+
123+
# Command to run the application
124+
CMD ["python", "app.py"]
125+
92126
---
93127

94-
## 4. Google Cloud Run Specifics
128+
## 4. Recommended Base Images
129+
130+
### Generic Base Image suggestions
131+
* For programming languages use their official base image.
132+
* Use latest version of the language specific image as base image.
133+
* Review project config files to identify required runtime version:
134+
* When a runtime version is specified, use that version for the base image.
135+
* If no minimum version is specified use latest version of the runtime
136+
137+
### Google Cloud Run Specifics Base Images
95138

96139
If you are deploying to **Google Cloud Run**, you can leverage advanced features for security and maintenance.
97140

98-
### Base Image for Cloud Run Automatic Updates
141+
#### Base Image for Cloud Run Automatic Updates
99142

100143
Google Cloud can automatically patch security vulnerabilities in your base image if you follow the **"Scratch Pattern"**.
101144

@@ -121,11 +164,11 @@ CMD [ "node", "index.js" ]
121164

122165
```
123166

124-
### Recommended Base Images (Stacks)
167+
#### Recommended Base Images (Stacks)
125168

126169
A base image serves as the starting foundation for container-based development. You build your application by layering necessary libraries, binaries, and configuration files on top of this image. Google Cloud's buildpacks publish these images with various configurations for system packages and languages.
127170

128-
#### Key Guidelines
171+
##### Key Guidelines
129172

130173
* **Hosting**: Base images are hosted in every region where the Artifact Registry is available.
131174
* **Updates**: Security and maintenance updates are released routinely. Depending on your environment (e.g., Cloud Run functions) and configuration, these updates can be applied automatically or manually.
@@ -139,70 +182,70 @@ A base image serves as the starting foundation for container-based development.
139182

140183

141184
Runtime IDs and environment details (mostly Ubuntu 22.04 or 18.04, with some newer Ubuntu 24.04 options) for the following languages:
142-
| Language | Runtime | Generation | Environment | Runtime ID |
143-
| :---------- | :------------ | :-------------- | :---------- | :---------- |
144-
| Node.js | Node.js 24 | 2nd gen | Ubuntu 24.04| nodejs24 |
145-
| Node.js | Node.js 22 | 1st gen, 2nd gen| Ubuntu 22.04| nodejs22 |
146-
| Node.js | Node.js 20 | 1st gen, 2nd gen| Ubuntu 22.04| nodejs20 |
147-
| Node.js | Node.js 18 | 1st gen, 2nd gen| Ubuntu 22.04| nodejs18 |
148-
| Node.js | Node.js 16 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs16 |
149-
| Node.js | Node.js 14 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs14 |
150-
| Node.js | Node.js 12 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs12 |
151-
| Node.js | Node.js 10 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs10 |
152-
| Node.js | Node.js 8 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs8 |
153-
| Node.js | Node.js 6 | 1st gen, 2nd gen| Ubuntu 18.04| nodejs6 |
154-
| Python | Python 3.14 | 2nd gen | Ubuntu 24.04| python314 |
155-
| Python | Python 3.13 | 2nd gen | Ubuntu 22.04| python313 |
156-
| Python | Python 3.12 | 1st gen, 2nd gen| Ubuntu 22.04| python312 |
157-
| Python | Python 3.11 | 1st gen, 2nd gen| Ubuntu 22.04| python311 |
158-
| Python | Python 3.10 | 1st gen, 2nd gen| Ubuntu 22.04| python310 |
159-
| Python | Python 3.9 | 1st gen, 2nd gen| Ubuntu 18.04| python39 |
160-
| Python | Python 3.8 | 1st gen, 2nd gen| Ubuntu 18.04| python38 |
161-
| Python | Python 3.7 | 1st gen | Ubuntu 18.04| python37 |
162-
| Go | Go 1.25 | 2nd gen | Ubuntu 22.04| go125 |
163-
| Go | Go 1.24 | 2nd gen | Ubuntu 22.04| go124 |
164-
| Go | Go 1.23 | 2nd gen | Ubuntu 22.04| go123 |
165-
| Go | Go 1.22 | 2nd gen | Ubuntu 22.04| go122 |
166-
| Go | Go 1.21 | 1st gen, 2nd gen| Ubuntu 22.04| go121 |
167-
| Go | Go 1.20 | 1st gen, 2nd gen| Ubuntu 22.04| go120 |
168-
| Go | Go 1.19 | 1st gen, 2nd gen| Ubuntu 22.04| go119 |
169-
| Go | Go 1.18 | 1st gen, 2nd gen| Ubuntu 22.04| go118 |
170-
| Go | Go 1.16 | 1st gen, 2nd gen| Ubuntu 18.04| go116 |
171-
| Go | Go 1.13 | 1st gen, 2nd gen| Ubuntu 18.04| go113 |
172-
| Go | Go 1.11 | 1st gen, 2nd gen| Ubuntu 18.04| go111 |
173-
| Java | Java 25 | 2nd gen | Ubuntu 24.04| java25 |
174-
| Java | Java 21 | 2nd gen | Ubuntu 22.04| java21 |
175-
| Java | Java 17 | 1st gen, 2nd gen| Ubuntu 22.04| java17 |
176-
| Java | Java 11 | 1st gen, 2nd gen| Ubuntu 18.04| java11 |
177-
| Ruby | Ruby 3.4 | 2nd gen | Ubuntu 22.04| ruby34 |
178-
| Ruby | Ruby 3.3 | 1st gen, 2nd gen| Ubuntu 22.04| ruby33 |
179-
| Ruby | Ruby 3.2 | 1st gen, 2nd gen| Ubuntu 22.04| ruby32 |
180-
| Ruby | Ruby 3.0 | 1st gen, 2nd gen| Ubuntu 18.04| ruby30 |
181-
| Ruby | Ruby 2.7 | 1st gen, 2nd gen| Ubuntu 18.04| ruby27 |
182-
| Ruby | Ruby 2.6 | 1st gen, 2nd gen| Ubuntu 18.04| ruby26 |
183-
| PHP | PHP 8.4 | 2nd gen | Ubuntu 22.04| php84 |
184-
| PHP | PHP 8.3 | 2nd gen | Ubuntu 22.04| php83 |
185-
| PHP | PHP 8.2 | 1st gen, 2nd gen| Ubuntu 22.04| php82 |
186-
| PHP | PHP 8.1 | 1st gen, 2nd gen| Ubuntu 18.04| php81 |
187-
| PHP | PHP 7.4 | 1st gen, 2nd gen| Ubuntu 18.04| php74 |
188-
| .NET Core | .NET Core 8 | 2nd gen | Ubuntu 22.04| dotnet8 |
189-
| .NET Core | .NET Core 6 | 1st gen, 2nd gen| Ubuntu 22.04| dotnet6 |
190-
| .NET Core | .NET Core 3 | 1st gen, 2nd gen| Ubuntu 18.04| dotnet3 |
185+
| Language | Runtime | Generation | Environment | Runtime ID |
186+
| :-------- | :---------- | :--------------- | :----------- | :--------- |
187+
| Node.js | Node.js 24 | 2nd gen | Ubuntu 24.04 | nodejs24 |
188+
| Node.js | Node.js 22 | 1st gen, 2nd gen | Ubuntu 22.04 | nodejs22 |
189+
| Node.js | Node.js 20 | 1st gen, 2nd gen | Ubuntu 22.04 | nodejs20 |
190+
| Node.js | Node.js 18 | 1st gen, 2nd gen | Ubuntu 22.04 | nodejs18 |
191+
| Node.js | Node.js 16 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs16 |
192+
| Node.js | Node.js 14 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs14 |
193+
| Node.js | Node.js 12 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs12 |
194+
| Node.js | Node.js 10 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs10 |
195+
| Node.js | Node.js 8 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs8 |
196+
| Node.js | Node.js 6 | 1st gen, 2nd gen | Ubuntu 18.04 | nodejs6 |
197+
| Python | Python 3.14 | 2nd gen | Ubuntu 24.04 | python314 |
198+
| Python | Python 3.13 | 2nd gen | Ubuntu 22.04 | python313 |
199+
| Python | Python 3.12 | 1st gen, 2nd gen | Ubuntu 22.04 | python312 |
200+
| Python | Python 3.11 | 1st gen, 2nd gen | Ubuntu 22.04 | python311 |
201+
| Python | Python 3.10 | 1st gen, 2nd gen | Ubuntu 22.04 | python310 |
202+
| Python | Python 3.9 | 1st gen, 2nd gen | Ubuntu 18.04 | python39 |
203+
| Python | Python 3.8 | 1st gen, 2nd gen | Ubuntu 18.04 | python38 |
204+
| Python | Python 3.7 | 1st gen | Ubuntu 18.04 | python37 |
205+
| Go | Go 1.25 | 2nd gen | Ubuntu 22.04 | go125 |
206+
| Go | Go 1.24 | 2nd gen | Ubuntu 22.04 | go124 |
207+
| Go | Go 1.23 | 2nd gen | Ubuntu 22.04 | go123 |
208+
| Go | Go 1.22 | 2nd gen | Ubuntu 22.04 | go122 |
209+
| Go | Go 1.21 | 1st gen, 2nd gen | Ubuntu 22.04 | go121 |
210+
| Go | Go 1.20 | 1st gen, 2nd gen | Ubuntu 22.04 | go120 |
211+
| Go | Go 1.19 | 1st gen, 2nd gen | Ubuntu 22.04 | go119 |
212+
| Go | Go 1.18 | 1st gen, 2nd gen | Ubuntu 22.04 | go118 |
213+
| Go | Go 1.16 | 1st gen, 2nd gen | Ubuntu 18.04 | go116 |
214+
| Go | Go 1.13 | 1st gen, 2nd gen | Ubuntu 18.04 | go113 |
215+
| Go | Go 1.11 | 1st gen, 2nd gen | Ubuntu 18.04 | go111 |
216+
| Java | Java 25 | 2nd gen | Ubuntu 24.04 | java25 |
217+
| Java | Java 21 | 2nd gen | Ubuntu 22.04 | java21 |
218+
| Java | Java 17 | 1st gen, 2nd gen | Ubuntu 22.04 | java17 |
219+
| Java | Java 11 | 1st gen, 2nd gen | Ubuntu 18.04 | java11 |
220+
| Ruby | Ruby 3.4 | 2nd gen | Ubuntu 22.04 | ruby34 |
221+
| Ruby | Ruby 3.3 | 1st gen, 2nd gen | Ubuntu 22.04 | ruby33 |
222+
| Ruby | Ruby 3.2 | 1st gen, 2nd gen | Ubuntu 22.04 | ruby32 |
223+
| Ruby | Ruby 3.0 | 1st gen, 2nd gen | Ubuntu 18.04 | ruby30 |
224+
| Ruby | Ruby 2.7 | 1st gen, 2nd gen | Ubuntu 18.04 | ruby27 |
225+
| Ruby | Ruby 2.6 | 1st gen, 2nd gen | Ubuntu 18.04 | ruby26 |
226+
| PHP | PHP 8.4 | 2nd gen | Ubuntu 22.04 | php84 |
227+
| PHP | PHP 8.3 | 2nd gen | Ubuntu 22.04 | php83 |
228+
| PHP | PHP 8.2 | 1st gen, 2nd gen | Ubuntu 22.04 | php82 |
229+
| PHP | PHP 8.1 | 1st gen, 2nd gen | Ubuntu 18.04 | php81 |
230+
| PHP | PHP 7.4 | 1st gen, 2nd gen | Ubuntu 18.04 | php74 |
231+
| .NET Core | .NET Core 8 | 2nd gen | Ubuntu 22.04 | dotnet8 |
232+
| .NET Core | .NET Core 6 | 1st gen, 2nd gen | Ubuntu 22.04 | dotnet6 |
233+
| .NET Core | .NET Core 3 | 1st gen, 2nd gen | Ubuntu 18.04 | dotnet3 |
191234

192235
---
193236

194237
## 5. Summary Checklist
195238

196-
| Feature | Best Practice |
197-
| --- | --- |
198-
| **Base Image** | Use official, versioned, slim, or distroless images. |
199-
| **Layers** | Combine `RUN` commands; copy dependencies before source code. |
200-
| **Security** | Prefer not to run as `root`; never include secrets/ENV keys in Dockerfile. |
201-
| **Size** | Use **Multi-Stage builds** to strip out build-time bloat. |
202-
| **Cloud Run** | Use `runtime provided` + base images |
203-
| **Metadata** | Use `LABEL` to provide contact and versioning info. |
239+
| Feature | Best Practice |
240+
| -------------- | -------------------------------------------------------------------------- |
241+
| **Base Image** | Use official, versioned, slim, or distroless images. |
242+
| **Layers** | Combine `RUN` commands; copy dependencies before source code. |
243+
| **Security** | Prefer not to run as `root`; never include secrets/ENV keys in Dockerfile. |
244+
| **Size** | Use **Multi-Stage builds** to strip out build-time bloat. |
245+
| **Cloud Run** | Use `runtime provided` + base images |
246+
| **Metadata** | Use `LABEL` to provide contact and versioning info. |
204247

205-
### Sources:
248+
#### Sources:
206249

207250
https://cloud.google.com/run/docs/configuring/services/automatic-base-image-updates
208251
https://cloud.google.com/docs/buildpacks/base-images

skills/google-cicd-pipeline-design/SKILL.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ Your purpose in this stage is to operate as a collaborative consultant, guiding
2323

2424
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*).
2525
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, rollback required?, canary deployments required?).
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.
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.
27+
4. **Best Practice Cross-Reference**: Before proposing the draft, you MUST read any relevant `how_to_` files in the `references/` directory (e.g., `how_to_build_cloudbuild_yaml.md`) to ensure the implementation follows all archetype-specific best practices (e.g., linting, testing, image tagging, scanning, provenance).
28+
5. **Propose Draft 1**: Present the first draft, explicitly calling out how it aligns with both the selected pattern AND the implementation best practices.
29+
6. **Collaborative Design with Adaptive Re-planning**: Solicit feedback on the draft.
2830
* **For minor changes** (e.g., "add a linter"), update the plan and present a new draft.
2931
* **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.
32+
7. **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.
3133

3234
### Stage 2: Plan Implementation
3335

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## Example config for project setup
2+
### Python
3+
Python has shifted toward a more unified configuration approach recently, but you'll still see a mix of old and new.
4+
5+
* pyproject.toml: The modern standard for defining build systems and project metadata.
6+
* requirements.txt: A simple list of dependencies for pip.
7+
* setup.py / setup.cfg: Legacy files for packaging and distribution.
8+
* environment.yml: Used specifically for Conda virtual environments.
9+
* tox.ini: Configuration for automated testing across different Python versions.
10+
11+
### Java
12+
Java relies heavily on established build automation tools.
13+
14+
* pom.xml: The core configuration file for Maven projects.
15+
* build.gradle: The build script for Gradle (Groovy DSL).
16+
* settings.gradle: Defines project structure and module names for Gradle.
17+
* MANIFEST.MF: Defines extension and package-related data for JAR files.
18+
19+
### Go (Golang)
20+
Go keeps it minimal with a focus on reproducibility.
21+
22+
* go.mod: Defines the module's path and its dependency requirements.
23+
* go.sum: Contains the expected cryptographic hashes of the content of specific module versions.
24+
25+
### Ruby
26+
Ruby’s ecosystem is centered around "Gems."
27+
Gemfile: Describes the gem dependencies required to run the Ruby code.
28+
29+
* Gemfile.lock: Records the exact versions of gems that were installed.
30+
* .ruby-version: Specifies which version of the Ruby interpreter should be used.
31+
* Rakefile: Contains instructions for rake (Ruby's build program).
32+
33+
### Node.js
34+
The JavaScript/TypeScript ecosystem is highly standardized.
35+
36+
* package.json: Manifest file containing metadata, scripts, and dependencies.
37+
* package-lock.json (or yarn.lock / pnpm-lock.yaml): Ensures consistent installation across machines.=
38+
* tsconfig.json: Configuration for TypeScript compiler settings.
39+
* .npmrc: Configuration file for how npm should behave.
40+
41+
### Rust
42+
Rust uses a single, powerful tool called Cargo.
43+
44+
* Cargo.toml: The manifest file where you declare dependencies and metadata.
45+
* Cargo.lock: Created automatically to ensure reproducible builds by locking dependency versions.
46+
47+
### Kotlin
48+
Since Kotlin is often used in the JVM or Android ecosystem, it shares tools with Java but uses its own "flavor."
49+
* build.gradle.kts: Gradle build script using the Kotlin DSL.
50+
* settings.gradle.kts: Project-wide settings using Kotlin DSL.
51+
52+
### PHP
53+
Modern PHP development revolves around Composer.
54+
* composer.json: Defines dependencies, autoloading rules, and project metadata.
55+
* composer.lock: Locks the project to specific versions of dependencies.
56+
* php.ini: The main configuration file for the PHP interpreter itself.
57+
58+
### C / C++
59+
These languages are more fragmented, often depending on the build system chosen.
60+
61+
* Makefile: Used by the make build automation tool.
62+
* CMakeLists.txt: Configuration for CMake, the industry standard for cross-platform C/C++ builds.
63+
* conanfile.txt / conanfile.py: Used by the Conan package manager.
64+
* vcpkg.json: Configuration for the vcpkg dependency manager.
65+
66+
### Visual Studio (IDE Specific)
67+
While the languages above use the files listed, the Visual Studio IDE adds its own layer.
68+
* .sln: The Solution file; acts as a container for one or more projects.
69+
* .csproj / .vcxproj: Project files for C# and C++ respectively, containing build settings and file references.
70+
* .editorconfig: Defines coding styles (indentation, etc.) to be enforced by the editor.
71+
* App.config / Web.config: XML files for runtime configuration settings.
72+

0 commit comments

Comments
 (0)