You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-8Lines changed: 85 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,25 +155,102 @@ The service now runs on port 3000 and listens to requests
155
155
156
156
<palign="right">(<ahref="#readme-top">back to top</a>)</p>
157
157
158
+
## Google Cloud Platform (GCP) Infrastructure
159
+
160
+
We use [Cloud Run](https://cloud.google.com/run). It is a serverless platform for deploying containerized applications.
161
+
Besides Cloud Run, there are a few other supporting GCP services that we use, such as Cloud Build and Artifact Registry.
162
+
163
+
This section briefly describes how to setup the infrastructure resources using the `gcloud` CLI. For a production-ready setup,
164
+
we strongly recommend not using the CLI, but rather adopting an Infrastructure-as-Code approach, e.g. using [Terraform](https://www.terraform.io/). For the scope of this demo application, the CLI is sufficient.
165
+
166
+
### Infrastructure Setup Prerequisites
167
+
168
+
1. Open an account on GCP.
169
+
2. Create a new project on GCP.
170
+
3. Install the [gcloud CLI](https://cloud.google.com/sdk/docs/install).
171
+
4. Authenticate to GCP using: `gcloud auth login`.
As a rule of thumb, try to always keep the permissions as granular as possible and follow the least-privilege principle.
220
+
221
+
> Note: `<GCP_PROJECT_NUMBER>[email protected]` refers to the Compute Engine default service account.
222
+
> You can find the project number in the GCP console, or by running `gcloud projects describe <GCP_PROJECT_ID> --format='value(projectNumber)'`.
223
+
158
224
## CI/CD Pipelines Using GitHub Actions
159
225
160
-
## Authenticating to GCP using a Service Account Key
226
+
[GitHub Actions](https://github.com/features/actions) is a reasonably good CI/CD platform. We use it to build and deploy
227
+
this demo application to GCP. The [.github/workflows](.github/workflows) directory contains the definitions for the CI and CD pipelines.
228
+
229
+
### Authenticating to GCP using a Service Account Key
161
230
162
-
TODO: add details
231
+
We use the [auth](https://github.com/google-github-actions/auth/tree/v1/) action to authenticate to GCP using a service account key.
232
+
The service account key is a long-lived credential, thus it's not ideal from a security perspective.
233
+
For a production-ready setup, we strongly recommend using [Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation) instead.
163
234
164
-
### Populating Secrets
235
+
Generate the service account key using the following command:
165
236
166
-
The GCP service account key need to be stored as a secret in the GitHub repo. Alongside, we store a few other GCP-related
237
+
`gcloud iam service-accounts keys create gh-actions-key.json --iam-account gh-actions@<GCP_PROJECT_ID>.iam.gserviceaccount.com`
238
+
239
+
### Populating Secrets in GitHub
240
+
241
+
The GCP service account key needs to be stored as a secret in the GitHub repo. Alongside, we store a few other GCP-related
167
242
configuration values, such as project ID and region. Secrets can be accessed in the GitHub Actions workflows.
168
243
169
-
We advise using `gh` to create the secrets:
244
+
We advise using [gh](https://cli.github.com/) to create the secrets:
170
245
171
246
```shell
172
-
gh secret set GCP_PROJECT_ID --body '<gcp_project_id>'
173
-
gh secret set GCP_REGION --body '<gcp_region>'
174
-
gh secret set GCP_SA_KEY --body $(cat <gpc_service_account_key.json>| base64)
247
+
gh secret set GCP_PROJECT_ID --body '<GCP_PROJECT_ID>'
248
+
gh secret set GCP_REGION --body '<GCP_REGION>'# e.g. europe-west1
249
+
gh secret set GCP_SA_KEY --body $(cat <GPC_SERVICE_ACCOUNT_KEY.json>| base64)
175
250
```
176
251
252
+
The CI and CD workflows reference these secrets and will now be able to authenticate to GCP.
0 commit comments