Deploying Service to Google App Engine Using Github and Github Actions

Github Actions

Introduction

What the hell is Github Actions and Google App Engine?

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Google App Engine is a Platform as a Service and cloud computing platform for developing and hosting web applications in Google-managed data centers. Applications are sandboxed and run across multiple servers.

Ingredients

I’m assuming you’d already have your project up and running locally. Once it’s done you can manually deploy your project to app engine via gcloud app deploy.

Secrets

Go to your project’s secrets (https://github.com/<username>/<repository>/settings/secrets) and update the details you just gathered.

Note: For GCP_SA_KEY, you need to first convert the JSON to base64 and then put the base64 value in the secrets. You can get the base64 value by passing your json to base64 binary as base64 -i service-account-config.json.

Setup

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    
    - name: setup
      uses: zxyle/publish-gae-action@v2.3
      with:
        service_account_email: ${{ secrets.GCP_SA_EMAIL }}
        service_account_key: ${{ secrets.GCP_SA_KEY }}
        project_id: ${{ secrets.GCP_PROJECT_ID }}

    - name: deploy
      run: |
        gcloud auth activate-service-account ${{ secrets.GCP_SA_EMAIL }} --key-file=client-secret.json
        gcloud config set project ${{ secrets.GCP_PROJECT_ID }}
        gcloud -q app deploy app.yaml --promote