CI/CD: Automate the deployment from Gitlab CI to Google App Engine.
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
with the following permission:
Create Key (JSON) upon completion of service account. This key would be needed in gitlab configuration.
CNFIGURE GITLAB CI/CD
Visit gitlab repo Settings → CI / CD → Variables → Expand:
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.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.
Make sure variables that need to be generated in
app.yaml file are prefixed with
app.template.yaml file in the root directory of the project.
.gitlab-ci.yaml in the root of the project and add following content:
MAGIC OF PUSH! 😲
You’re literally one push away from the magic to happen!
git push origin develop and that’s it!