Automatically deploy to Google App Engine with Gitlab CI
Automate the boring task 😁 of deployment
All we have to do is:
- Create a service account (I assume you know about it)
- Setup Gitlab CI
- Magic happens!
Creating a service account
Visit iam-admin page and create the service account with required permissions and create the key.
- App Engine Admin (This is required only if your using dispatch.yaml)
- App Engine Deployer and App Engine Service Account (Ignore this both,if you have given 1st permission)
- Create the JSON key (You will need this in Gitlab configuration)
Now visit storage and go to buckets:
- 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.
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.
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.
Now, git push automatically deploys your code to staging and production.