An easy guide to automatically deploy your Google App Engine project with Gitlab CI

Continuous Integration is generally considered to be a good thing. Effective. Efficient. And makes your updates smooth and safe. But that’s none of the reasons for why I did this.

Dennis Alund
Aug 31, 2016 · 3 min read
No attribution needed, I single handedly crafted this collage

I did this simply because I got carried away. I’ve recently started to use Gitlab for my project hostings and I’ve probably spent a little bit of an unhealthy amount of time and joy playing around with it. One of the things that really had me excited was the built in continuous integration (CI).

I found that there were lots of good articles on how to get setup with automatic build for Node.js, Jekyll sites etc. But I was lacking a complete guide for deploying to Google App Engine (GAE). So here it goes.

GAE Developer Console

In this example, I am using the project id “ordinal-cacao-141615”. Replace that random name with whatever your project is called.

Then go to the “IAM & Admin” menu and create a service account that is having “Editor” role in your project. Name the account to something that makes sense for you. In this case, I only use the account specifically for the automatic deployment.

Update 2018–08-29

Pay attention to the key file. Create a JSON export, download it and store it temporarily. The content of the file looks something like below. You’ll need this for the Gitlab configuration. Don’t store it anywhere else! Delete the file on disk.

{
“type”: “service_account”,
“project_id”: “ordinal-cacao-141615”,
“private_key_id”: “02cca4dd86b0f210ae696564e5d41470b4255c89”,
“private_key”: “ — — -BEGIN PRIVATE KEY — — -\nVIIEvwIBADANBgkqhkiG9w0BAOEFAASCBKkwggSlAgEAAoIBAODK6pryUY0g5htF\n
...
TL;DR
...
yiK+aiA9tXVCk7APwTg+\nSzVPVi2007FzF0K9vZDTs9yvl+a8H57gkjL9RoVGNSHYuUUdEUExvyCHj57/fllq\nhvgEXOe1ARtEyxO4enSfXIVAYg==\n — — -END PRIVATE KEY — — -\n”,
“client_email”: “gitlab-ci@ordinal-cacao-141615.iam.gserviceaccount.com”,
“client_id”: “109498122000701669157”,
“auth_uri”: “https://accounts.google.com/o/oauth2/auth",
“token_uri”: “https://accounts.google.com/o/oauth2/token",
“auth_provider_x509_cert_url”: “https://www.googleapis.com/oauth2/v1/certs",
“client_x509_cert_url”: “https://www.googleapis.com/robot/v1/metadata/x509/gitlab-ci%40ordinal-cacao-141615.iam.gserviceaccount.com"
}

Update 2016–09–23

Gitlab

  1. PROJECT_ID_PRODUCTION: your GAE project id (e.g. ordinal-cacao-141615)
  2. DEPLOY_KEY_FILE_PRODUCTION: copy/paste the content of that JSON file.
Screenshot of the Gitlab project variables

Now, all you have to do is simply to copy/paste all the code from the gist below into your .gitlab-ci.yml file. It will just work! Please pay attention to the choice of debian distribution for the cloud SDK installation package. You should not need to make any changes to this, but if you have special needs, then you can have look at the Debian distribution list and make the choice which suites you better.

Now, simply submit that Gitlab CI configuration file and watch how your build instantly triggers and in a couple of minutes you’ll find your app automatically deployed to Google App Engine.

For extra credits, you should probably set up the configuration file with additional build rules, branch tags, staging environment etc. All those things that might apply to your specific project.

oddbit

The odd bit of technology

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store