Compare commits

..

1 Commits

Author SHA1 Message Date
leo 78b81b9e3c ♻️(backend) factorize s3 client creation in utils
Factorize s3 client creation in utils for code simplification.
2026-08-25 16:55:25 +02:00
5 changed files with 44 additions and 86 deletions
-1
View File
@@ -18,7 +18,6 @@ and this project adheres to
- ⬆️(frontend) upgrade @tanstack/react-query from 5.101.1 to 5.101.4 - ⬆️(frontend) upgrade @tanstack/react-query from 5.101.1 to 5.101.4
- ⬆️(frontend) upgrade @pandacss/preset-panda from 1.11.3 to 1.12.0 - ⬆️(frontend) upgrade @pandacss/preset-panda from 1.11.3 to 1.12.0
- ⬆️(frontend) upgrade posthog-js from 1.404.1 to 1.409.5 - ⬆️(frontend) upgrade posthog-js from 1.404.1 to 1.409.5
- 🩹(makefile) change target of lint to also cover summary and agents
## [1.28.0] - 2026-08-24 ## [1.28.0] - 2026-08-24
+16 -41
View File
@@ -39,16 +39,14 @@ DB_PORT = 5432
DOCKER_UID = $(shell id -u) DOCKER_UID = $(shell id -u)
DOCKER_GID = $(shell id -g) DOCKER_GID = $(shell id -g)
DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID) DOCKER_USER = $(DOCKER_UID):$(DOCKER_GID)
COMPOSE = DOCKER_USER=$(DOCKER_USER) docker compose COMPOSE = DOCKER_USER=$(DOCKER_USER) docker compose
COMPOSE_EXEC = $(COMPOSE) exec COMPOSE_EXEC = $(COMPOSE) exec
COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev
COMPOSE_RUN = $(COMPOSE) run --rm COMPOSE_RUN = $(COMPOSE) run --rm
COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev
COMPOSE_RUN_LINT_BACK = $(COMPOSE_RUN) --no-deps app-dev COMPOSE_RUN_LINT = $(COMPOSE_RUN) --no-deps app-dev
COMPOSE_RUN_LINT_AGENTS = $(COMPOSE_RUN) --no-deps multi-user-transcriber-dev COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin
COMPOSE_RUN_LINT_SUMMARY = $(COMPOSE_RUN) --no-deps app-summary-dev WAIT_DB = @$(COMPOSE_RUN) dockerize -wait tcp://$(DB_HOST):$(DB_PORT) -timeout 60s
COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin
WAIT_DB = @$(COMPOSE_RUN) dockerize -wait tcp://$(DB_HOST):$(DB_PORT) -timeout 60s
# -- Backend # -- Backend
MANAGE = $(COMPOSE_RUN_APP) python manage.py MANAGE = $(COMPOSE_RUN_APP) python manage.py
@@ -58,13 +56,9 @@ MAIL_NPM = $(COMPOSE_RUN) -w /app/src/mail node npm
LINT_RUFF_FORMAT = ruff format . LINT_RUFF_FORMAT = ruff format .
LINT_RUFF_CHECK = ruff check . --fix LINT_RUFF_CHECK = ruff check . --fix
LINT_PYLINT = pylint meet demo core LINT_PYLINT = pylint meet demo core
LINT_BACK = echo 'lint:back:ruff-format started…' && $(LINT_RUFF_FORMAT) \ LINT_BACK = echo 'lint:ruff-format started…' && $(LINT_RUFF_FORMAT) \
&& echo 'lint:back:ruff-check started…' && $(LINT_RUFF_CHECK) \ && echo 'lint:ruff-check started…' && $(LINT_RUFF_CHECK) \
&& echo 'lint:back:pylint started…' && $(LINT_PYLINT) && echo 'lint:pylint started…' && $(LINT_PYLINT)
LINT_AGENTS = echo 'lint:agents:ruff-format started…' && $(LINT_RUFF_FORMAT) \
&& echo 'lint:agents:ruff-check started…' && $(LINT_RUFF_CHECK)
LINT_SUMMARY = echo 'lint:summary:ruff-format started…' && $(LINT_RUFF_FORMAT) \
&& echo 'lint:summary:ruff-check started…' && $(LINT_RUFF_CHECK)
# -- Frontend # -- Frontend
PATH_FRONT = ./src/frontend PATH_FRONT = ./src/frontend
@@ -113,7 +107,6 @@ build: ## build the project containers
@$(MAKE) build-backend @$(MAKE) build-backend
@$(MAKE) build-frontend @$(MAKE) build-frontend
@$(MAKE) build-agents @$(MAKE) build-agents
@$(MAKE) build-summary
.PHONY: build .PHONY: build
build-backend: ## build the app-dev container build-backend: ## build the app-dev container
@@ -129,10 +122,6 @@ build-agents: ## build the multi-user-transcriber agent container
@$(COMPOSE) build multi-user-transcriber-dev @$(COMPOSE) build multi-user-transcriber-dev
.PHONY: build-agents .PHONY: build-agents
build-summary: ## build the app-summary-dev container
@$(COMPOSE) build app-summary-dev
.PHONY: build-summary
down: ## stop and remove containers, networks, images, and volumes down: ## stop and remove containers, networks, images, and volumes
@$(COMPOSE) down @$(COMPOSE) down
.PHONY: down .PHONY: down
@@ -209,37 +198,23 @@ demo: ## flush db then create a demo for load testing purpose
@$(MANAGE) create_demo @$(MANAGE) create_demo
.PHONY: demo .PHONY: demo
lint: ## lint all python sources (back-end, agents, summary) lint: ## lint back-end python sources
@$(MAKE) lint-back @$(COMPOSE_RUN_LINT) sh -c "$(LINT_BACK)"
@$(MAKE) lint-agents
@$(MAKE) lint-summary
.PHONY: lint .PHONY: lint
lint-back: ## lint back-end python sources
@$(COMPOSE_RUN_LINT_BACK) sh -c "$(LINT_BACK)"
.PHONY: lint-back
lint-agents: ## lint agents python sources
@$(COMPOSE_RUN_LINT_AGENTS) sh -c "$(LINT_AGENTS)"
.PHONY: lint-agents
lint-summary: ## lint summary python sources
@$(COMPOSE_RUN_LINT_SUMMARY) sh -c "$(LINT_SUMMARY)"
.PHONY: lint-summary
lint-ruff-format: ## format back-end python sources with ruff lint-ruff-format: ## format back-end python sources with ruff
@echo 'lint:ruff-format started…' @echo 'lint:ruff-format started…'
@$(COMPOSE_RUN_LINT_BACK) $(LINT_RUFF_FORMAT) @$(COMPOSE_RUN_LINT) $(LINT_RUFF_FORMAT)
.PHONY: lint-ruff-format .PHONY: lint-ruff-format
lint-ruff-check: ## lint back-end python sources with ruff lint-ruff-check: ## lint back-end python sources with ruff
@echo 'lint:ruff-check started…' @echo 'lint:ruff-check started…'
@$(COMPOSE_RUN_LINT_BACK) $(LINT_RUFF_CHECK) @$(COMPOSE_RUN_LINT) $(LINT_RUFF_CHECK)
.PHONY: lint-ruff-check .PHONY: lint-ruff-check
lint-pylint: ## lint back-end python sources with pylint only on changed files from main lint-pylint: ## lint back-end python sources with pylint only on changed files from main
@echo 'lint:pylint started…' @echo 'lint:pylint started…'
@$(COMPOSE_RUN_LINT_BACK) $(LINT_PYLINT) @$(COMPOSE_RUN_LINT) $(LINT_PYLINT)
.PHONY: lint-pylint .PHONY: lint-pylint
test: ## run project tests; pass extra pytest args via ARGS, e.g. `make test ARGS="-vv"` test: ## run project tests; pass extra pytest args via ARGS, e.g. `make test ARGS="-vv"`
-2
View File
@@ -249,7 +249,6 @@ services:
build: build:
context: ./src/agents context: ./src/agents
target: development target: development
user: ${DOCKER_USER:-1000}
command: ["python", "metadata_collector.py", "dev"] command: ["python", "metadata_collector.py", "dev"]
env_file: env_file:
- env.d/development/metadata_collector - env.d/development/metadata_collector
@@ -268,7 +267,6 @@ services:
build: build:
context: ./src/agents context: ./src/agents
target: development target: development
user: ${DOCKER_USER:-1000}
env_file: env_file:
- env.d/development/multi_user_transcriber - env.d/development/multi_user_transcriber
volumes: volumes:
+27 -40
View File
@@ -381,6 +381,31 @@ def detect_mimetype(file_buffer: bytes, filename: str | None = None) -> str:
return mimetype_from_content or "application/octet-stream" return mimetype_from_content or "application/octet-stream"
def _get_s3_client(*, override_domain: bool = True):
"""Return an S3 client, honoring the AWS_S3_DOMAIN_REPLACE endpoint override.
AWS_S3_DOMAIN_REPLACE is used when the backend and frontend reach object
storage under different domains (this is the case in the docker compose stack
used in development: the frontend connects to the object storage on localhost
while the backend uses the object storage service name declared in the stack).
The domain name is used to compute the signature, so it can't be changed
dynamically by the frontend; we build a dedicated boto3 client pointed at that
endpoint. Otherwise we reuse the default storage client.
"""
if settings.AWS_S3_DOMAIN_REPLACE and override_domain:
return boto3.client(
"s3",
aws_access_key_id=settings.AWS_S3_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_S3_SECRET_ACCESS_KEY,
endpoint_url=settings.AWS_S3_DOMAIN_REPLACE,
config=botocore.client.Config(
region_name=settings.AWS_S3_REGION_NAME,
signature_version=settings.AWS_S3_SIGNATURE_VERSION,
),
)
return default_storage.connection.meta.client
def generate_upload_policy(file): def generate_upload_policy(file):
""" """
Generate a S3 upload policy for a given file. Generate a S3 upload policy for a given file.
@@ -391,26 +416,7 @@ def generate_upload_policy(file):
key = file.temporary_file_key key = file.temporary_file_key
# This settings should be used if the backend application and the frontend application s3_client = _get_s3_client()
# can't connect to the object storage with the same domain. This is the case in the
# docker compose stack used in development. The frontend application will use localhost
# to connect to the object storage while the backend application will use the object storage
# service name declared in the docker compose stack.
# This is needed because the domain name is used to compute the signature. So it can't be
# changed dynamically by the frontend application.
if settings.AWS_S3_DOMAIN_REPLACE:
s3_client = boto3.client(
"s3",
aws_access_key_id=settings.AWS_S3_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_S3_SECRET_ACCESS_KEY,
endpoint_url=settings.AWS_S3_DOMAIN_REPLACE,
config=botocore.client.Config(
region_name=settings.AWS_S3_REGION_NAME,
signature_version=settings.AWS_S3_SIGNATURE_VERSION,
),
)
else:
s3_client = default_storage.connection.meta.client
# Generate the policy # Generate the policy
policy = s3_client.generate_presigned_url( policy = s3_client.generate_presigned_url(
@@ -431,26 +437,7 @@ def generate_download_s3_url(
if not key: if not key:
raise ValueError("key cannot be empty") raise ValueError("key cannot be empty")
# This setting should be used if the backend application and the frontend application s3_client = _get_s3_client(override_domain=override_domain)
# can't connect to the object storage with the same domain. This is the case in the
# docker compose stack used in development. The frontend application will use localhost
# to connect to the object storage while the backend application will use the object storage
# service name declared in the docker compose stack.
# This is needed because the domain name is used to compute the signature. So it can't be
# changed dynamically by the frontend application.
if settings.AWS_S3_DOMAIN_REPLACE and override_domain:
s3_client = boto3.client(
"s3",
aws_access_key_id=settings.AWS_S3_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_S3_SECRET_ACCESS_KEY,
endpoint_url=settings.AWS_S3_DOMAIN_REPLACE,
config=botocore.client.Config(
region_name=settings.AWS_S3_REGION_NAME,
signature_version=settings.AWS_S3_SIGNATURE_VERSION,
),
)
else:
s3_client = default_storage.connection.meta.client
return s3_client.generate_presigned_url( return s3_client.generate_presigned_url(
ClientMethod="get_object", ClientMethod="get_object",
+1 -2
View File
@@ -17,8 +17,7 @@ FROM base AS development
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN pip install --no-cache-dir -e ".[dev]" || pip install --no-cache-dir -e .
RUN pip install --no-cache-dir -e ".[dev]"
CMD ["uvicorn", "summary.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] CMD ["uvicorn", "summary.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]