diff --git a/Makefile b/Makefile index aefd8f2..d2c069a 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -MAKEFLAGS += -j3 - +MAKEFLAGS += -j4 GIT_TAG = ${shell git tag | tail -1} build: build-tailwindcss build-statics deps: bun-install python-install build-docker: build-docker-image -dev: dev-tailwindcss dev-django dev-redis-start +dev: dev-tailwindcss dev-django dev-redis-start dev-minio-start migrate: migrate-django prod: prod-release @@ -42,6 +41,13 @@ prod-nginx-link: dev-redis-start: docker run --rm -p 6379:6379 --name hanz_dev_redis redis:7-bookworm +dev-minio-start: + docker run --rm -p 9000:9000 -p 9001:9001 \ + --env MINIO_ROOT_USER=root --env MINIO_ROOT_PASSWORD=password \ + --volume ./dev_data/minio/data:/data \ + --name hanz_dev_minio \ + quay.io/minio/minio server /data --console-address ":9001" + build-docker-image: docker build --tag hanz-web:${GIT_TAG} -f ./dev.Dockerfile . diff --git a/Pipfile b/Pipfile index c5755bd..b68a80b 100644 --- a/Pipfile +++ b/Pipfile @@ -16,7 +16,7 @@ crispy-tailwind = "*" wagtail-cache = "*" redis = {extras = ["hiredis"], version = "*"} django-dbbackup = "*" -django-storages = {extras = ["boto3"], version = "*"} +django-storages = {extras = ["boto3"], version = "==1.14"} django-anymail = {extras = ["resend"], version = "*"} [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 8ca0c0e..91a3c82 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e97e3a37b649d46b05fbbf5495baca50ba60fb44602cdc5dd145a6b9db9e4706" + "sha256": "a4b02325a0d37d3d441339e737bb2c75844a147f029e46d1efbef43bc5296a5f" }, "pipfile-spec": 6, "requires": { @@ -323,11 +323,11 @@ "boto3" ], "hashes": [ - "sha256:1db759346b52ada6c2efd9f23d8241ecf518813eb31db9e2589207174f58f6ad", - "sha256:51b36af28cc5813b98d5f3dfe7459af638d84428c8df4a03990c7d74d1bea4e5" + "sha256:11280a883b13812df548f3cfe9c10280afc0d4727c8babdee369a75e71158f16", + "sha256:6c97e5faad829c923a1262206281742c484d76d43b332a196ddcc242b909c551" ], "markers": "python_version >= '3.7'", - "version": "==1.14.2" + "version": "==1.14" }, "django-taggit": { "hashes": [ diff --git a/hanz/settings/base.py b/hanz/settings/base.py index e5164a3..6a8f110 100644 --- a/hanz/settings/base.py +++ b/hanz/settings/base.py @@ -14,6 +14,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os import dj_database_url +from django.conf.global_settings import STORAGES PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) @@ -57,6 +58,7 @@ "crispy_forms", "crispy_tailwind", "dbbackup", # django-dbbackup + "storages", # django-storages ] MIDDLEWARE = [ @@ -95,6 +97,8 @@ WSGI_APPLICATION = "hanz.wsgi.application" +SESSION_COOKIE_SECURE = True +CSRF_COOKIE_SECURE = True # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases @@ -161,13 +165,9 @@ # https://docs.djangoproject.com/en/5.0/topics/i18n/ LANGUAGE_CODE = "en-us" - TIME_ZONE = "UTC" - USE_I18N = True - USE_L10N = True - USE_TZ = True @@ -193,19 +193,34 @@ # # in the case of CDN url STATIC_HOST = os.environ.get("DJANGO_STATIC_HOST", "") - STATIC_URL = STATIC_HOST + "/static/" -MEDIA_ROOT = os.path.join(BASE_DIR, "media") -MEDIA_URL = "/media/" -SESSION_COOKIE_SECURE = True -CSRF_COOKIE_SECURE = True +# Storage Backends +STORAGES["default"] = { + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "access_key": os.environ.get("MEDIA_S3_ACCESS_KEY_ID"), + "secret_key": os.environ.get("MEDIA_S3_SECRET_KEY"), + "bucket_name": os.environ.get("MEDIA_S3_BUCKET_NAME"), + "region_name": os.environ.get("MEDIA_S3_REGION_NAME", "us-east-1"), + "endpoint_url": os.environ.get("MEDIA_S3_ENDPOINT_URL"), + "use_ssl": os.environ.get("MEDIA_S3_USE_SSL", True) == "True", + "addressing_style": "path", + "default_acl": "public-read", + }, +} -COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" # brotli compression for static files +MEDIA_ROOT = os.path.join(BASE_DIR, "media") +MEDIA_URL = "/media/" + +# Static Files # Boolean that decides if compression will happen. COMPRESS_ENABLED = os.environ.get("COMPRESS_ENABLED", not DEBUG) == "True" +COMPRESS_STORAGE = ( + "compressor.storage.GzipCompressorFileStorage" # gzip compression for static files +) # Boolean that decides if compression should be done outside of the request/response loop. # Must enable this to use with Whitenoise @@ -215,7 +230,6 @@ COMPRESS_ROOT = os.path.join(BASE_DIR, "static") # Wagtail settings - WAGTAIL_SITE_NAME = "hanz" # Search