-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
141 lines (132 loc) · 4.15 KB
/
cloudbuild.yaml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
steps:
# Build the container image.
- id: "build image"
name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_IMAGE_NAME}:$COMMIT_SHA",
".",
]
# Push the container image to Container Registry.
- id: "push image"
name: "gcr.io/cloud-builders/docker"
args:
[
"push",
"${_IMAGE_NAME}:$COMMIT_SHA"
]
# Apply the latest migrations.
- id: "apply migrations"
name: "gcr.io/google-appengine/exec-wrapper"
args:
[
"-i", "${_IMAGE_NAME}:$COMMIT_SHA",
"-s", "${_CLOUDSQL_INSTANCE_CONNECTION_NAME}",
"-e", "DJANGO_SETTINGS_MODULE=config.settings.production",
"-e", "GOOGLE_CLOUD_PROJECT=$PROJECT_ID",
"-e", "SETTINGS_NAME=${_SETTINGS_NAME}",
"--", "python", "/app/manage.py", "migrate",
]
# Create cache table
- id: "create cache table"
name: "gcr.io/google-appengine/exec-wrapper"
args:
[
"-i", "${_IMAGE_NAME}:$COMMIT_SHA",
"-s", "${_CLOUDSQL_INSTANCE_CONNECTION_NAME}",
"-e", "DJANGO_SETTINGS_MODULE=config.settings.production",
"-e", "GOOGLE_CLOUD_PROJECT=$PROJECT_ID",
"-e", "SETTINGS_NAME=${_SETTINGS_NAME}",
"--", "python", "/app/manage.py", "createcachetable",
]
# Collect static files
- id: "collect static files"
name: "gcr.io/google-appengine/exec-wrapper"
args:
[
"-i", "${_IMAGE_NAME}:$COMMIT_SHA",
"-s", "${_CLOUDSQL_INSTANCE_CONNECTION_NAME}",
"-e", "DJANGO_SETTINGS_MODULE=config.settings.production",
"-e", "GOOGLE_CLOUD_PROJECT=$PROJECT_ID",
"-e", "SETTINGS_NAME=${_SETTINGS_NAME}",
"--", "python", "/app/manage.py", "collectstatic", "--noinput"
]
# Compress static assets
- id: "compress static assets"
name: "gcr.io/google-appengine/exec-wrapper"
args:
[
"-i", "${_IMAGE_NAME}:$COMMIT_SHA",
"-s", "${_CLOUDSQL_INSTANCE_CONNECTION_NAME}",
"-e", "DJANGO_SETTINGS_MODULE=config.settings.production",
"-e", "GOOGLE_CLOUD_PROJECT=$PROJECT_ID",
"-e", "SETTINGS_NAME=${_SETTINGS_NAME}",
"--", "python", "/app/manage.py", "compress"
]
# Get credentials for the cluster.
- id: "get credentials for the cluster"
name: "gcr.io/cloud-builders/kubectl"
env:
- CLOUDSDK_CORE_PROJECT=$PROJECT_ID
- CLOUDSDK_COMPUTE_ZONE=${_GKE_COMPUTE_ZONE}
- CLOUDSDK_CONTAINER_CLUSTER=${_GKE_CLUSTER}
- KUBECONFIG=/workspace/.kube/config
args:
- cluster-info
# Update essential Variables and Deploy to cluster
- id: "update essential variables and start deployment to cluster"
dir: "deploy"
name: "gcr.io/$PROJECT_ID/helm:3.7.0"
env:
- KUBECONFIG=/workspace/.kube/config
args:
- upgrade
- --install
- ${_APP_NAME}-${_DEPLOYMENT_TYPE}
- --create-namespace
- --namespace=${_NAMESPACE}
- --atomic
- --debug
- --values
- values.yaml
- --set
- common.project_id=$PROJECT_ID
- --set
- common.cluster_name=${_GKE_CLUSTER}
- --set
- common.compute_zone=${_GKE_COMPUTE_ZONE}
- --set
- common.cluster_namespace=${_NAMESPACE}
- --set
- django.image.repository=${_IMAGE_NAME}
- --set
- django.image.tag=$COMMIT_SHA
- --set
- secret_manager.file_name=${_SETTINGS_NAME}
- --set
- django.env.django_settings_module=${_DJANGO_SETTINGS_MODULE}
- --set
- django.env.postgres_host=${_PG_BOUNCER_HOST}
- --set
- django.env.postgres_port=${_PG_BOUNCER_PORT}
- --set
- ingress.networking.domain=${_DOMAIN_NAME}
- --set
- ingress.networking.issuer.name=${_LETSENCRYPT_SERVER_TYPE}
- --set
- pg_bouncer.env.db_name=${_PG_NAME}
- --set
- pg_bouncer.env.db_user=${_PG_USER}
- --set
- pg_bouncer.env.db_password=${_PG_PASSWORD}
- --set
- cloud_sql.env.cloudsql_connection_instance=${_CLOUDSQL_INSTANCE_CONNECTION_NAME}
- --set
- common.service_account_key=${_IAM_SERVICE_ACCOUNT_KEY}
- .
images:
- "${_IMAGE_NAME}:$COMMIT_SHA"
timeout: 1200s
queueTtl: 3600s