Refactor Docker setup for environment flexibility and dev support

Moved environment variables to .env.template for better management and updated docker-compose files to use them. Added separate docker-compose.dev.yml for development, a Makefile for streamlined commands, and split backend Dockerfile into development and production stages. Updated .gitignore to include new changes.
This commit is contained in:
2025-02-27 13:23:14 +01:00
parent 03f4792232
commit d283f3a3ed
6 changed files with 162 additions and 56 deletions

View File

@@ -1,37 +1,34 @@
# Use Python 3.12 as the base image
FROM python:3.12-slim
# Set working directory
# Development stage
FROM python:3.12-slim AS development
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc postgresql-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Set up entrypoint script
# Note: entrypoint.sh is at the root of the backend directory, not in a scripts folder
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
# Expose port
EXPOSE 8000
# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# Default command
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# Production stage
FROM python:3.12-slim AS production
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app
RUN apt-get update && \
apt-get install -y --no-install-recommends postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]