PHACDataHub / cloudrun-deployment-example

Working towards deploying Django apps to Google Cloud Run, using a Cloud SQL Postgres database and a Cloud Build GitHub Trigger.
0 stars 0 forks source link

Cloud Run Django Deployment Example

CI Workflow - Code check on Pull Request CI/CD Workflow - Deploy to Cloud Run on Push to Main

#

Note - Have moved to CPHO Phase 2 project to determine workflow and patterns. This project is on pause for the moment.

Working towards deploying Django apps to Google Cloud Run, using a Cloud SQL Postgres database and a Cloud Build GitHub Trigger for the continuous deployment. (Also exploring Github actions push deployment as well as AlloyDB as Cloud SQL alternative)

Currently running on

https://hello-world-vlfae7w5dq-nn.a.run.app/ (from GitHub Actions) and https://hello-world-three-vlfae7w5dq-nn.a.run.app (from Cloud Build trigger).

References:

Steps to Deployment

Ready Django App:

  1. Build app with tests
  2. Add requirements.txt to indicate dependencies
  3. Add a Dockerfile for containerization
  4. Add .dockerignore and .gitignore
  5. Modify settings.py (https://docs.djangoproject.com/en/4.2/intro/tutorial01/)
    • rename settings.py to basesettings.py
    • add settings.py file from here (and link) to include Google Cloud deployment instructions and secrets
    • change your app name in installed apps section of settings.py

Set up for GCP Deployment

  1. Authenticate
    gcloud auth application-default login
  2. Set project Variable
    gcloud config set project <your project>
  3. Enable APIs and set up service accounts and secrets for Artifact Registry, Cloud Build trigger, Cloud Run and Cloud SQL. Provision database.
    • Follow instructions in deploy/gcp-initialization.sh (step by step in terminal or command prompt, or just run). Note: variables need to be modified for your project.

Deploy

  1. Manually Cloud Build with no trigger (remove COMMIT_SHA):
    gcloud builds submit --config cloudbuild.yaml
  2. Otherwise, the project is automatically deployed each time there's a commit to main branch

TODO - waitress and TODO - ci.yaml github actions for pull request

After first deployment

Set Service URL

TO DO

Resources:

CICD options (TODO - add in testing and linting steps)

videos

Database

To look at:

AlloyDB Omni (containerized version - for testing)

Migrations:

Options:

gcloud run jobs update JOB_NAME --image IMAGE_URL

Logging: