diff --git a/.deploy/service.json b/.deploy/service.json index 1bfea96..b8c628c 100644 --- a/.deploy/service.json +++ b/.deploy/service.json @@ -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" } } ] diff --git a/api/urls.py b/api/urls.py index dad28ed..cb05b45 100644 --- a/api/urls.py +++ b/api/urls.py @@ -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", ), ], diff --git a/settings.py b/settings.py index e991109..64acd06 100644 --- a/settings.py +++ b/settings.py @@ -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!* @@ -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: @@ -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") @@ -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 * @@ -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")