Skip to content

Commit

Permalink
Create separate file for storage settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Oct 30, 2024
1 parent c53ebfa commit b880356
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ src/ARte/config/__pycache__/
*.sqlite3

build/
static/
media/
src/data/certbot/
docker/node_modules/
node_modules/
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
environment:
- USE_GUNICORN=True
- INSTALL_DEV=True
# command: sleep infinity
depends_on:
storage:
condition: service_started
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ skip_glob = "*/migrations/*.py,.venv/*"

[tool.flake8]
max-line-length = 200
exclude="**/migrations/"
exclude="**/migrations/, .venv/*"
49 changes: 2 additions & 47 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
56 changes: 56 additions & 0 deletions src/config/storage_settings.py
Original file line number Diff line number Diff line change
@@ -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",
},
}

0 comments on commit b880356

Please sign in to comment.