The simplest GitlabCI pipline for building and deploying a java microservice to Google Cloud Run
I keep spending some of my free time playing around with Slack and specifically Slack bots. More to come on future posts but for now I can tell that I am amazed by the quality of the Slack Java SDK called Bolt.
In this post I want to share a very simple Gitlab-CI pipeline that I use for building and deploying my toy slack bot. It has 4 stages and each stage 1 step (very simple).
- Deploy to Google Cloud (Run)
- Notify a private Slack channel
A side note regarding Gitlab-CI, I know my
ex-colleague Kostis has some valid points and concerns :) regarding other CI/CD
services out there, and the amount of integration they offer to
clouds like Google.
There is a case that this pipeline might change a bit in the future - since Gitlab is actually trying to simplify the integration between it's shared runner / CI and clouds like google. Service Account definition or integration in the pipeline might become simpler, and you might not be required to save JSON files in variables and then inject them on specific steps. For those interested on GitlabCI here is a list of issues that I am following their resolution
What you will need ( is also documented on the snippet):
- A Google cloud account, and a project (usually you get one preconfigured)
- Inside the project you need to enable Google Container Registry and Google Cloud Run Apis
- I have created 2 separate Service Accounts, one with the appropriate rights on the project, that will allow my pipeline to push to my private container registry, and the second one will allow the pipeline to make use of the gcloud cli and deploy/activate the new revisions of my Cloud Run application
- A Slack channel / Webhook, so that I send deployment status notifications - once my bot is deployed
- A bash script - on the root of the repo - more or less this one.