Skip to content

Conversation

@aaronjae22
Copy link
Collaborator

@aaronjae22 aaronjae22 commented Oct 28, 2025

This PR implements complete CI/CD pipeline for automated deployment to Google Cloud Run staging and production environment, with refactored Django settings following organizational patterns.

Changes

Settings Refactoring

  • base.py: Common settings with SQLite default, development-friendly
  • production.py: GCS storage, Cloud SQL, SMTP email, ALLOWED_SEED_COMMAND=False
  • staging.py: Inherits from production, staging-specific overrides
  • development.py: Simplified, inherits SQLite from base

Updated dependencies in requirements.txt and created deployment files

  • Dockerfile
  • .dockerignore
  • .gcloudignore

Management Command

  • create_gcp_cors_config.py that generates CORS configuration for GCS bucket from Django settings

CI/CD Workflow (.github/workflows/ci-cd.yml)

test-python job:

  • PostgreSQL 17 service container
  • Runs pytest with testbed.settings.ci
  • No seeding (fast, focused testing for now. Seeding during ci/cd will be added again as its own feature later on but need to do some thinking about how to implement it)

deploy job:

  • Runs on push to main (auto-deploy to Staging)
  • Manual trigger with environment selection (Staging/Production)
  • deployment process:
    1. Setup and dependency installation
    2. GCP authentication
    3. URL-encode database credentials (handles special characters)
    4. Cloud SQL Auth Proxy for migrations
    5. Run Django migrations
    6. Compile SCSS
    7. Collect static files to GCS
    8. Configure bucket CORS
    9. Deploy to Cloud Run via --source flag

Deployment Flow

Push to main → Tests pass → Deploy to Staging (automatic)
Manual trigger → Choose environment → Deploy to selected environment

Configuration for Each Environment

Required GitHub Environment Variables

  • DJANGO_SETTINGS_MODULE: Settings module path
  • GCP_PROJECT_ID: Google Cloud project ID
  • CLOUD_RUN_SERVICE_NAME: Cloud Run service name
  • SERVICE_ACCOUNT_NAME: Deployment service account
  • DATABASE_NAME: PostgreSQL database name
  • ARTIFACT_REGISTRY: Container image name

Required GitHub Environment Secrets

  • GCP_CREDENTIALS: Service account JSON credentials
  • CLOUD_SQL_ICN: Cloud SQL instance connection name
  • POSTGRES_CREDENTIALS: Database credentials (username:password)
  • DJANGO_SECRET_KEY: Django secret key

Shared Repository Secret

  • EMAIL_HOST_PASSWORD: SMTP password (Gmail app password)

Close #206
Close #207
Close #209
Close #203

@aaronjae22 aaronjae22 requested a review from lisad October 28, 2025 08:24
@aaronjae22 aaronjae22 self-assigned this Oct 28, 2025
@aaronjae22 aaronjae22 added deploy Cloud Run related ci/cd CI/CD pipeline related Refactor Codebase refactoring labels Oct 28, 2025
@aaronjae22 aaronjae22 merged commit 35d4266 into main Oct 28, 2025
2 checks passed
@aaronjae22 aaronjae22 deleted the feat/gcp-cloud-run-deployment branch October 29, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI/CD pipeline related deploy Cloud Run related Refactor Codebase refactoring

Projects

None yet

1 participant