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 -m pip install gunicorn
RUN python manage.py collectstatic --no-input --clear 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"
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"

View File

@ -17,7 +17,7 @@ services:
web: web:
build: . build: .
restart: always 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: volumes:
- .:/code - .:/code
- /code/build_static - /code/build_static

View File

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

View File

@ -51,6 +51,7 @@ INSTALLED_APPS = [
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"django.contrib.postgres", "django.contrib.postgres",
"storages", # django-storages s3boto support
"social_django", "social_django",
"tree", "tree",
"django_select2", "django_select2",
@ -168,14 +169,52 @@ SOCIAL_AUTH_PIPELINE = (
"auth.pipeline.staff_me_up", "auth.pipeline.staff_me_up",
) )
STORAGES = { # Determines the storage type for Django static files and media.
"default": { FILE_STORAGE_TYPE = env("FILE_STORAGE_TYPE", "filesystem")
"BACKEND": "django.core.files.storage.FileSystemStorage", if FILE_STORAGE_TYPE == "filesystem":
}, STORAGES = {
"staticfiles": { "default": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", "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 # Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/ # https://docs.djangoproject.com/en/1.10/topics/i18n/