Skip to content

Commit 3552f02

Browse files
committed
fix: use file system storage locally and adapt AWS variables
1 parent 9ef68ea commit 3552f02

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

backend/settings.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,35 @@
206206
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
207207

208208

209+
# AWS S3 storage configuration
210+
AWS_STORAGE_BUCKET_NAME = os.environ.get('DEFAULT_STORAGE_BUCKET', '')
211+
AWS_ACCESS_KEY_ID = os.environ.get('DEFAULT_STORAGE_ACCESS_KEY_ID', '')
212+
AWS_SECRET_ACCESS_KEY = os.environ.get('DEFAULT_STORAGE_SECRET_ACCESS_KEY', '')
213+
AWS_S3_CUSTOM_DOMAIN = os.environ.get('DEFAULT_STORAGE_CUSTOM_DOMAIN', '')
214+
AWS_S3_REGION_NAME = os.environ.get('DEFAULT_STORAGE_REGION', '')
215+
AWS_S3_OBJECT_PARAMETERS = {
216+
'ACL': 'public-read',
217+
'CacheControl': 'max-age=86400',
218+
}
219+
AWS_S3_FILE_OVERWRITE = False
220+
221+
209222
# Default storage settings, with the staticfiles storage updated.
210223
# See https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-STORAGES
224+
STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"
225+
226+
if AWS_SECRET_ACCESS_KEY:
227+
STORAGE_BACKEND = "storages.backends.s3boto3.S3Boto3Storage"
211228

212229
STORAGES = {
213230
"default": {
214-
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
231+
"BACKEND": STORAGE_BACKEND,
215232
},
233+
# ManifestStaticFilesStorage is recommended in production, to prevent
234+
# outdated JavaScript / CSS assets being served from cache
235+
# See https://docs.djangoproject.com/en/5.0/ref/contrib/staticfiles/#manifeststaticfilesstorage
216236
"staticfiles": {
217-
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
237+
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
218238
},
219239
}
220240

@@ -242,15 +262,3 @@
242262

243263
CMS_CONFIRM_VERSION4 = True
244264
DJANGOCMS_VERSIONING_ALLOW_DELETING_VERSIONS = True
245-
246-
247-
# AWS S3 storage configuration
248-
AWS_ACCESS_KEY_ID = os.environ.get('DEFAULT_STORAGE_ACCESS_KEY_ID', '')
249-
AWS_SECRET_ACCESS_KEY = os.environ.get('DEFAULT_STORAGE_SECRET_ACCESS_KEY', '')
250-
AWS_S3_REGION_NAME = os.environ.get('DEFAULT_STORAGE_REGION', '')
251-
AWS_STORAGE_BUCKET_NAME=os.environ.get('DEFAULT_STORAGE_BUCKET', '')
252-
AWS_S3_CUSTOM_DOMAIN = os.environ.get('DEFAULT_STORAGE_CUSTOM_DOMAIN', '')
253-
AWS_S3_OBJECT_PARAMETERS = {
254-
'ACL': 'public-read',
255-
'CacheControl': 'max-age=86400',
256-
}

0 commit comments

Comments
 (0)