mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-27 17:42:08 +00:00
Merge pull request #129 from revsys/setup-django-storages
Setup django-storages for S3 compatible storage when deployed
This commit is contained in:
@@ -339,5 +339,20 @@ if ENV_NAME == "Development Environment":
|
||||
elif ENV_NAME == "Production Environment":
|
||||
ENVIRONMENT_COLOR = "#E53E3E"
|
||||
|
||||
# S3 Compatiable Storage Settings
|
||||
if not LOCAL_DEVELOPMENT:
|
||||
AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID", default="changeme")
|
||||
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY", default="changeme")
|
||||
MEDIA_BUCKET_NAME = env("MEDIA_BUCKET", default="changeme")
|
||||
AWS_STORAGE_BUCKET_NAME = MEDIA_BUCKET_NAME
|
||||
AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400"}
|
||||
AWS_DEFAULT_ACL = None
|
||||
AWS_S3_ENDPOINT_URL = env(
|
||||
"AWS_S3_ENDPOINT_URL", default="https://sfo2.digitaloceanspaces.com"
|
||||
)
|
||||
AWS_S3_REGION_NAME = env("AWS_S3_REGION_NAME", default="sfo2")
|
||||
DEFAULT_FILE_STORAGE = "core.storages.MediaStorage"
|
||||
MEDIA_URL = f"{AWS_S3_ENDPOINT_URL}/{MEDIA_BUCKET_NAME}/"
|
||||
|
||||
# Markdown content
|
||||
BASE_CONTENT = env("BOOST_CONTENT_DIRECTORY", "/website")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import logging
|
||||
|
||||
from .settings import * # noqa
|
||||
|
||||
|
||||
@@ -30,3 +29,6 @@ GITHUB_TOKEN = "changeme"
|
||||
|
||||
# Make content relative to the project root
|
||||
BASE_CONTENT = BASE_DIR / "core/tests/content"
|
||||
|
||||
# Don't use S3 in tests
|
||||
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
|
||||
|
||||
10
core/storages.py
Normal file
10
core/storages.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.conf import settings
|
||||
|
||||
from storages.backends.s3boto3 import S3Boto3Storage
|
||||
|
||||
|
||||
class MediaStorage(S3Boto3Storage):
|
||||
bucket_name = settings.MEDIA_BUCKET_NAME
|
||||
default_acl = "public-read"
|
||||
file_overwrite = True
|
||||
custom_domain = False
|
||||
@@ -89,19 +89,18 @@ Env:
|
||||
key: key
|
||||
- name: ENVIRONMENT_NAME
|
||||
value: "Development Environment"
|
||||
# Bucket is setup already, but not using storages just yet
|
||||
# - name: AWS_ACCESS_KEY_ID
|
||||
# valueFrom:
|
||||
# secretKeyRef:
|
||||
# name: digital-ocean-keys
|
||||
# key: do_access_key
|
||||
# - name: AWS_SECRET_ACCESS_KEY
|
||||
# valueFrom:
|
||||
# secretKeyRef:
|
||||
# name: digital-ocean-keys
|
||||
# key: do_secret_key
|
||||
# - name: MEDIA_BUCKET_NAME
|
||||
# value: boost-dev-media
|
||||
- name: AWS_ACCESS_KEY_ID
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: media-bucket
|
||||
key: access_key
|
||||
- name: AWS_SECRET_ACCESS_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: media-bucket
|
||||
key: secret_key
|
||||
- name: MEDIA_BUCKET_NAME
|
||||
value: boost-dev-media
|
||||
|
||||
# Volumes
|
||||
Volumes:
|
||||
|
||||
@@ -16,6 +16,7 @@ psycopg2-binary
|
||||
whitenoise
|
||||
django-click
|
||||
Pillow==9.4.0
|
||||
django-storages
|
||||
|
||||
# Logging
|
||||
django-tracer
|
||||
|
||||
@@ -80,6 +80,7 @@ django==3.2.2
|
||||
# django-machina
|
||||
# django-redis
|
||||
# django-rest-auth
|
||||
# django-storages
|
||||
# djangorestframework
|
||||
# model-bakery
|
||||
django-admin-env-notice==0.4
|
||||
@@ -110,6 +111,8 @@ django-redis==5.0.0
|
||||
# via -r ./requirements.in
|
||||
django-rest-auth==0.9.5
|
||||
# via -r ./requirements.in
|
||||
django-storages==1.13.2
|
||||
# via -r ./requirements.in
|
||||
django-test-plus==1.4.0
|
||||
# via -r ./requirements.in
|
||||
django-tracer==0.9.3
|
||||
|
||||
Reference in New Issue
Block a user