(English) Gitlab CI/CD to deploy on GCloud

App engine logo

Désolé, cet article est seulement disponible en Anglais Américain.

So, sometimes I’m kinda lazy.
Considering the fact I needed to be connecting to different Gcloud env for different project, it was kinda a hassle to have to switch every time.
So I told myself… why not automatize it ?

So I search a bit and found this good example:
https://gist.github.com/troyharvey/bae82c86c27a3aa539dea83857ee9ecd

I searched a bit for a alpine image and then adapted for my needs like that

deploy:
  stage: deploy
  image: google/cloud-sdk:alpine
  only:
    - dev
  before_script:
    - echo $FIREBASE_KEY > ${CI_PROJECT_DIR}/key.json
    - echo $GCLOUD_SERVICE_KEY > /tmp/$CI_PIPELINE_ID.json
    - gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
    - gcloud config set project $CLOUDSDK_CORE_PROJECT
  script:
    - cd ${CI_PROJECT_DIR} 
    - gcloud app deploy
  allow_failure: false

With this, you’ll also need a configuration in your settings, CI/CD variables.
Something like that

Example CI/CD variable
This is the configuration example for deploy Gcloud app in CI/CD

Once done, Please do not forget to have at least your branch / tag as protected.
Else you’ll loose time like me 🙂