CI/CD: Automate the deployment from Gitlab CI to Google App Engine.

Abu Shumon
3 min readNov 13, 2019

--

Everyone wants magic to happen just like that 😄 but it’s not always as simple as expect of 💁. Let’s see how the magic of automated deployment happens 😉.

Coming straight to the point — this article talks about deploying a react-app from gitlab to google app engine.

Assuming you have a google cloud project and app engine setup already, and a gitlab CI is synced up with a gitlab runner. If not follow this link for google project, this link for app app engine, and this link for configuring gitlab runner .

We would cover the following:

  • Service account creation.
  • Configure Gitlab CI/CD.
  • Magic of Push!

SERVICE ACCOUNT CREATION

Go to IAM & admin.

Create a service account for gitlab deployment

Creating a service account.

with the following permission:

Roles service account needs to deploy to app engine.
Roles for service account

Create Key (JSON) upon completion of service account. This key would be needed in gitlab configuration.

Create JSON key.

CNFIGURE GITLAB CI/CD

Visit gitlab repo Settings → CI / CD → Variables → Expand:

Gitlab environment variables

PROJECT_ID: id of google cloud project
SERVICE_ACCOUNT: copy content of JSON key download for this service account and paste it here.

Additional variables can be added if sensitive info for example dbpassword, appKey, appSecrect etc needs to be passed in the build environment and eventually to the deployed app.

Following step is additional if you like to generate app.yaml file from app.template.yaml as app.yaml doesn’t support substituting variables from gitlab environment variables.

But be hold! Even though app.yaml doesn’t support it doesn’t mean we can’t do it 😎! It can be achieved using this beautiful library called gae-ayaml-env. Add environment variables in gitlab CI like it’s done in previous step.

Gitlab environment variables

Make sure variables that need to be generated in app.yaml file are prefixed with APP_

Create a app.template.yaml file in the root directory of the project.

app.template.yaml

Create a .gitlab-ci.yaml in the root of the project and add following content:

.gitlab-ci.yml

MAGIC OF PUSH! 😲

You’re literally one push away from the magic to happen!

git push origin develop and that’s it!

Magic!!!

--

--