Skip to content

Commit

Permalink
fix: variables
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Dec 5, 2024
1 parent 73dd5a0 commit 624a256
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 77 deletions.
10 changes: 2 additions & 8 deletions .deploy/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@
"APP_VERSION": "REPLACE_IN_PIPELINE",
"DJANGO_SETTINGS_MODULE": "REPLACE_IN_PIPELINE",
"DEBUG": "REPLACE_IN_PIPELINE",
"ENV": "REPLACE_IN_PIPELINE",
"SERVICE_PROTOCOL": "REPLACE_IN_PIPELINE",
"SERVICE_PORT": "REPLACE_IN_PIPELINE",
"MAIL_ENABLED": "REPLACE_IN_PIPELINE",
"STATIC_ROOT": "REPLACE_IN_PIPELINE",
"STATIC_URL": "REPLACE_IN_PIPELINE",
"AWS_STORAGE_BUCKET_NAME": "REPLACE_IN_PIPELINE",
"AWS_S3_ADDRESSING_STYLE": "${AWS_S3_ADDRESSING_STYLE}",
"AWS_S3_REGION_NAME": "${AWS_S3_REGION_NAME}",
"AWS_DEFAULT_ACL": "${AWS_DEFAULT_ACL}",
"AWS_LOCATION": "${AWS_LOCATION}",
"AWS_S3_CUSTOM_DOMAIN": "${AWS_S3_CUSTOM_DOMAIN}",
"STATICFILES_DIRS": "${STATICFILES_DIRS}"
"AWS_STORAGE_BUCKET_NAME": "REPLACE_IN_PIPELINE"
}
}
]
Expand Down
47 changes: 1 addition & 46 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,7 @@ def get_health_check(self, request):
details=[
HealthCheck.Detail(
name="settings_secrets_keys",
description=",".join(list(settings.secrets.keys())),
health="healthy",
),
HealthCheck.Detail(
name="STATIC_ROOT",
description=str(settings.STATIC_ROOT),
health="healthy",
),
HealthCheck.Detail(
name="STATIC_URL",
description=str(settings.STATIC_URL),
health="healthy",
),
HealthCheck.Detail(
name="AWS_STORAGE_BUCKET_NAME",
description=str(settings.AWS_STORAGE_BUCKET_NAME),
health="healthy",
),
HealthCheck.Detail(
name="AWS_S3_CUSTOM_DOMAIN",
description=str(settings.AWS_S3_CUSTOM_DOMAIN),
health="healthy",
),
HealthCheck.Detail(
name="AWS_LOCATION",
description=str(settings.AWS_LOCATION),
health="healthy",
),
HealthCheck.Detail(
name="AWS_DEFAULT_ACL",
description=str(settings.AWS_DEFAULT_ACL),
health="healthy",
),
HealthCheck.Detail(
name="AWS_S3_ADDRESSING_STYLE",
description=str(settings.AWS_S3_ADDRESSING_STYLE),
health="healthy",
),
HealthCheck.Detail(
name="AWS_S3_REGION_NAME",
description=str(settings.AWS_S3_REGION_NAME),
health="healthy",
),
HealthCheck.Detail(
name="STATICFILES_DIRS",
description=str(settings.STATICFILES_DIRS),
description=",".join(list(settings.SECRETS.keys())),
health="healthy",
),
],
Expand Down
43 changes: 20 additions & 23 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pathlib import Path


def set_up_settings(service_name: str):
def set_up_settings(service_base_dir: Path, service_name: str):
"""Set up the settings for the service.
*This needs to be called before importing the CFL settings!*
Expand All @@ -27,12 +27,13 @@ def set_up_settings(service_name: str):
from codeforlife import set_up_settings
# Must set up settings before importing them!
secrets = set_up_settings("example")
SECRETS = set_up_settings("example")
from codeforlife.settings import *
```
Args:
service_base_dir: The base directory of the service.
service_name: The name of the current service.
Returns:
Expand All @@ -59,6 +60,7 @@ def set_up_settings(service_name: str):
"You must set up the CFL settings before importing them."
)

os.environ["SERVICE_BASE_DIR"] = str(service_base_dir)
os.environ["SERVICE_NAME"] = service_name

os.environ.setdefault("ENV", "local")
Expand Down Expand Up @@ -107,7 +109,7 @@ def set_up_settings(service_name: str):
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent

secrets = set_up_settings(service_name="contributor")
SECRETS = set_up_settings(BASE_DIR, service_name="contributor")

# pylint: disable-next=wildcard-import,unused-wildcard-import,wrong-import-position
from codeforlife.settings import *
Expand Down Expand Up @@ -147,31 +149,26 @@ def set_up_settings(service_name: str):
# https://docs.djangoproject.com/en/3.2/howto/static-files/

# TODO: move to cfl package and create helper functions.
# STATIC_ROOT = get_static_root(BASE_DIR)
STATIC_ROOT = os.getenv("STATIC_ROOT", BASE_DIR / "static")
STATIC_ROOT = Path(os.environ["SERVICE_BASE_DIR"]) / "static"
STATIC_URL = os.getenv("STATIC_URL", "/static/")
STATICFILES_DIRS = (
os.environ["STATICFILES_DIRS"].split(",")
if os.getenv("STATICFILES_DIRS")
else []
)


# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")

AWS_S3_CUSTOM_DOMAIN = os.getenv("AWS_S3_CUSTOM_DOMAIN")
if AWS_S3_CUSTOM_DOMAIN == "":
AWS_S3_CUSTOM_DOMAIN = None
AWS_LOCATION = os.getenv("AWS_LOCATION", "")
AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL")
if AWS_DEFAULT_ACL == "":
AWS_DEFAULT_ACL = None
AWS_S3_ADDRESSING_STYLE = os.getenv("AWS_S3_ADDRESSING_STYLE")
if AWS_S3_ADDRESSING_STYLE == "":
AWS_S3_ADDRESSING_STYLE = None
AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME")
if AWS_S3_REGION_NAME == "":
AWS_S3_REGION_NAME = None
# AWS_S3_CUSTOM_DOMAIN = os.getenv("AWS_S3_CUSTOM_DOMAIN")
# if AWS_S3_CUSTOM_DOMAIN == "":
# AWS_S3_CUSTOM_DOMAIN = None
# AWS_LOCATION = os.getenv("AWS_LOCATION", "")
# AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL")
# if AWS_DEFAULT_ACL == "":
# AWS_DEFAULT_ACL = None
# AWS_S3_ADDRESSING_STYLE = os.getenv("AWS_S3_ADDRESSING_STYLE")
# if AWS_S3_ADDRESSING_STYLE == "":
# AWS_S3_ADDRESSING_STYLE = None
# AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME")
# if AWS_S3_REGION_NAME == "":
# AWS_S3_REGION_NAME = None
if AWS_STORAGE_BUCKET_NAME:
if "storages" not in INSTALLED_APPS:
INSTALLED_APPS.append("storages")
Expand Down

0 comments on commit 624a256

Please sign in to comment.