From a1637ec456a2d2672ffaee9910d4c6684a1071bd Mon Sep 17 00:00:00 2001 From: paulmwatson Date: Wed, 11 Dec 2024 18:05:39 +0200 Subject: [PATCH] Added S3 CloudFront Image files --- pombola/settings/base.py | 23 +++++++++++++++++------ requirements.txt | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pombola/settings/base.py b/pombola/settings/base.py index 7ab2ef841..203f08254 100644 --- a/pombola/settings/base.py +++ b/pombola/settings/base.py @@ -142,11 +142,6 @@ # All uploaded files world-readable FILE_UPLOAD_PERMISSIONS = 0o644 # 'rw-r--r--' -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = "/media_root/" - # Use django-pipeline for handling static files STATICFILES_STORAGE = "pipeline.storage.PipelineCachedStorage" @@ -460,12 +455,28 @@ "django_nose", "django_extensions", "rest_framework", - "djcelery" + "djcelery", ) + if os.environ.get("DJANGO_DEBUG_TOOLBAR", "true").lower() == "true": INSTALLED_APPS += ("debug_toolbar",) +if os.environ.get("AWS_STORAGE_BUCKET_NAME"): + STATIC_HOST = os.environ.get("STATIC_HOST", "static.pa.org.za") + INSTALLED_APPS += ("storages",) + AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME") + AWS_S3_REGION_NAME = 'af-south-1' + AWS_S3_CUSTOM_DOMAIN = STATIC_HOST + DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' + MEDIA_URL = '//{}/'.format(AWS_S3_CUSTOM_DOMAIN) +else: + # URL that handles the media served from MEDIA_ROOT. Make sure to use a + # trailing slash. + # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" + MEDIA_URL = "/media_root/" + + def insert_after(sequence, existing_item, item_to_put_after): """A helper method for inserting an item after another in a sequence diff --git a/requirements.txt b/requirements.txt index 7faf2e5cf..28187241a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,6 +25,8 @@ django-pipeline==1.6.13 django-pipeline-compass-rubygem==0.1.9 django-formtools==2.1 django-cors-headers==1.3.1 +django-storages==1.9.1 + ### API related djangorestframework==3.4.7 @@ -210,3 +212,4 @@ xlrd==1.2.0 #sentry-sdk[django]==1.39.2 sentry-sdk==0.14.3 +boto3==1.17.112 \ No newline at end of file