How to configure Django project + Tailwind CSS + django-compressor + MinIO

264 Views Asked by At

I have Django project which I configured for local development on my notebook and docker-compose for production use.

I use Tailwind CSS + django-compressor and it works great locally but I don't understand how make it works with Min.io storage on product server.

I found documentation for configure django-compressor with S3 storage, but it doesn't work with MinIO storage...

Here is my settings.py

.....

# django-compressor settings
COMPRESS_ROOT = BASE_DIR / 'static'
COMPRESS_ENABLED = True
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)
if not DEBUG:
    COMPRESS_OFFLINE = True

# MINIO settings
MINIO_STATIC_FILES_BUCKET = 'my-static-files-bucket'  # replacement for STATIC_ROOT
if not DEBUG:
    MINIO_ENDPOINT = 'minio:9000'
    MINIO_EXTERNAL_ENDPOINT = 'localhost:9000'
    MINIO_EXTERNAL_ENDPOINT_USE_HTTPS = False
    MINIO_ACCESS_KEY = os.getenv('MINIO_ROOT_USER')
    MINIO_SECRET_KEY = os.getenv('MINIO_ROOT_PASSWORD')
    MINIO_USE_HTTPS = False
    MINIO_BUCKET_CHECK_ON_SAVE = True  # Default: True // Creates bucket if missing, then save
    # MINIO_CONSISTENCY_CHECK_ON_START = True



    COMPRESS_URL = f"{MINIO_EXTERNAL_ENDPOINT}/{MINIO_STATIC_FILES_BUCKET}/"
    COMPRESS_STORAGE = 'django_minio_backend.models.MinioBackendStatic'

    MINIO_MEDIA_FILES_BUCKET = 'my-media-files-bucket'  # replacement for MEDIA_ROOT
    MINIO_PRIVATE_BUCKETS = [
        os.getenv('MINIO_STORAGE_BUCKET'),
        MINIO_STATIC_FILES_BUCKET,
        MINIO_MEDIA_FILES_BUCKET,
    ]

    # MINIO_PRIVATE_BUCKETS.append(MINIO_STATIC_FILES_BUCKET)
    STATICFILES_STORAGE = 'django_minio_backend.models.MinioBackendStatic'

    # MINIO_PRIVATE_BUCKETS.append(MINIO_STATIC_FILES_BUCKET)
    DEFAULT_FILE_STORAGE = 'django_minio_backend.models.MinioBackend'
    MEDIA_URL = f"{MINIO_EXTERNAL_ENDPOINT}/{MINIO_MEDIA_FILES_BUCKET}/media/"
else:
    MEDIA_URL = "/media/"
0

There are 0 best solutions below