Skip to content

Commit

Permalink
Merge pull request #969 from ImageMarkup/prod-composed-config-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna authored Sep 30, 2024
2 parents 20e31f6 + 71bb8c5 commit 3b0eb95
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion isic/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _oauth2_pkce_required(client_id):
# with both methods.
ISIC_USE_ELASTICSEARCH_COUNTS = False

ISIC_ELASTICSEARCH_URI = os.environ["DJANGO_ISIC_ELASTICSEARCH_URI"]
ISIC_ELASTICSEARCH_URI = os.environ.get("DJANGO_ISIC_ELASTICSEARCH_URI")
ISIC_ELASTICSEARCH_INDEX = "isic"
ISIC_GUI_URL = "https://www.isic-archive.com/"
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = ISIC_GUI_URL
Expand Down
8 changes: 8 additions & 0 deletions isic/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

import dj_database_url

from ._docker import _AlwaysContains, _is_docker
from .base import * # noqa: F403

Expand All @@ -12,6 +14,12 @@
r"^https?://127\.0\.0\.1:\d+$",
]

DATABASES = {
"default": dj_database_url.config(
default=os.environ["DJANGO_DATABASE_URL"], conn_max_age=600, conn_health_checks=False
)
}

# When in Docker, the bridge network sends requests from the host machine exclusively via a
# dedicated IP address. Since there's no way to determine the real origin address,
# consider any IP address (though actually this will only be the single dedicated address) to
Expand Down
34 changes: 22 additions & 12 deletions isic/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import os

from botocore.config import Config
import dj_email_url
from django_cache_url import BACKENDS
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.pure_eval import PureEvalIntegration

from ._utils import _get_sentry_performance_sample_rate, string_to_list
from ._utils import _get_sentry_performance_sample_rate, string_to_bool, string_to_list
from .base import * # noqa: F403

# This is an unfortunate monkeypatching of django_cache_url to support an old version
Expand All @@ -18,12 +19,13 @@
BACKENDS["redis"] = BACKENDS["rediss"] = "django_redis.cache.RedisCache"


SECRET_KEY = os.environ["SECRET_KEY"]
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]

CELERY_BROKER_URL = os.environ["CLOUDAMQP_URL"]
CELERY_TASK_ACKS_LATE = True
CELERY_WORKER_CONCURRENCY = None

ALLOWED_HOSTS = string_to_list(os.environ["ALLOWED_HOSTS"])
ALLOWED_HOSTS = string_to_list(os.environ["DJANGO_ALLOWED_HOSTS"])

# Enable HSTS
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365 # 1 year
Expand All @@ -46,15 +48,15 @@

DATABASES = {
"default": dj_database_url.config( # noqa: F405
default=os.environ["DJANGO_DATABASE_URL"],
default=os.environ["DATABASE_URL"],
conn_max_age=600,
conn_health_checks=True,
ssl_require=True,
)
}

# Email
email_config = dj_email_url.config() # noqa: F405
email_config = dj_email_url.config(env="DJANGO_EMAIL_URL")
EMAIL_FILE_PATH = email_config["EMAIL_FILE_PATH"]
EMAIL_HOST_USER = email_config["EMAIL_HOST_USER"]
EMAIL_HOST_PASSWORD = email_config["EMAIL_HOST_PASSWORD"]
Expand All @@ -74,8 +76,8 @@
# If a "dsn" is not explicitly passed, sentry_sdk will attempt to find the DSN in
# the SENTRY_DSN environment variable; however, by pulling it from an explicit
# setting, it can be overridden by downstream project settings.
# dsn=settings.SENTRY_DSN,
# environment=settings.SENTRY_ENVIRONMENT,
dsn=os.environ["DJANGO_SENTRY_DSN"],
environment=os.environ["DJANGO_SENTRY_ENVIRONMENT"],
# release=settings.SENTRY_RELEASE,
integrations=[
LoggingIntegration(level=logging.INFO, event_level=logging.WARNING),
Expand Down Expand Up @@ -126,19 +128,19 @@

SENTRY_TRACES_SAMPLE_RATE = 0.01 # sample 1% of requests for performance monitoring

ZIP_DOWNLOAD_SERVICE_URL = os.environ["ZIP_DOWNLOAD_SERVICE_URL"]
ZIP_DOWNLOAD_BASIC_AUTH_TOKEN = os.environ["ZIP_DOWNLOAD_BASIC_AUTH_TOKEN"]
ZIP_DOWNLOAD_SERVICE_URL = os.environ["DJANGO_ZIP_DOWNLOAD_SERVICE_URL"]
ZIP_DOWNLOAD_BASIC_AUTH_TOKEN = os.environ["DJANGO_ZIP_DOWNLOAD_BASIC_AUTH_TOKEN"]
ZIP_DOWNLOAD_WILDCARD_URLS = True


STORAGES["default"]["BACKEND"] = "isic.core.storages.s3.CacheableCloudFrontStorage" # noqa: F405
STORAGES["default"] = {"BACKEND": "isic.core.storages.s3.CacheableCloudFrontStorage"} # noqa: F405


# This exact environ_name is important, as direct use of Boto will also use it
AWS_S3_REGION_NAME = os.environ["AWS_DEFAULT_REGION"]
AWS_S3_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"]
AWS_S3_SECRET_ACCESS_KEY = os.environ["AWS_SECRET_ACCESS_KEY"]
AWS_STORAGE_BUCKET_NAME = os.environ["STORAGE_BUCKET_NAME"]
AWS_STORAGE_BUCKET_NAME = os.environ["DJANGO_STORAGE_BUCKET_NAME"]

# It's critical to use the v4 signature;
# it isn't the upstream default only for backwards compatability reasons.
Expand All @@ -155,4 +157,12 @@
signature_version=AWS_S3_SIGNATURE_VERSION,
)

ISIC_GOOGLE_API_JSON_KEY = os.environ["ISIC_GOOGLE_API_JSON_KEY"]
ISIC_GOOGLE_API_JSON_KEY = os.environ.get("ISIC_GOOGLE_API_JSON_KEY")

ISIC_NOINDEX = string_to_bool(os.environ["DJANGO_ISIC_NOINDEX"])
ISIC_OAUTH_ALLOW_REGEX_REDIRECT_URIS = string_to_bool(
os.environ["DJANGO_ISIC_OAUTH_ALLOW_REGEX_REDIRECT_URIS"]
)
ISIC_SANDBOX_BANNER = string_to_bool(os.environ["DJANGO_ISIC_SANDBOX_BANNER"])

CDN_LOG_BUCKET = os.environ["DJANGO_CDN_LOG_BUCKET"]
8 changes: 8 additions & 0 deletions isic/settings/testing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import os

import dj_database_url

from .base import * # noqa: F403

SECRET_KEY = "testingsecret" # noqa: S105

DATABASES = {
"default": dj_database_url.config(
default=os.environ["DJANGO_DATABASE_URL"], conn_max_age=600, conn_health_checks=False
)
}

# Testing will add 'testserver' to ALLOWED_HOSTS
ALLOWED_HOSTS: list[str] = []

Expand Down
4 changes: 3 additions & 1 deletion isic/settings/upstream_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
DATABASES = {
"default": dj_database_url.config(
default=os.environ["DJANGO_DATABASE_URL"], conn_max_age=600, conn_health_checks=False
default=os.environ.get("DATABASE_URL", os.environ.get("DJANGO_DATABASE_URL")),
conn_max_age=600,
conn_health_checks=False,
)
}

Expand Down

0 comments on commit 3b0eb95

Please sign in to comment.