Add S3 storage configuration

pull/1/head
Patryk Jakuszew 2024-01-14 23:56:26 +01:00
parent 650fc34115
commit 1bbd28933f
4 changed files with 50 additions and 11 deletions

View File

@ -14,5 +14,4 @@ ADD . /code/
RUN python -m pip install gunicorn
RUN python manage.py collectstatic --no-input --clear
CMD bash -c "python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"
CMD bash -c "python manage.py collectstatic --no-input --clear && python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"

View File

@ -17,7 +17,7 @@ services:
web:
build: .
restart: always
command: bash -c "python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"
command: bash -c "python manage.py collectstatic --no-input --clear && python manage.py migrate && gunicorn --workers 1 --threads 4 -b 0.0.0.0:8000 --capture-output --error-logfile - --access-logfile - spejstore.wsgi:application"
volumes:
- .:/code
- /code/build_static

View File

@ -12,6 +12,7 @@ django-appconf==1.0.5
django-hstore==1.4.2
django-markdown2==0.3.1
django-select2==8.1.2
django-storages[s3]==1.14.2
# Django-tree
https://github.com/Palid/django-tree/archive/master.zip
djangorestframework==3.14.0

View File

@ -51,6 +51,7 @@ INSTALLED_APPS = [
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.postgres",
"storages", # django-storages s3boto support
"social_django",
"tree",
"django_select2",
@ -168,14 +169,52 @@ SOCIAL_AUTH_PIPELINE = (
"auth.pipeline.staff_me_up",
)
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
# Determines the storage type for Django static files and media.
FILE_STORAGE_TYPE = env("FILE_STORAGE_TYPE", "filesystem")
if FILE_STORAGE_TYPE == "filesystem":
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
elif FILE_STORAGE_TYPE == "s3":
S3_BUCKET_NAME = env("S3_BUCKET_NAME", "inventory")
S3_ENDPOINT_URL = env("S3_ENDPOINT_URL", "https://object.ceph-eu.hswaw.net")
S3_DOMAIN_NAME = env("S3_DOMAIN_NAME", "object.ceph-eu.hswaw.net")
S3_ACCESS_KEY = env("S3_ACCESS_KEY", "")
S3_SECRET_KEY = env("S3_SECRET_KEY", "=")
S3_STATIC_LOCATION = "static"
S3_MEDIA_LOCATION = "media"
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
"access_key": S3_ACCESS_KEY,
"secret_key": S3_SECRET_KEY,
"endpoint_url": S3_ENDPOINT_URL,
"bucket_name": S3_BUCKET_NAME,
"default_acl": "public-read",
"location": S3_MEDIA_LOCATION,
"custom_domain": f"{S3_DOMAIN_NAME}/{S3_BUCKET_NAME}",
"file_overwrite": False,
},
},
"staticfiles": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
"access_key": S3_ACCESS_KEY,
"secret_key": S3_SECRET_KEY,
"endpoint_url": S3_ENDPOINT_URL,
"bucket_name": S3_BUCKET_NAME,
"default_acl": "public-read",
"location": S3_STATIC_LOCATION,
"custom_domain": f"{S3_DOMAIN_NAME}/{S3_BUCKET_NAME}",
},
},
}
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/