Add azure blob storage as default media storage
This commit is contained in:
parent
6e264b1480
commit
0a5a6fa4ce
|
|
@ -0,0 +1,4 @@
|
||||||
|
npm install
|
||||||
|
python server/manage.py collectstatic --noinput
|
||||||
|
docker build --platform linux/amd64 -f compose/django/Dockerfile -t iterativ/vbv-lernwelt-django:azure .
|
||||||
|
docker image push iterativ/vbv-lernwelt-django:azure
|
||||||
Binary file not shown.
|
|
@ -5,14 +5,14 @@ from environs import Env
|
||||||
env = Env()
|
env = Env()
|
||||||
env.read_env()
|
env.read_env()
|
||||||
class AzureMediaStorage(AzureStorage):
|
class AzureMediaStorage(AzureStorage):
|
||||||
account_name = env("AZURE_STORAGE_ACCOUNT")
|
account_name = env("IT_AZURE_STORAGE_ACCOUNT")
|
||||||
account_key = env("AZURE_STORAGE_KEY")
|
account_key = env("IT_AZURE_STORAGE_KEY")
|
||||||
azure_container = 'media'
|
azure_container = 'media'
|
||||||
expiration_secs = None
|
expiration_secs = None
|
||||||
|
|
||||||
class AzureStaticStorage(AzureStorage):
|
class AzureStaticStorage(AzureStorage):
|
||||||
account_name = env("AZURE_STORAGE_ACCOUNT")
|
account_name = env("IT_AZURE_STORAGE_ACCOUNT")
|
||||||
account_key = env("AZURE_STORAGE_KEY")
|
account_key = env("IT_AZURE_STORAGE_KEY")
|
||||||
azure_container = 'static'
|
azure_container = 'static'
|
||||||
expiration_secs = None
|
expiration_secs = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,18 +214,18 @@ if USE_AWS:
|
||||||
# https://wagtail.org/blog/amazon-s3-for-media-files/
|
# https://wagtail.org/blog/amazon-s3-for-media-files/
|
||||||
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
|
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
|
||||||
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
|
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
|
||||||
elif env(USE_AZURE_BLOB_STORAGE):
|
elif env("IT_USE_AZURE_BLOB_STORAGE", False):
|
||||||
# https://medium.com/@DawlysD/django-using-azure-blob-storage-to-handle-static-media-assets-from-scratch-90cbbc7d56be
|
# https://medium.com/@DawlysD/django-using-azure-blob-storage-to-handle-static-media-assets-from-scratch-90cbbc7d56be
|
||||||
DEFAULT_FILE_STORAGE = 'backend.custom_azure.AzureMediaStorage'
|
DEFAULT_FILE_STORAGE = 'backend.custom_azure.AzureMediaStorage'
|
||||||
STATICFILES_STORAGE = 'backend.custom_azure.AzureStaticStorage'
|
#STATICFILES_STORAGE = 'backend.custom_azure.AzureStaticStorage'
|
||||||
|
|
||||||
STATIC_LOCATION = "static"
|
#STATIC_LOCATION = "static"
|
||||||
MEDIA_LOCATION = "media"
|
MEDIA_LOCATION = "media"
|
||||||
|
|
||||||
AZURE_ACCOUNT_NAME = "djangoaccountstorage"
|
AZURE_ACCOUNT_NAME = env("IT_AZURE_STORAGE_ACCOUNT")
|
||||||
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
|
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
|
||||||
STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
|
#STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{APP_ENVIRONMENT}/{STATIC_LOCATION}/'
|
||||||
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/'
|
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{APP_ENVIRONMENT}/{MEDIA_LOCATION}/'
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.10
|
# This file is autogenerated by pip-compile with python 3.10
|
||||||
# by the following command:
|
# To update, run:
|
||||||
#
|
#
|
||||||
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
|
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
|
||||||
#
|
#
|
||||||
|
|
@ -10,6 +10,8 @@ anyascii==0.3.1
|
||||||
# via wagtail
|
# via wagtail
|
||||||
anyio==3.5.0
|
anyio==3.5.0
|
||||||
# via watchfiles
|
# via watchfiles
|
||||||
|
appnope==0.1.3
|
||||||
|
# via ipython
|
||||||
argon2-cffi==21.3.0
|
argon2-cffi==21.3.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
argon2-cffi-bindings==21.2.0
|
argon2-cffi-bindings==21.2.0
|
||||||
|
|
@ -29,6 +31,16 @@ attrs==21.4.0
|
||||||
# usort
|
# usort
|
||||||
authlib==1.0.0
|
authlib==1.0.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
|
azure-core==1.26.4
|
||||||
|
# via
|
||||||
|
# azure-identity
|
||||||
|
# azure-storage-blob
|
||||||
|
azure-identity==1.13.0
|
||||||
|
# via -r requirements.in
|
||||||
|
azure-storage-blob==12.16.0
|
||||||
|
# via
|
||||||
|
# -r requirements.in
|
||||||
|
# django-storages
|
||||||
backcall==0.2.0
|
backcall==0.2.0
|
||||||
# via ipython
|
# via ipython
|
||||||
beautifulsoup4==4.9.3
|
beautifulsoup4==4.9.3
|
||||||
|
|
@ -82,7 +94,12 @@ coverage==6.3.2
|
||||||
# -r requirements-dev.in
|
# -r requirements-dev.in
|
||||||
# django-coverage-plugin
|
# django-coverage-plugin
|
||||||
cryptography==36.0.2
|
cryptography==36.0.2
|
||||||
# via authlib
|
# via
|
||||||
|
# authlib
|
||||||
|
# azure-identity
|
||||||
|
# azure-storage-blob
|
||||||
|
# msal
|
||||||
|
# pyjwt
|
||||||
decorator==5.1.1
|
decorator==5.1.1
|
||||||
# via
|
# via
|
||||||
# ipdb
|
# ipdb
|
||||||
|
|
@ -155,7 +172,7 @@ django-ratelimit==3.0.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-redis==5.2.0
|
django-redis==5.2.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-storages==1.13.1
|
django-storages[azure]==1.13.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-stubs==1.10.1
|
django-stubs==1.10.1
|
||||||
# via
|
# via
|
||||||
|
|
@ -241,6 +258,8 @@ ipdb==0.13.9
|
||||||
# via -r requirements-dev.in
|
# via -r requirements-dev.in
|
||||||
ipython==8.2.0
|
ipython==8.2.0
|
||||||
# via ipdb
|
# via ipdb
|
||||||
|
isodate==0.6.1
|
||||||
|
# via azure-storage-blob
|
||||||
isort==5.10.1
|
isort==5.10.1
|
||||||
# via
|
# via
|
||||||
# flake8-isort
|
# flake8-isort
|
||||||
|
|
@ -281,6 +300,12 @@ moreorless==0.4.0
|
||||||
# via
|
# via
|
||||||
# ufmt
|
# ufmt
|
||||||
# usort
|
# usort
|
||||||
|
msal==1.22.0
|
||||||
|
# via
|
||||||
|
# azure-identity
|
||||||
|
# msal-extensions
|
||||||
|
msal-extensions==1.0.0
|
||||||
|
# via azure-identity
|
||||||
mypy==0.942
|
mypy==0.942
|
||||||
# via
|
# via
|
||||||
# -r requirements-dev.in
|
# -r requirements-dev.in
|
||||||
|
|
@ -330,7 +355,9 @@ pluggy==1.0.0
|
||||||
polib==1.1.1
|
polib==1.1.1
|
||||||
# via wagtail-localize
|
# via wagtail-localize
|
||||||
portalocker==2.4.0
|
portalocker==2.4.0
|
||||||
# via concurrent-log-handler
|
# via
|
||||||
|
# concurrent-log-handler
|
||||||
|
# msal-extensions
|
||||||
pre-commit==2.17.0
|
pre-commit==2.17.0
|
||||||
# via -r requirements-dev.in
|
# via -r requirements-dev.in
|
||||||
promise==2.3
|
promise==2.3
|
||||||
|
|
@ -353,6 +380,8 @@ pyflakes==2.4.0
|
||||||
# via flake8
|
# via flake8
|
||||||
pygments==2.11.2
|
pygments==2.11.2
|
||||||
# via ipython
|
# via ipython
|
||||||
|
pyjwt[crypto]==2.7.0
|
||||||
|
# via msal
|
||||||
pylint==2.13.4
|
pylint==2.13.4
|
||||||
# via
|
# via
|
||||||
# pylint-django
|
# pylint-django
|
||||||
|
|
@ -409,9 +438,11 @@ redis==4.2.1
|
||||||
# django-redis
|
# django-redis
|
||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
# via
|
# via
|
||||||
|
# azure-core
|
||||||
# caprover-api
|
# caprover-api
|
||||||
# coreapi
|
# coreapi
|
||||||
# djangorestframework-stubs
|
# djangorestframework-stubs
|
||||||
|
# msal
|
||||||
# wagtail
|
# wagtail
|
||||||
s3transfer==0.6.0
|
s3transfer==0.6.0
|
||||||
# via boto3
|
# via boto3
|
||||||
|
|
@ -422,8 +453,11 @@ sentry-sdk==1.5.8
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
# via
|
# via
|
||||||
# asttokens
|
# asttokens
|
||||||
|
# azure-core
|
||||||
|
# azure-identity
|
||||||
# django-coverage-plugin
|
# django-coverage-plugin
|
||||||
# html5lib
|
# html5lib
|
||||||
|
# isodate
|
||||||
# l18n
|
# l18n
|
||||||
# promise
|
# promise
|
||||||
# python-dateutil
|
# python-dateutil
|
||||||
|
|
@ -490,8 +524,10 @@ types-pytz==2021.3.6
|
||||||
# via django-stubs
|
# via django-stubs
|
||||||
types-pyyaml==6.0.5
|
types-pyyaml==6.0.5
|
||||||
# via django-stubs
|
# via django-stubs
|
||||||
typing-extensions==4.1.1
|
typing-extensions==4.5.0
|
||||||
# via
|
# via
|
||||||
|
# azure-core
|
||||||
|
# azure-storage-blob
|
||||||
# django-stubs
|
# django-stubs
|
||||||
# django-stubs-ext
|
# django-stubs-ext
|
||||||
# djangorestframework-stubs
|
# djangorestframework-stubs
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ django-ratelimit
|
||||||
django-ipware
|
django-ipware
|
||||||
django-csp
|
django-csp
|
||||||
django-storages
|
django-storages
|
||||||
|
django-storages[azure]
|
||||||
django-notifications-hq
|
django-notifications-hq
|
||||||
django-jsonform
|
django-jsonform
|
||||||
|
|
||||||
|
|
@ -42,4 +43,7 @@ wagtail-factories>=4
|
||||||
wagtail-localize>=1.5
|
wagtail-localize>=1.5
|
||||||
wagtail_grapple>=0.19.2
|
wagtail_grapple>=0.19.2
|
||||||
|
|
||||||
|
azure-storage-blob
|
||||||
|
azure-identity
|
||||||
|
|
||||||
boto3
|
boto3
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#
|
#
|
||||||
# This file is autogenerated by pip-compile with Python 3.10
|
# This file is autogenerated by pip-compile with python 3.10
|
||||||
# by the following command:
|
# To update, run:
|
||||||
#
|
#
|
||||||
# pip-compile --output-file=requirements.txt requirements.in
|
# pip-compile --output-file=requirements.txt requirements.in
|
||||||
#
|
#
|
||||||
|
|
@ -22,6 +22,16 @@ attrs==21.4.0
|
||||||
# via jsonschema
|
# via jsonschema
|
||||||
authlib==1.0.0
|
authlib==1.0.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
|
azure-core==1.26.4
|
||||||
|
# via
|
||||||
|
# azure-identity
|
||||||
|
# azure-storage-blob
|
||||||
|
azure-identity==1.13.0
|
||||||
|
# via -r requirements.in
|
||||||
|
azure-storage-blob==12.16.0
|
||||||
|
# via
|
||||||
|
# -r requirements.in
|
||||||
|
# django-storages
|
||||||
beautifulsoup4==4.9.3
|
beautifulsoup4==4.9.3
|
||||||
# via wagtail
|
# via wagtail
|
||||||
boto3==1.26.11
|
boto3==1.26.11
|
||||||
|
|
@ -50,7 +60,12 @@ click==8.1.1
|
||||||
concurrent-log-handler==0.9.20
|
concurrent-log-handler==0.9.20
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
cryptography==36.0.2
|
cryptography==36.0.2
|
||||||
# via authlib
|
# via
|
||||||
|
# authlib
|
||||||
|
# azure-identity
|
||||||
|
# azure-storage-blob
|
||||||
|
# msal
|
||||||
|
# pyjwt
|
||||||
deprecated==1.2.13
|
deprecated==1.2.13
|
||||||
# via redis
|
# via redis
|
||||||
dj-database-url==1.0.0
|
dj-database-url==1.0.0
|
||||||
|
|
@ -104,7 +119,7 @@ django-ratelimit==3.0.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-redis==5.2.0
|
django-redis==5.2.0
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-storages==1.13.1
|
django-storages[azure]==1.13.1
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
django-taggit==2.1.0
|
django-taggit==2.1.0
|
||||||
# via wagtail
|
# via wagtail
|
||||||
|
|
@ -154,6 +169,8 @@ idna==3.3
|
||||||
# requests
|
# requests
|
||||||
inflection==0.5.1
|
inflection==0.5.1
|
||||||
# via drf-spectacular
|
# via drf-spectacular
|
||||||
|
isodate==0.6.1
|
||||||
|
# via azure-storage-blob
|
||||||
jmespath==1.0.1
|
jmespath==1.0.1
|
||||||
# via
|
# via
|
||||||
# boto3
|
# boto3
|
||||||
|
|
@ -166,6 +183,12 @@ l18n==2021.3
|
||||||
# via wagtail
|
# via wagtail
|
||||||
marshmallow==3.15.0
|
marshmallow==3.15.0
|
||||||
# via environs
|
# via environs
|
||||||
|
msal==1.22.0
|
||||||
|
# via
|
||||||
|
# azure-identity
|
||||||
|
# msal-extensions
|
||||||
|
msal-extensions==1.0.0
|
||||||
|
# via azure-identity
|
||||||
openpyxl==3.1.2
|
openpyxl==3.1.2
|
||||||
# via wagtail
|
# via wagtail
|
||||||
packaging==21.3
|
packaging==21.3
|
||||||
|
|
@ -179,13 +202,17 @@ pillow==9.0.1
|
||||||
polib==1.1.1
|
polib==1.1.1
|
||||||
# via wagtail-localize
|
# via wagtail-localize
|
||||||
portalocker==2.4.0
|
portalocker==2.4.0
|
||||||
# via concurrent-log-handler
|
# via
|
||||||
|
# concurrent-log-handler
|
||||||
|
# msal-extensions
|
||||||
promise==2.3
|
promise==2.3
|
||||||
# via graphene-django
|
# via graphene-django
|
||||||
psycopg2-binary==2.9.3
|
psycopg2-binary==2.9.3
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
# via cffi
|
# via cffi
|
||||||
|
pyjwt[crypto]==2.7.0
|
||||||
|
# via msal
|
||||||
pyparsing==3.0.7
|
pyparsing==3.0.7
|
||||||
# via packaging
|
# via packaging
|
||||||
pyrsistent==0.18.1
|
pyrsistent==0.18.1
|
||||||
|
|
@ -221,7 +248,10 @@ redis==4.2.1
|
||||||
# -r requirements.in
|
# -r requirements.in
|
||||||
# django-redis
|
# django-redis
|
||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
# via wagtail
|
# via
|
||||||
|
# azure-core
|
||||||
|
# msal
|
||||||
|
# wagtail
|
||||||
s3transfer==0.6.0
|
s3transfer==0.6.0
|
||||||
# via boto3
|
# via boto3
|
||||||
sendgrid==6.9.7
|
sendgrid==6.9.7
|
||||||
|
|
@ -230,7 +260,10 @@ sentry-sdk==1.5.8
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
# via
|
# via
|
||||||
|
# azure-core
|
||||||
|
# azure-identity
|
||||||
# html5lib
|
# html5lib
|
||||||
|
# isodate
|
||||||
# l18n
|
# l18n
|
||||||
# promise
|
# promise
|
||||||
# python-dateutil
|
# python-dateutil
|
||||||
|
|
@ -252,8 +285,11 @@ text-unidecode==1.3
|
||||||
# via
|
# via
|
||||||
# graphene-django
|
# graphene-django
|
||||||
# python-slugify
|
# python-slugify
|
||||||
typing-extensions==4.2.0
|
typing-extensions==4.5.0
|
||||||
# via wagtail-localize
|
# via
|
||||||
|
# azure-core
|
||||||
|
# azure-storage-blob
|
||||||
|
# wagtail-localize
|
||||||
uritemplate==4.1.1
|
uritemplate==4.1.1
|
||||||
# via drf-spectacular
|
# via drf-spectacular
|
||||||
urllib3==1.26.9
|
urllib3==1.26.9
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue