Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
steps: | |
# 0. Docker Build | |
- name: gcr.io/cloud-builders/docker | |
args: | |
- build | |
- '--no-cache' | |
- '-t' | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- . | |
- '-f' |
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
# Update the settings.py file to use our newly created env variables. | |
import io | |
import os | |
import environ | |
import google.auth | |
from google.cloud import secretmanager | |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
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
gcloud secrets create django_app_settings --replication-policy automatic | |
gcloud secrets versions add django_app_settings --data-file .env.prod | |
# Get the PROJECTNUM from your GCP project dashboard | |
gcloud secrets add-iam-policy-binding django_app_settings \ | |
--member serviceAccount:<PROJECTNUM>@cloudbuild.gserviceaccount.com \ | |
--role roles/secretmanager.secretAccessor | |
gcloud secrets describe django_app_settings |
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
SECRET_KEY=<SECRET> | |
GS_BUCKET_NAME=django_dev_bucket | |
DATABASE_URL=postgres://djangodevdbadmin:<Password>@//cloudsql/django-cloudrun-project:us-east1:django-dev-db/djangodevdb |
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
PYTHON_ENV=dev | |
PORT=8000 | |
SECRET_KEY=<SECRET> | |
GS_BUCKET_NAME=django_dev_bucket | |
USE_CLOUD_SQL_AUTH_PROXY=True | |
GOOGLE_CLOUD_PROJECT=django-cloudrun-project | |
DATABASE_URL=postgres://djangodevdbadmin:<Password>@//cloudsql/django-cloudrun-project:us-east1:django-dev-db/djangodevdb |
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
version: '3.9' | |
services: | |
app: | |
container_name: django-app | |
build: | |
context: . | |
ports: | |
- 8000:8000 | |
volumes: |
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
FROM python:3.8-slim | |
COPY ./requirements.txt /requirements.txt | |
COPY ./src /app | |
WORKDIR /app | |
RUN python -m venv /py && \ | |
/py/bin/pip install --upgrade pip && \ | |
/py/bin/pip install -r /requirements.txt && \ | |
adduser --disabled-password --no-create-home django-user |
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
Django==3.2.6 | |
gunicorn==20.1.0 | |
psycopg2-binary==2.9.1 | |
django-environ==0.4.5 | |
google-cloud-secret-manager==2.6.0 | |
django-storages[google]==1.11.1 |
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
mkdir django-cloudrun && cd django-cloudrun | |
# move the creds.json file downloaded above to project root | |
mv ~/Downloads/creds.json . | |
# source repo for django | |
mkdir src | |
touch requirements.txt Dockerfile docker-compose.yml |
NewerOlder