Add these lines:
psycopg2-binary>=2.9.9
gunicorn>=21.2.0
whitenoise>=6.6.0
python-dotenv>=1.0.0
- Set
SECRET_KEYfrom 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'afterSecurityMiddleware - Add
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
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__pycache__ *.pyc *.pyo *.pyd .Python env/ venv/ .venv .env db.sqlite3 *.log .git node_modules frontend/node_modules .DS_Store
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'gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.compython -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"After first deployment, set these in Cloud Run console or via CLI:
SECRET_KEY- Generated Django secret keyDATABASE_URL- Your NeonDB connection stringBLOCKFROST_PROJECT_ID- Your Blockfrost API keyDEBUG-FalseALLOWED_HOSTS- Your Cloud Run URL (e.g.,blocknotes-xxxxx.run.app)
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.appgcloud builds submit --config cloudbuild.yamlgcloud 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- Check Cloud Run service URL
- Test static files loading
- Verify database connection
- Test API endpoints
- Updated
requirements.txt - Updated
settings.pywith 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