Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TM-49 minio #406

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ DB_PORT=5432
YANDEX_CLIENT_ID=
YANDEX_SECRET=
SENTRY_KEY=

S3_ACCESS_KEY=admin
S3_SECRET_KEY=password
# DJANGO_HOST=
2 changes: 2 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
env:
USE_MINIO_STORAGE: true
with:
path: src/.venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/src/poetry.lock') }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ data/**
.vscode/
.devcontainer/
*.code-workspace

### minio ###
s3_buckets/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ new:
run:
docker-compose up --detach --build

# Запуск с контейнером minio
run-with-minio:
docker-compose -f docker-compose.yml -f docker-compose.s3.yml up --detach --build

# Собирает статику
collect:
docker-compose exec backend python manage.py collectstatic --no-input
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'

services:
s3:
image: minio/minio:latest
container_name: s3
command: server --console-address ":9001" /data/
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ROOT_USER: ${S3_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
volumes:
- minio-storage:/data
networks:
- app_net

networks:
app_net:
external: true

volumes:
minio-storage:
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- pgdata:/var/lib/postgresql/data/
env_file:
- ./services/postgres/.env
networks:
- app_net

backend:
image: local/lizaalert_backend
Expand All @@ -19,6 +21,8 @@ services:
- ./src/tests:/app/tests
- ./static_volume:/app/static/
- ./media_volume:/app/media/
networks:
- app_net
depends_on:
- postgres

Expand All @@ -29,8 +33,14 @@ services:
- ./media_volume:/var/html/media/
ports:
- "8000:8000"
networks:
- app_net
depends_on:
- backend

networks:
app_net:
driver: bridge

volumes:
pgdata:
7 changes: 7 additions & 0 deletions services/nginx/site.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ server {
location /media/ {
alias /var/html/media/;
}
location /s3/ {
proxy_pass http://s3:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
32 changes: 26 additions & 6 deletions src/lizaalert/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"drf_yasg",
"corsheaders",
"django_filters",
"minio_storage",
# 3-rd party authentication apps
"djoser",
"allauth",
Expand Down Expand Up @@ -143,12 +144,6 @@

USE_TZ = True

STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")

MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

AUTH_USER_MODEL = "users.User"
Expand Down Expand Up @@ -212,3 +207,28 @@
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
)

STATIC_URL = "/static/"
STATIC_ROOT = "./static_files/"

DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
MINIO_STORAGE_ENDPOINT = "s3:9000"
MINIO_STORAGE_ACCESS_KEY = "admin"
MINIO_STORAGE_SECRET_KEY = "password"
MINIO_STORAGE_USE_HTTPS = False
MINIO_STORAGE_MEDIA_OBJECT_METADATA = {"Cache-Control": "max-age=1000"}
MINIO_STORAGE_MEDIA_BUCKET_NAME = "media"
MINIO_STORAGE_MEDIA_BACKUP_BUCKET = "Recycle Bin"
MINIO_STORAGE_MEDIA_BACKUP_FORMAT = "%c/"
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET = True
MINIO_STORAGE_STATIC_BUCKET_NAME = "static"
MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET = True
DJANGO_HOST = os.environ.get("DJANGO_HOST", "localhost")
MINIO_STORAGE_MEDIA_URL = f"http://{DJANGO_HOST}:9000/s3/"

if os.environ.get("USE_MINIO_STORAGE", "false") == "true":
DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
else:
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
624 changes: 359 additions & 265 deletions src/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ factory-boy = "^3.2.1"
django-filter = "^22.1"
djoser = "^2.1.0"
sentry-sdk = {extras = ["django"], version = "^1.39.2"}
django-minio-storage = "^0.5.7"

[tool.poetry.dev-dependencies]
flake8 = "^4.0.1"
Expand Down
Loading