Vultr Object Storage With Wagtail
This quick writeup assumes you already are running dokku on vultr.
Create storage on Vultr and copy your keys.
We are available to do this type of work for you, just contact us.
dokku config:set app-name --no-restart AWS_ACCESS_KEY_ID=aws-key-id-here
dokku config:set app-name --no-restart AWS_SECRET_ACCESS_KEY=aws-secret-here
dokku config:set app-name --no-restart AWS_MEDIA_URL=https://bucket-name.ewr1.vultrobjects.com
dokku config:set app-name --no-restart AWS_S3_ENDPOINT_URL=https://ewr1.vultrobjects.com
dokku config:set app-name --no-restart AWS_S3_CUSTOM_DOMAIN=bucket-name.ewr1.vultrobjects.com
dokku config:set app-name AWS_STORAGE_BUCKET_NAME=bucket-name
# base.py
# S3 Storage
if "AWS_STORAGE_BUCKET_NAME" in os.environ:
# https://docs.djangoproject.com/en/stable/ref/settings/#default-file-storage
MEDIA_URL = "https://%s/" % env("AWS_MEDIA_URL")
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
# Disables signing of the S3 objects' URLs. When set to True it
# will append authorization querystring to each URL.
AWS_QUERYSTRING_AUTH = False
# Do not allow overriding files on S3 as per Wagtail docs recommendation:
# https://docs.wagtail.io/en/stable/advanced_topics/deploying.html#cloud-storage
# Not having this setting may have consequences such as losing files.
AWS_S3_FILE_OVERWRITE = False
# Default ACL for new files should be "private" - not accessible to the
# public. Images should be made available to public via the bucket policy,
# where the documents should use wagtail-storages.
AWS_DEFAULT_ACL = "public-read"
# We generally use this setting in production to put the S3 bucket
# behind a CDN using a custom domain, e.g. media.llamasavers.com.
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
if "AWS_S3_CUSTOM_DOMAIN" in os.environ:
AWS_S3_CUSTOM_DOMAIN = os.environ["AWS_S3_CUSTOM_DOMAIN"]
# When signing URLs is enabled, the region must be set.
# The global S3 endpoint does not seem to support signed URLS.
# Set this only if you will be using signed URLs.
if "AWS_S3_REGION_NAME" in os.environ:
AWS_S3_REGION_NAME = os.environ["AWS_S3_REGION_NAME"]
# This settings lets you force using http or https protocol when generating
# the URLs to the files. Set https as default.
# https://github.com/jschneier/django-storages/blob/10d1929de5e0318dbd63d715db4bebc9a42257b5/storages/backends/s3boto3.py#L217
AWS_S3_URL_PROTOCOL = os.environ.get("AWS_S3_URL_PROTOCOL", "https:")
# We generally use this setting in production to put the S3 bucket
# behind a CDN using a custom domain, e.g. media.llamasavers.com.
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
if "AWS_S3_CUSTOM_DOMAIN" in os.environ:
AWS_S3_CUSTOM_DOMAIN = os.environ["AWS_S3_CUSTOM_DOMAIN"]
if "AWS_S3_ENDPOINT_URL" in os.environ:
AWS_S3_ENDPOINT_URL = os.environ["AWS_S3_ENDPOINT_URL"]
# requirements.tx
wagtail-storages
boto3
django-storages
# Add to apps
"storages",
"wagtail_storages.apps.WagtailStoragesConfig",
Next time you deploy your app, file uploads should be stored on Vultr Object Storage.
If you have problems, you may need to change bucket permissions.