Skip to content

Google App Engine Deployment #84

Google App Engine Deployment

Google App Engine Deployment #84

# Based on https://github.com/actions/starter-workflows/blob/main/ci/django.yml
name: Google App Engine Deployment
on:
# CI must pass on the master branch
workflow_run:
workflows: ["Continuous Integration"]
branches: [master]
types:
- completed
env:
PYTHON_TARGET: 3.9
# Django
DJANGO_SETTINGS_MODULE: tcf_core.settings.prod
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DEBUG: 0
# database
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
# social-auth-app-django
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY: ${{ secrets.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY }}
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET: ${{ secrets.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET }}
# elasticsearch
ES_PUBLIC_API_KEY: ${{ secrets.ES_PUBLIC_API_KEY }}
ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCH_ENDPOINT }}
ES_PRIVATE_API_KEY: ${{ secrets.ES_PRIVATE_API_KEY }}
# discord
DISCORD_URL_BUG: ${{ secrets.DISCORD_URL_BUG }}
DISCORD_URL_FEEDBACK: ${{ secrets.DISCORD_URL_FEEDBACK }}
# email for account verification
EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }}
EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }}
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
# A workaround because this workflow runs on the default branch (`dev`)
# because that's how `workflow_run` works at the moment
# https://github.community/t/workflow-run-not-working-as-expected/139342
- name: Checkout `master`
uses: actions/checkout@v2
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Set up Python ${{ env.PYTHON_TARGET }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_TARGET }}
- name: Install Python packages, excluding the unnecessary ones
run: |
python -m pip install --upgrade pip
sed -i '/\(coverage\|gunicorn\|django\-heroku\)/d' requirements.txt
pip install -r requirements.txt
- name: Migrations
run: |
python manage.py migrate
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Collect static files
run: python3 manage.py collectstatic --noinput --clear
- name: Substitute environment variables
run: envsubst < .config/app.yaml.template > app.yaml
- name: Deploy to Google App Engine
uses: google-github-actions/deploy-appengine@main
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
discord:
if: ${{ always() }}
needs: [deploy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Send a message to tCF Discord Server when deployment is finished
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_URL_CI }}
DEPLOY_RESULT: ${{ needs.deploy.result }}
run: |
bash ./scripts/notify-deployment-result.sh
shell: bash