From a51b18e8f5f61d2ba9dd5b6fc9352be83e97e6db Mon Sep 17 00:00:00 2001 From: mohamad Date: Sun, 1 Jun 2025 15:41:42 +0200 Subject: [PATCH] refactor: Update Docker configurations for improved environment variable handling - Changed the frontend Dockerfile to use process.env for environment variables instead of direct interpolation. - Updated the production Docker Compose file to set environment variables directly instead of using build args. - Switched the backend Dockerfile base image from `python:3.11-slim` to `python:alpine` for a smaller image size and increased worker count from 4 to 8 for better performance. --- be/Dockerfile.prod | 5 ++--- docker-compose.prod.yml | 6 +++--- fe/Dockerfile.prod | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/be/Dockerfile.prod b/be/Dockerfile.prod index 758027a..12631b9 100644 --- a/be/Dockerfile.prod +++ b/be/Dockerfile.prod @@ -1,5 +1,5 @@ # Multi-stage build for production -FROM python:3.11-slim as base +FROM python:alpine as base # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ @@ -58,7 +58,6 @@ EXPOSE 8000 CMD ["uvicorn", "app.main:app", \ "--host", "0.0.0.0", \ "--port", "8000", \ - "--workers", "4", \ - "--worker-class", "uvicorn.workers.UvicornWorker", \ + "--workers", "8", \ "--access-log", \ "--log-level", "info"] \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index e9935ec..1ac4f7c 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -66,9 +66,9 @@ services: context: ./fe dockerfile: Dockerfile.prod target: production - args: - - VITE_API_URL=${VITE_API_URL} - - VITE_SENTRY_DSN=${VITE_SENTRY_DSN} + environment: + - VITE_API_URL=${VITE_API_URL} + - VITE_SENTRY_DSN=${VITE_SENTRY_DSN} ports: - "80:3000" networks: diff --git a/fe/Dockerfile.prod b/fe/Dockerfile.prod index a0c2320..8022cb2 100644 --- a/fe/Dockerfile.prod +++ b/fe/Dockerfile.prod @@ -53,9 +53,9 @@ RUN echo '{ \n "rewrites": [ \n { "source": "**", "destination": "/index.htm RUN echo '#!/bin/sh\n\ cat > /app/env-config.js << EOL\n\ window.ENV = {\n\ - VITE_API_URL: "${VITE_API_URL}",\n\ - VITE_SENTRY_DSN: "${VITE_SENTRY_DSN}",\n\ - VITE_ROUTER_MODE: "${VITE_ROUTER_MODE}"\n\ + VITE_API_URL: process.env.VITE_API_URL,\n\ + VITE_SENTRY_DSN: process.env.VITE_SENTRY_DSN,\n\ + VITE_ROUTER_MODE: process.env.VITE_ROUTER_MODE\n\ };\n\ EOL\n\ serve -s . -l 3000' > /app/start.sh && chmod +x /app/start.sh