This project demonstrates how to trigger CloudRun using an Eventarc rule from Cloud Storage.
Before using this project, you must ensure the following pre-requisites are fulfilled:
- Terraform is installed on the machine where Terraform is executed.
- The Service Account you execute with has the right permissions
- The necessary APIs are active on the project
In order to execute this project you must have:
-
A Service Account with roles to deploy GCP resources using Terraform.
- Documentation on Service Accounts here
- Roles needed:
- roles/eventarc.admin
- roles/run.admin
- roles/iam.securityAdmin
- roles/iam.securityReviewer
- roles/iam.serviceAccountAdmin
- roles/iam.serviceAccountUser
- roles/storage.admin
-
A Service Account Key associated with the Service Account from #1. Then update
credentials
underterraform/main.tf
to point to this json file.
To build the CloudRun container:
-
Build a container from your function using the Functions buildpacks:
cd src && npm i
pack build \
--builder gcr.io/buildpacks/builder:v1 \
--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
--env GOOGLE_FUNCTION_TARGET=imageResize \
gcr.io/PROJECT_ID/IMAGE_NAME
Where PROJECT_ID
is your GCP project ID and IMAGE_NAME
is the name of your image.
- Upload to your Google Cloud project image repository using gcloud credential helper
docker push gcr.io/PROJECT_ID/IMAGE_NAME
Where PROJECT_ID
is your GCP project ID and IMAGE_NAME
is the name of your image.
- Update
image
variable interraform/variables.tf
with this image name