diff --git a/.gitignore b/.gitignore index 865d2101..013baf29 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ src/ARte/config/__pycache__/ *.sqlite3 build/ +static/ +media/ src/data/certbot/ docker/node_modules/ node_modules/ diff --git a/docker-compose.yml b/docker-compose.yml index 40ae995e..9ec15ad0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,6 @@ services: environment: - USE_GUNICORN=True - INSTALL_DEV=True - # command: sleep infinity depends_on: storage: condition: service_started diff --git a/pyproject.toml b/pyproject.toml index 059b803d..721a020f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,4 +63,4 @@ skip_glob = "*/migrations/*.py,.venv/*" [tool.flake8] max-line-length = 200 -exclude="**/migrations/" \ No newline at end of file +exclude="**/migrations/, .venv/*" \ No newline at end of file diff --git a/src/config/settings.py b/src/config/settings.py index 2112a64e..38c7dd26 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -9,6 +9,8 @@ from django.utils.translation import gettext_lazy as _ from sentry_sdk.integrations.django import DjangoIntegration +from .storage_settings import * # noqa F403 F401 + ROOT_DIR = environ.Path("/jandig/") BASE_DIR = "/jandig/src" @@ -184,53 +186,6 @@ def debug(request): USE_TZ = True - -# AWS credentials -AWS_S3_OBJECT_PARAMETERS = { - "CacheControl": "max-age=86400", -} -AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID", "") -AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", "") -AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME", "") -AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME", "us-east-2") -AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL", None) -AWS_STATIC_LOCATION = os.getenv("AWS_STATIC_LOCATION", "static") -AWS_MEDIA_LOCATION = os.getenv("AWS_MEDIA_LOCATION", "media") -USE_MINIO = os.getenv("USE_MINIO", "false").lower() in ("true", "True", "1") -if USE_MINIO: - AWS_S3_ENDPOINT_URL = os.getenv("MINIO_S3_ENDPOINT_URL", "http://storage:9000") - AWS_S3_CUSTOM_DOMAIN = f"localhost:9000/{AWS_STORAGE_BUCKET_NAME}" - AWS_S3_USE_SSL = False - AWS_S3_SECURE_URLS = False - AWS_S3_URL_PROTOCOL = "http:" - -else: - AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com" - AWS_S3_URL_PROTOCOL = "https:" - -# Static configuration -# Add your own apps statics in this list -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, "core", "static"), - os.path.join(BASE_DIR, "users", "static"), - os.path.join(BASE_DIR, "blog", "static"), -] - -STATICFILES_FINDERS = [ - "django.contrib.staticfiles.finders.AppDirectoriesFinder", -] - -AWS_PUBLIC_MEDIA_LOCATION = "media/public" - -# Storages -STORAGES = { - "default": { - "BACKEND": "config.storage_backends.PublicMediaStorage", - }, - "staticfiles": { - "BACKEND": "config.storage_backends.StaticStorage", - }, -} # LOGIN / LOGOUT LOGIN_URL = "login" LOGIN_REDIRECT_URL = "home" diff --git a/src/config/storage_settings.py b/src/config/storage_settings.py new file mode 100644 index 00000000..8dfc5e5d --- /dev/null +++ b/src/config/storage_settings.py @@ -0,0 +1,56 @@ +import os + +AWS_S3_OBJECT_PARAMETERS = { + "CacheControl": "max-age=86400", +} +AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID", "") +AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", "") +AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME", "") +AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME", "us-east-2") +AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL", None) +AWS_STATIC_LOCATION = os.getenv("AWS_STATIC_LOCATION", "static") +AWS_MEDIA_LOCATION = os.getenv("AWS_MEDIA_LOCATION", "media") + +if os.getenv("USE_GUNICORN", "true").lower() in ("false", "0"): + USE_MINIO = False + STATIC_URL = "/static/" + MEDIA_URL = "/media/" + STATIC_ROOT = os.path.join("/jandig", "static") + MEDIA_ROOT = os.path.join("/jandig", "media") +else: + USE_MINIO = os.getenv("USE_MINIO", False) + +if USE_MINIO: + AWS_S3_ENDPOINT_URL = os.getenv("MINIO_S3_ENDPOINT_URL", "http://storage:9000") + AWS_S3_CUSTOM_DOMAIN = f"localhost:9000/{AWS_STORAGE_BUCKET_NAME}" + AWS_S3_USE_SSL = False + AWS_S3_SECURE_URLS = False + AWS_S3_URL_PROTOCOL = "http:" + +else: + AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com" + AWS_S3_URL_PROTOCOL = "https:" + +# Static configuration +# Add your own apps statics in this list +STATICFILES_DIRS = [ + os.path.join("/jandig/src", "core", "static"), + os.path.join("/jandig/src", "users", "static"), + os.path.join("/jandig/src", "blog", "static"), +] + +STATICFILES_FINDERS = [ + "django.contrib.staticfiles.finders.AppDirectoriesFinder", +] + +AWS_PUBLIC_MEDIA_LOCATION = "media/public" + +if os.getenv("USE_GUNICORN", "true").lower() in ("true", "1"): + STORAGES = { + "default": { + "BACKEND": "config.storage_backends.PublicMediaStorage", + }, + "staticfiles": { + "BACKEND": "config.storage_backends.StaticStorage", + }, + }