Created
January 17, 2022 08:26
-
-
Save paulonteri/be8e57d17e463a340399ad150b617323 to your computer and use it in GitHub Desktop.
Deploy Django to Cloud Run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Backend Production | |
on: | |
push: | |
branches: | |
- production | |
paths: | |
- "backend/**" | |
workflow_dispatch: | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./backend | |
env: | |
DB_HOST: ${{ secrets.DB_HOST }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
DB_USER: ${{ secrets.DB_USER }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
DEBUG: True | |
TESTING: True | |
DJANGO_SETTINGS_MODULE: "backend.settings.production" | |
SECRET_KEY: "paul" | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.7 | |
- name: Pip Cache | |
uses: actions/cache@v2 | |
with: | |
id: python-cache | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install Python dependencies | |
run: pip install -r requirements.txt | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@master | |
with: | |
project_id: ${{ secrets.GCLOUD_PROJECT }} | |
service_account_key: ${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY_BASE64 }} | |
export_default_credentials: true | |
- name: Authorize Docker push | |
run: gcloud auth configure-docker | |
- name: Build and Push Container | |
run: |- | |
docker build -t gcr.io/${{ env.GCLOUD_PROJECT }}/${{ secrets.GCLOUD_RUN_SERVICE }}/${{ github.sha }} . | |
docker push gcr.io/${{ env.GCLOUD_PROJECT }}/${{ secrets.GCLOUD_RUN_SERVICE }}/${{ github.sha }} | |
- name: Django migrate | |
run: python manage.py migrate --noinput | |
- name: Deploy to Cloud Run | |
run: |- | |
gcloud run deploy ${{ secrets.GCLOUD_RUN_SERVICE }} --region ${{ secrets.GCLOUD_REGION }} --image gcr.io/${{ env.GCLOUD_PROJECT }}/${{ secrets.GCLOUD_RUN_SERVICE }}/${{ github.sha }} --platform "managed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment