
- Introduced `docker-compose.prod.yml` to define services for production deployment, including PostgreSQL, FastAPI backend, frontend, and Redis. - Created `env.production.template` to outline necessary environment variables for production, ensuring sensitive data is not committed. - Added `PRODUCTION.md` as a deployment guide detailing the setup process using Docker Compose and Gitea Actions for CI/CD. - Implemented Gitea workflows for build, test, and deployment processes to streamline production updates. - Updated backend and frontend Dockerfiles for optimized production builds and configurations. - Enhanced application settings to support environment-specific configurations, including CORS and health checks.
64 lines
1.5 KiB
Docker
64 lines
1.5 KiB
Docker
# Multi-stage build for production
|
|
FROM python:3.11-slim as base
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONHASHSEED=random \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
build-essential \
|
|
libpq-dev \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create non-root user
|
|
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
|
|
|
# Development stage
|
|
FROM base as development
|
|
WORKDIR /app
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
COPY . .
|
|
RUN chown -R appuser:appuser /app
|
|
USER appuser
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
|
|
|
# Production stage
|
|
FROM base as production
|
|
WORKDIR /app
|
|
|
|
# Install production dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create necessary directories and set permissions
|
|
RUN mkdir -p /app/logs && \
|
|
chown -R appuser:appuser /app
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Production command with optimizations
|
|
CMD ["uvicorn", "app.main:app", \
|
|
"--host", "0.0.0.0", \
|
|
"--port", "8000", \
|
|
"--workers", "4", \
|
|
"--worker-class", "uvicorn.workers.UvicornWorker", \
|
|
"--access-log", \
|
|
"--log-level", "info"] |