GitLab + Google Cloud Container Registry

Art Krisada
2 min readAug 3, 2022

--

Note on using Gitlab to Build and store container images on Google. That’s because my current project is using Google Cloud Run.

I use simple node.js project for this note. You can use this code for sample.

This is a very good to read. You can follow this tutorial on creating server.js and Dockerfile.

server.js
Dockerfile

Then, You need Service Account to build on GCP.
You can follow this tutorial on Service account and how to add two variables in GitLab for your build.

GCP Variable setting on GitLab

Because I want to add CI_PIPELINE_IID to be a running number to tag on my build. I pass it and use substitutions in gcloud command.

.gitlab-ci.yml

The tricky part is cloudbuild.yaml. I build several times and fails because you have to add options logging or it will fail.

cloudbuild.yaml

I comment the deploy part out because I want to push image only. You can see that I pass _JOB_ID from .gitlab-ci.yml.

If everything is done. When you commit, it will start pipeline on GitLab and push the image to your Google Container Registry.

--

--

Art Krisada
Art Krisada

Written by Art Krisada

Never stop learning, because life never stop teaching.

No responses yet