cloud-build-helper
Cloud Build Helper
Quick Start
Configure Cloud Build pipelines with proper caching and optimization for fast, efficient builds.
Instructions
Step 1: Create cloudbuild.yaml
steps:
# Build step
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA', '.']
# Push to registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA']
# Deploy
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'myapp'
- '--image=gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA'
- '--region=us-central1'
images:
- 'gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA'
options:
machineType: 'N1_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
Step 2: Configure caching
steps:
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
docker pull gcr.io/$PROJECT_ID/myapp:latest || exit 0
docker build \
--cache-from gcr.io/$PROJECT_ID/myapp:latest \
-t gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA \
-t gcr.io/$PROJECT_ID/myapp:latest \
.
docker push gcr.io/$PROJECT_ID/myapp:$COMMIT_SHA
docker push gcr.io/$PROJECT_ID/myapp:latest
Step 3: Set up build triggers
# Create trigger from GitHub
gcloud builds triggers create github \
--repo-name=my-repo \
--repo-owner=my-org \
--branch-pattern="^main$" \
--build-config=cloudbuild.yaml
# Create trigger with substitutions
gcloud builds triggers create github \
--repo-name=my-repo \
--repo-owner=my-org \
--branch-pattern="^main$" \
--build-config=cloudbuild.yaml \
--substitutions=_ENV=production,_REGION=us-central1
Step 4: Optimize build performance
Use parallel steps:
steps:
# These run in parallel
- name: 'gcr.io/cloud-builders/npm'
id: 'install-frontend'
args: ['install']
dir: 'frontend'
waitFor: ['-']
- name: 'gcr.io/cloud-builders/npm'
id: 'install-backend'
args: ['install']
dir: 'backend'
waitFor: ['-']
# This waits for both
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
waitFor: ['install-frontend', 'install-backend']
Best Practices
- Use caching to speed up builds
- Implement parallel build steps
- Use appropriate machine types
- Store artifacts in Cloud Storage
- Use substitution variables
- Implement proper error handling
- Monitor build performance
- Use Cloud Build's built-in builders when possible
Advanced
For detailed information, see:
- Build Steps - Build step configuration and patterns
- Caching - Caching strategies for faster builds
- Triggers - Build trigger configuration
More from armanzeroeight/fastagent-plugins
gcp-cost-optimizer
Analyzes GCP costs and provides optimization recommendations including committed use discounts, rightsizing, and unused resources. Use when optimizing GCP spending or analyzing GCP costs.
15kubernetes-best-practices
Provides production-ready Kubernetes manifest guidance including resource management, security, high availability, and configuration best practices. This skill should be used when working with Kubernetes YAML files, deployments, pods, services, or when users mention k8s, container orchestration, or cloud-native applications.
11schema-designer
Design database schemas with proper normalization, relationships, constraints, and indexes. Use when creating database tables, modeling data relationships, or designing database structure.
11api-documentation-generator
Generate OpenAPI/Swagger specifications and API documentation from code or design. Use when creating API docs, generating OpenAPI specs, or documenting REST APIs.
9goroutine-patterns
Implement Go concurrency patterns using goroutines, channels, and synchronization primitives. Use when building concurrent systems, implementing parallelism, or managing goroutine lifecycles. Trigger words include "goroutine", "channel", "concurrent", "parallel", "sync", "context".
9inventory-manager
Organizes Ansible inventory files, manages host groups, and configures dynamic inventory. Use when organizing Ansible inventory, managing host groups, or setting up dynamic inventory sources.
9