Skip to content

Commit

Permalink
Add the migrate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pcraig3 committed Nov 19, 2024
1 parent 96c2733 commit 6d52273
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/django_gcp_migrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "Migrate Django database in Cloud Run"

on:
workflow_call: # Allow this workflow to be called by other workflows
secrets:
DATABASE_URL:
required: true
GCP_CLOUD_CONNECTION_NAME:
required: true
GCP_IAM_SA_CREDENTIALS:
required: true

jobs:
migrate:
runs-on: "ubuntu-latest"
defaults:
run:
working-directory: ./bloom_nofos

permissions:
contents: "read"
id-token: "write"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Set up Python"
uses: actions/setup-python@v4
with:
python-version: "3.11.9"

- name: "Set up poetry"
uses: Gr1N/setup-poetry@v8

- uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}

- run: poetry --version

- name: Install poetry dependencies
run: poetry install

# Configure auth with Service Account with permissions to build and deploy on Google Cloud
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v2"
with:
credentials_json: ${{ secrets.GCP_IAM_SA_CREDENTIALS }}

# BEGIN - Django migration (if needed)
# sudo mv cloud-sql-proxy /usr/local/bin/
- name: "Install Cloud SQL Auth Proxy"
run: |
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.14.0/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy
./cloud-sql-proxy ${{ secrets.GCP_CLOUD_CONNECTION_NAME }} &
- name: Run migration
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: poetry run python manage.py migrate --plan
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ on:
- main

jobs:
run-ci:
ci:
uses: ./.github/workflows/django_ci.yml # Call the CI workflow
with:
branch: ${{ github.ref_name }}
secrets: inherit

migrate:
needs: ci
uses: ./.github/workflows/django_gcp_migrate.yml
secrets:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
GCP_CLOUD_CONNECTION_NAME: ${{ secrets.GCP_CLOUD_CONNECTION_NAME }}
GCP_IAM_SA_CREDENTIALS: ${{ secrets.GCP_IAM_SA_CREDENTIALS }}
3 changes: 3 additions & 0 deletions .github/workflows/old_django_gcp_migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
chmod +x cloud-sql-proxy
./cloud-sql-proxy ${{ secrets.GCP_CLOUD_CONNECTION_NAME }} &
- name: Install poetry dependencies
run: poetry install

- name: Run migration
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
Expand Down

0 comments on commit 6d52273

Please sign in to comment.