Skip to content

Commit

Permalink
Add support for S3
Browse files Browse the repository at this point in the history
Co-authored-by: Colin Copeland <copelco@caktusgroup.com>
Co-authored-by: Jeanette O'Brien <jeanetteobr@users.noreply.github.com>
Co-authored-by: geraldo128 <geraldo128@users.noreply.github.com>
  • Loading branch information
4 people committed Jan 29, 2025
1 parent 1a9c868 commit f7989d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Docker

on:
push:
branches: [master]
branches: [main]
# Publish semver tags as releases.
tags: ["v*.*.*"]

Expand Down
3 changes: 2 additions & 1 deletion apps/odk_publish/etl/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def generate_and_save_app_user_collect_qrcodes(project: Project):
project_name_prefix=project.name,
)
app_user.qr_code.save(
f"{app_user.name}.png", SimpleUploadedFile("qrcode.png", image.getvalue())
f"{app_user.name}.png",
SimpleUploadedFile("qrcode.png", image.getvalue(), content_type="image/png"),
)


Expand Down
29 changes: 14 additions & 15 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@
# Uploaded media files
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
MEDIA_STORAGE_BUCKET_NAME = os.getenv("MEDIA_STORAGE_BUCKET_NAME", "")
MEDIA_LOCATION = os.getenv("MEDIA_LOCATION", f"{ENVIRONMENT}/")
MEDIA_S3_CUSTOM_DOMAIN = os.getenv("MEDIA_S3_CUSTOM_DOMAIN", "")

STORAGES = {
"default": {
"BACKEND": os.getenv("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage")
Expand All @@ -213,6 +211,19 @@
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

# Optionally configure settings for S3/MinIO
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
AWS_S3_CUSTOM_DOMAIN = os.getenv("AWS_S3_CUSTOM_DOMAIN", "")
AWS_LOCATION = os.getenv("AWS_LOCATION", f"{ENVIRONMENT}/")
AWS_S3_ENDPOINT_URL = os.getenv("AWS_S3_ENDPOINT_URL")
AWS_S3_USE_SSL = int(os.getenv("AWS_S3_USE_SSL", "1")) == 1
# AWS_S3_VERIFY is a funny setting whose allowed values are
# None, False, or a string (path to a AA bundle). Support all
# those values here.
AWS_S3_VERIFY = os.getenv("AWS_S3_VERIFY")
if AWS_S3_VERIFY and AWS_S3_VERIFY.lower() in ("false", "0"):
AWS_S3_VERIFY = False
AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL")
AWS_S3_ADDRESSING_STYLE = os.getenv("AWS_S3_ADDRESSING_STYLE", None)
AWS_S3_SIGNATURE_VERSION = os.getenv("AWS_S3_SIGNATURE_VERSION", "s3v4")
Expand All @@ -224,18 +235,6 @@
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")

# Azure storage
# https://django-storages.readthedocs.io/en/latest/backends/azure.html
AZURE_ACCOUNT_KEY = os.getenv("AZURE_ACCOUNT_KEY")
AZURE_ACCOUNT_NAME = os.getenv("AZURE_ACCOUNT_NAME")
AZURE_CONTAINER = os.getenv("AZURE_CONTAINER")
AZURE_OVERWRITE_FILES = os.getenv("AZURE_OVERWRITE_FILES", "True") == "True"
AZURE_SSL = os.getenv("AZURE_SSL", "True") == "True"
AZURE_LOCATION = os.getenv("AZURE_LOCATION", MEDIA_LOCATION)
AZURE_URL_EXPIRATION_SECS = os.getenv("AZURE_URL_EXPIRATION_SECS")
if AZURE_URL_EXPIRATION_SECS is not None:
AZURE_URL_EXPIRATION_SECS = int(AZURE_URL_EXPIRATION_SECS)

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

Expand Down

0 comments on commit f7989d1

Please sign in to comment.