Skip to content

Latest commit

 

History

History
139 lines (119 loc) · 3.93 KB

DEPLOYMENT_CHECKLIST.md

File metadata and controls

139 lines (119 loc) · 3.93 KB

Deployment Checklist - Cloud Run + Cloud Build

📋 Pre-Deployment: Project Files

1. Update requirements.txt

Add these lines:

psycopg2-binary>=2.9.9
gunicorn>=21.2.0
whitenoise>=6.6.0
python-dotenv>=1.0.0

2. Update notepad_project/settings.py

  • Set SECRET_KEY from environment: SECRET_KEY = config('SECRET_KEY', default='...')
  • Set DEBUG = config('DEBUG', default='False') == 'True'
  • Set ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='*').split(',')
  • Add STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  • Add 'whitenoise.middleware.WhiteNoiseMiddleware' after SecurityMiddleware
  • Add STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

3. Create Dockerfile (root directory)

FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y gcc postgresql-client && rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
WORKDIR /app/frontend
RUN npm install && npm run build
WORKDIR /app
RUN python manage.py collectstatic --noinput
ENV PORT=8080
EXPOSE 8080
CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 --timeout 0 notepad_project.wsgi:application

4. Create .dockerignore (root directory)

__pycache__ *.pyc *.pyo *.pyd .Python env/ venv/ .venv .env db.sqlite3 *.log .git node_modules frontend/node_modules .DS_Store

5. Create cloudbuild.yaml (root directory)

steps:
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/$PROJECT_ID/blocknotes:$SHORT_SHA', '.']
  - name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/$PROJECT_ID/blocknotes:$SHORT_SHA']
  - name: 'gcr.io/cloud-builders/gcloud'
    args:
      - 'run'
      - 'deploy'
      - 'blocknotes'
      - '--image'
      - 'gcr.io/$PROJECT_ID/blocknotes:$SHORT_SHA'
      - '--region'
      - 'us-central1'
      - '--platform'
      - 'managed'
      - '--allow-unauthenticated'
images:
  - 'gcr.io/$PROJECT_ID/blocknotes:$SHORT_SHA'

🔧 GCP Setup

1. Enable APIs

gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.com

2. Generate Django Secret Key

python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

3. Set Cloud Run Environment Variables

After first deployment, set these in Cloud Run console or via CLI:

  • SECRET_KEY - Generated Django secret key
  • DATABASE_URL - Your NeonDB connection string
  • BLOCKFROST_PROJECT_ID - Your Blockfrost API key
  • DEBUG - False
  • ALLOWED_HOSTS - Your Cloud Run URL (e.g., blocknotes-xxxxx.run.app)

🚀 Deployment

Option A: Manual Deploy (First Time)

gcloud run deploy blocknotes \
  --source . \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --set-env-vars SECRET_KEY=your-key,DATABASE_URL=your-db-url,BLOCKFROST_PROJECT_ID=your-id,DEBUG=False,ALLOWED_HOSTS=blocknotes-xxxxx.run.app

Option B: Cloud Build (CI/CD)

gcloud builds submit --config cloudbuild.yaml

📝 Post-Deployment

1. Run Migrations

gcloud run jobs create migrate-job \
  --image gcr.io/YOUR_PROJECT_ID/blocknotes:latest \
  --region us-central1 \
  --command python \
  --args manage.py,migrate \
  --set-env-vars SECRET_KEY=your-key,DATABASE_URL=your-db-url

gcloud run jobs execute migrate-job --region us-central1

2. Verify Deployment

  • Check Cloud Run service URL
  • Test static files loading
  • Verify database connection
  • Test API endpoints

✅ Quick Checklist

  • Updated requirements.txt
  • Updated settings.py with production config
  • Created Dockerfile
  • Created .dockerignore
  • Created cloudbuild.yaml
  • Generated new SECRET_KEY
  • Enabled GCP APIs
  • Deployed to Cloud Run
  • Set environment variables
  • Ran migrations
  • Tested application