Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Configure GCS SA key in Cloud Build env as well as in the settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
xSAVIKx committed May 5, 2021
1 parent 8dc3f7b commit 0254d75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ steps:
- "-c"
- |
printf "%s" "$$APP_ENGINE_ENVS" > ./env.sh
printf "%s" "$$DJANGO_STORAGES_GCS_KEY" > ./django-storages-gcs-key.json
chmod +x ./env.sh
secretEnv: ["APP_ENGINE_ENVS"]
secretEnv: ["APP_ENGINE_ENVS", "DJANGO_STORAGES_GCS_KEY"]
waitFor: ["-"]
- name: "python:3.8-slim-buster"
id: "install-deps"
Expand Down Expand Up @@ -62,3 +63,5 @@ availableSecrets:
secretManager:
- versionName: "projects/anth-ja77-local-contexts-8985/secrets/APP_ENGINE_ENVS/versions/latest"
env: "APP_ENGINE_ENVS"
- versionName: "projects/anth-ja77-local-contexts-8985/secrets/django-storages-gcs-key/versions/latest"
env: "DJANGO_STORAGES_GCS_KEY"
13 changes: 7 additions & 6 deletions localcontexts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
SITE_ADMIN_EMAIL = os.environ['SITE_ADMIN_EMAIL']
ADMINS = [(SITE_ADMIN_NAME, SITE_ADMIN_EMAIL)]


# Application definition
INSTALLED_APPS = [
'maintenance_mode',
Expand Down Expand Up @@ -107,12 +106,13 @@

WSGI_APPLICATION = 'localcontexts.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
if os.getenv('GAE_APPLICATION', None):
"""Setup Google App Engine-specific options."""

from google.oauth2 import service_account

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand All @@ -123,6 +123,9 @@
}
}
GS_BUCKET_NAME = os.environ.get('GCS_BUCKET', 'anth-ja77-local-contexts-8985.appspot.com')
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
os.path.join(BASE_DIR, 'django-storages-gcs-key.json')
)
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
MAINTENANCE_MODE_STATE_BACKEND = 'localcontexts.storage_backends.GCSDefaultStorageBackend'
else:
Expand All @@ -141,7 +144,6 @@
# if True the superuser will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_SUPERUSER = True


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

Expand All @@ -160,7 +162,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

Expand All @@ -176,6 +177,7 @@

# Messages
from django.contrib.messages import constants as messages

MESSAGE_TAGS = {
messages.ERROR: 'error-msg',
messages.SUCCESS: 'success-msg',
Expand All @@ -190,7 +192,6 @@
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

Expand All @@ -213,4 +214,4 @@
# Session expires after an hour of inactivity.
# Note: this will UPDATE the db on every request.
SESSION_COOKIE_AGE = 3600
SESSION_SAVE_EVERY_REQUEST = True
SESSION_SAVE_EVERY_REQUEST = True

0 comments on commit 0254d75

Please sign in to comment.