Skip to content

Commit

Permalink
Feature/s3 minio (#162)
Browse files Browse the repository at this point in the history
* added minio as s3 server-container

* added minio as s3 server-container

* added minio as s3 server-container

* added minio as s3 server-container

* updated env example

* updated cd
  • Loading branch information
blakkheart authored Apr 3, 2024
1 parent 4d806df commit 50b3593
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 36 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,3 @@ jobs:
sudo docker compose -f docker-compose.production.yml exec backend python manage.py collectstatic
sudo docker compose -f docker-compose.production.yml exec backend python manage.py migrate
sudo docker compose -f docker-compose.production.yml exec backend python manage.py loaddata fixture/achievements_fixture.json
sudo docker compose -f docker-compose.production.yml exec backend cp -r /app/static/. /backend_static/static/
5 changes: 1 addition & 4 deletions backend/api/v1/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import base64
import datetime
import re

from django.conf import settings
from django.core.files.base import ContentFile
Expand All @@ -27,6 +26,4 @@ def to_representation(self, value):
uri = self.context["request"].build_absolute_uri(
f"{settings.MEDIA_URL}{value}" if isinstance(value, str) else value.url
)
if set(settings.CSRF_TRUSTED_ORIGINS).issubset(("http://127.0.0.1", "http://localhost")):
return uri
return re.sub("http", "https", uri, 1)
return uri
6 changes: 3 additions & 3 deletions backend/templates/email/new-email.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<div style="max-width: 160px">
<img
alt="Logo."
src="https://running.myddns.me/media/email/logo1.png"
src="https://running.myddns.me:9000/running-app/media/email/logo1.png"
style="
display: block;
height: auto;
Expand Down Expand Up @@ -400,7 +400,7 @@
<div style="max-width: 640px">
<img
alt="Image of lock & key."
src="https://running.myddns.me/media/email/___passwordreset.gif"
src="https://running.myddns.me:9000/running-app/media/email/___passwordreset.gif"
style="
display: block;
height: auto;
Expand Down Expand Up @@ -715,7 +715,7 @@
>
<img
alt="Logo."
src="https://running.myddns.me/media/email/logo2.png"
src="https://running.myddns.me:9000/running-app/media/email/logo2.png"
style="
display: block;
height: auto;
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ services:

minio:
image: minio/minio:latest
hostname: running.myddns.me
environment:
- MINIO_SERVER_URL=https://running.myddns.me:9000
volumes:
- ./minio:/minio_files
- /home/capwell/diary-training/minio/certs/:/opt/minio/certs
env_file: .env
command: 'minio server /minio_files --console-address ":9001"'
command: 'minio server --certs-dir /opt/minio/certs /minio_files --console-address ":9001"'
ports:
- 9000:9000
- 9001:9001
Expand All @@ -82,7 +86,7 @@ services:
env_file: .env
entrypoint: >
/bin/sh -c "
/usr/bin/mc config host add --quiet --api s3v4 s3 http://minio:9000 minioadmin minioadmin;
/usr/bin/mc config host add --quiet --api s3v4 s3 https://running.myddns.me:9000 minioadmin minioadmin;
/usr/bin/mc mb --quiet s3/running-app;
/usr/bin/mc anonymous set public s3/running-app;
"
Expand Down
36 changes: 18 additions & 18 deletions docs/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:
paths:
/api/v1/achievements/:
get:
operationId: achievements_list
operationId: api_v1_achievements_list
description: Выводит список достижений
summary: Список достижений
tags:
Expand All @@ -24,7 +24,7 @@ paths:
description: ''
/api/v1/health/:
get:
operationId: health_retrieve
operationId: api_v1_health_retrieve
description: Проверка работы АПИ
summary: Проверка работы
tags:
Expand All @@ -41,7 +41,7 @@ paths:
description: ''
/api/v1/history/:
get:
operationId: history_list
operationId: api_v1_history_list
description: Выводит историю тренировок
summary: История тренировок
tags:
Expand All @@ -58,7 +58,7 @@ paths:
$ref: '#/components/schemas/History'
description: ''
post:
operationId: history_create
operationId: api_v1_history_create
description: Сохраняет выполненную тренировку
summary: Сохранение выполненной тренировки
tags:
Expand Down Expand Up @@ -88,9 +88,9 @@ paths:
description: ''
/api/v1/me/:
get:
operationId: me_retrieve
operationId: api_v1_me_retrieve
tags:
- me
- api
security:
- jwtAuth: []
responses:
Expand All @@ -101,9 +101,9 @@ paths:
$ref: '#/components/schemas/User'
description: ''
patch:
operationId: me_partial_update
operationId: api_v1_me_partial_update
tags:
- me
- api
requestBody:
content:
application/json:
Expand All @@ -125,19 +125,19 @@ paths:
$ref: '#/components/schemas/User'
description: ''
delete:
operationId: me_destroy
operationId: api_v1_me_destroy
tags:
- me
- api
security:
- jwtAuth: []
responses:
'204':
description: No response body
/api/v1/resend_code/:
post:
operationId: resend_code_create
operationId: api_v1_resend_code_create
tags:
- resend_code
- api
security:
- jwtAuth: []
- {}
Expand All @@ -146,9 +146,9 @@ paths:
description: No response body
/api/v1/token/refresh/:
post:
operationId: token_refresh_create
operationId: api_v1_token_refresh_create
tags:
- token
- api
requestBody:
content:
application/json:
Expand All @@ -173,7 +173,7 @@ paths:
description: ''
/api/v1/training/:
get:
operationId: training_list
operationId: api_v1_training_list
description: Выводит список тренировок
summary: Список тренировок
tags:
Expand All @@ -191,7 +191,7 @@ paths:
description: ''
/api/v1/update/:
post:
operationId: update_create
operationId: api_v1_update_create
description: Обновляет заморозки у пользователя и сохраняет часовой пояс
summary: Обновляет заморозки у пользователя и сохраняет часовой пояс
tags:
Expand All @@ -207,9 +207,9 @@ paths:
description: ''
/api/v1/user/:
post:
operationId: user_create
operationId: api_v1_user_create
tags:
- user
- api
requestBody:
content:
application/json:
Expand Down
20 changes: 14 additions & 6 deletions infra/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ EMAIL_USE_SSL=True
DEBUG=True


# s3 config
# S3 config with Minio
IS_AWS_ACTIVE=True
AWS_STORAGE_BUCKET_NAME='<YOUR_BUCKET_NAME>'
AWS_S3_ENDPOINT_URL='https://<YOUR_ACCOUNT_ID>.r2.cloudflarestorage.com'
AWS_S3_ACCESS_KEY_ID='<YOUR_ACCESS_KEY>'
AWS_S3_SECRET_ACCESS_KEY='<YOUR_SECRET_KEY>'
AWS_S3_SIGNATURE_VERSION='s3v4'
MINIO_ROOT_USER="<YOUR_LOGIN>"
MINIO_ROOT_PASSWORD="<YOUR_PASSWORD>"
MINIO_BUCKET_NAME="<YOUR_BUCKET_NAME>"
MINIO_ENDPOINT="<MINIO_ENDPOINT>"
MINIO_ACCESS_URL="<MINIO_ACCESS_URL>"
MINIO_STORAGE_USE_HTTPS=True
MINIO_S3_SECURE_URLS=True

AWS_S3_USE_SSL=True
AWS_S3_SECURE_URLS=True
AWS_S3_FILE_OVERWRITE=True
AWS_S3_URL_PROTOCOL="https:"
AWS_S3_SIGNATURE_VERSION="s3v4"
4 changes: 2 additions & 2 deletions test/api_tests/throttling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def code_user():
@pytest.fixture
def alternative_throttling_settings():
settings.ACCESS_RESTORE_CODE_THROTTLING = {
"duration": timedelta(milliseconds=200),
"duration": timedelta(milliseconds=300),
"num_requests": 3,
"cooldown": timedelta(milliseconds=200),
"cooldown": timedelta(milliseconds=300),
}


Expand Down

0 comments on commit 50b3593

Please sign in to comment.