Automatically deploy to Google App Engine with Gitlab CI

Yogesh Lakhotia
Nov 4, 2018 · 3 min read

Automate the boring task 😁 of deployment

gitlab ci + appengine

All we have to do is:

  1. Create a service account (I assume you know about it)
  2. Setup Gitlab CI
  3. Magic happens!

Creating a service account

Visit iam-admin page and create the service account with required permissions and create the key.

create service account to auto deploy
  1. App Engine Admin (This is required only if your using dispatch.yaml)
  2. App Engine Deployer and App Engine Service Account (Ignore this both,if you have given 1st permission)
  3. Create the JSON key (You will need this in Gitlab configuration)
create the JSON key

Now visit storage and go to buckets:

  1. staging.PROJECT-ID.appspot.com
  2. us.artifacts.PROJECT-ID.appspot.com (Create bucket with this name, if you don’t have one)

Now add your service account as a member of this buckets and give permissions Storage Object Creator and Storage Object Viewer.

adding service account as a member

One final step in Google Cloud Developer console.

Enable cloud-build api and you will need to have billing account linked to enable this api.

Setup Gitlab CI

We will deploy master branch to production and staging branch to staging.

Visit CI/CD settings of your gitlab project.

Let’s add two variable PROJECT_ID and SERVICE_ACCOUNT

SERVICE_ACCOUNT: Put the data of JSON key which we have downloaded while creating service account.

Now create the .gitlab-ci.yml file in your root folder.

code

Changes of master and staging branches will deploy to production and staging respectively.
I have used dispatch.yaml file, if you don’t have one just remove it from the script as well.

Push the .gitlab-ci.yml in your repo and your are done.

Source code: https://github.com/mryogesh/yogesh
In case if you want to see staging-app.yaml and dispatch.yaml file.

Magic 🎩

Now, git push automatically deploys your code to staging and production.

You have mastered your spell

Google Cloud - Community

A collection of technical articles published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Yogesh Lakhotia

Written by

Lead Engineer at QuickSell.co , Creator of Programming Hub

Google Cloud - Community

A collection of technical articles published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade