CI/CD with Github actions, Docker registry, GCP Cloud Run & NodeJS.
The purpose of this project is to demo how to automate in CI/CD the revision of a GCP Cloud Run Service on push to a Github Repo.
I used NodeJS and NPX Express Generator because it was quick & easy to get a simple web page which you can checkout here.
Use a Marketplace Github Action to bump the version on push to repo/trigger. In my case I just have it as push to main because this is a POC.
Github actions have a lot of helpers which allow us to manage/administer our CI/CD pipeline more easily.
In this demo I just grab the commit sha to add to the resp as POC.
Build the container image within the job.
1docker build -t primetimetran/gcp-cloud-run-example:latest . --platform linux/amd64
I included --platform linux/amd64
because it'll fail in Cloud Run if I don't at the time of writing. Note that you may need to remove it for the next step to succeed.
This is what you'd do locally before integrating the CI/CD to produce a revision within Github actions
1docker run -p=3000:3000 primetimetran/gcp-cloud-run-example:latest
We map host:container ports with the -p=3000:3000
. So our host port 3000 will point toward the container port's 3000. If it was -p=3005:3000
then it'd be host port 3005
to container port 3000
.
Share our local image to DockerHub's container registry so Cloud Run has access to it later.
1docker push primetimetran/gcp-cloud-run-example
To programmatically create/revise a GCP Cloud Run service create a file named service.yaml
and put in your project specific values. Read more.
1gcloud run services replace service.yaml
Update index file using a step in the jobs action which updates the response to include a url to the commit which triggered the workflow.