-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
74 lines (66 loc) · 1.95 KB
/
cloudbuild.yaml
File metadata and controls
74 lines (66 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Cloud Build configuration for deploying to Cloud Run
# This file automates the build and deployment process
steps:
# Step 1: Build the Docker image
- name: 'gcr.io/cloud-builders/docker'
id: 'build-image'
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$SHORT_SHA'
- '-f'
- 'Dockerfile'
- '.'
env:
- 'DOCKER_BUILDKIT=1'
# Step 2: Push the image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
id: 'push-image'
args:
- 'push'
- 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$SHORT_SHA'
waitFor: ['build-image']
# Step 3: Deploy to Cloud Run
- name: 'gcr.io/cloud-builders/gke-deploy'
id: 'deploy'
args:
- run
- --filename=.
- --image=gcr.io/$PROJECT_ID/$_SERVICE_NAME:$SHORT_SHA
- --location=${_REGION}
- --config=cloudbuild.yaml
env:
- 'CLOUDSDK_COMPUTE_REGION=${_REGION}'
waitFor: ['push-image']
# Step 4: Alternative: Use gcloud run deploy (recommended)
- name: 'gcr.io/cloud-builders/gcloud'
id: 'deploy-cloudrun'
args:
- 'run'
- 'deploy'
- '${_SERVICE_NAME}'
- '--image=gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$SHORT_SHA'
- '--platform=managed'
- '--region=${_REGION}'
- '--allow-unauthenticated'
- '--set-env-vars=CLOUD_RUN=true,ENVIRONMENT=production,DEBUG=false'
- '--memory=512Mi'
- '--cpu=1'
- '--timeout=120s'
- '--max-instances=100'
waitFor: ['push-image']
# Environment variables for substitution
substitutions:
_SERVICE_NAME: 'finance-dashboard'
_REGION: 'us-central1' # Change to your preferred region
_ENVIRONMENT: 'production'
# Build configuration
options:
machineType: 'N1_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
# Timeout for the entire build
timeout: '1800s'
# Images to be pushed to Container Registry
images:
- 'gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$SHORT_SHA'
- 'gcr.io/$PROJECT_ID/${_SERVICE_NAME}:latest'