Skip to content

Commit

Permalink
configurado arquivos estaticos para Amazon S3
Browse files Browse the repository at this point in the history
close #40
  • Loading branch information
thiago-garcia committed Mar 30, 2024
1 parent 6a34837 commit fffe4d3
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pytest-django = "*"
python-decouple = "*"
dj-database-url = "*"
psycopg2-binary = "*"
django-s3-folder-storage = "*"
collectfast = "*"

[dev-packages]
flake8 = "*"
Expand Down
82 changes: 81 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion contrib/env-sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
DEBUG=False
SECRET_KEY=CHAVE SECRETA
ALLOWED_HOSTS=127.0.0.1, localhost
DATABASE_URL=postgres://postgres:postgres@localhost/postgres
DATABASE_URL=postgres://postgres:postgres@localhost/postgres
# Configuração do AWS
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_STORAGE_BUCKET_NAME=
35 changes: 35 additions & 0 deletions pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'collectfast',
'django.contrib.staticfiles',
'pypro.base',
]
Expand Down Expand Up @@ -128,6 +129,40 @@
MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'mediafiles'

COLLECTFAST_ENABLE = False

AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')

# STORAGE CONFIGURATION IN S3 AWS
if AWS_ACCESS_KEY_ID:
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400', }
AWS_PRELOAD_METADATA = True
AWS_AUTO_CREATE_BUCKET = False
AWS_QUERYSTRING_AUTH = True
AWS_S3_CUSTOM_DOMAIN = None

COLLECTFAST_ENABLE = True

AWS_DEFAULT_ACL = 'private'

# Static Assets
STATICFILES_STORAGE = 's3_folder_storage.s3.StaticStorage'
STATIC_S3_PATH = 'static'
STATIC_ROOT = f'/{STATIC_S3_PATH}/'
STATIC_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{STATIC_S3_PATH}/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

# Upload Media Folder
DEFAULT_FILE_STORAGE = 's3_folder_storage.s3.DefaultStorage'
DEFAULT_S3_PATH = 'media'
MEDIA_ROOT = f'/{DEFAULT_S3_PATH}/'
MEDIA_URL = f'//s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/{DEFAULT_S3_PATH}/'

INSTALLED_APPS.append('s3_folder_storage')
INSTALLED_APPS.append('storages')


# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
Expand Down

0 comments on commit fffe4d3

Please sign in to comment.