Skip to content

Commit

Permalink
add configuration for azure storage
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmagar committed Jul 11, 2024
1 parent 78e0839 commit e001bf0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

python manage.py collectstatic --no-input
python manage.py migrate --noinput

waitress-serve --port=$PORT {{cookiecutter.project_slug}}.wsgi:application
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,14 @@ def google_service_account_config():
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
GS_DEFAULT_ACL = "publicRead"

# Configuration for Azure Storage
AS_BUCKET_NAME = env.str("AS_BUCKET_NAME", "")
if AS_BUCKET_NAME:
AZURE_ACCOUNT_NAME = AS_BUCKET_NAME
AZURE_TOKEN_CREDENTIAL = DefaultAzureCredential()
AS_STATIC_CONTAINER = env.str("AS_STATIC_CONTAINER", "static")
AS_MEDIA_CONTAINER = env.str("AS_MEDIA_CONTAINER", "media")
DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.storage_backends.AzureMediaStorage"
STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.storage_backends.AzureStaticStorage"

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf import settings
from storages.backends.azure_storage import AzureStorage

class AzureStaticStorage(AzureStorage):
azure_container = settings.AS_STATIC_CONTAINER
expiration_secs = None

class AzureMediaStorage(AzureStorage):
azure_container = settings.AS_MEDIA_CONTAINER
expiration_secs = 3600

0 comments on commit e001bf0

Please sign in to comment.