|
1 | | -# Stage 1: Build dependencies |
| 1 | +# Stage 1: Build Python dependencies |
2 | 2 | FROM python:3.10-alpine AS build |
3 | | -COPY requirements.txt . |
| 3 | +WORKDIR /api/app |
| 4 | + |
| 5 | +# Install build dependencies for psycopg2 |
| 6 | +RUN apk add --no-cache gcc musl-dev postgresql-dev |
| 7 | + |
| 8 | +# Copy requirements and install dependencies |
| 9 | +COPY requirements.txt ./ |
4 | 10 | RUN pip install --user --no-cache-dir -r requirements.txt \ |
5 | | - && find /root/.local -name '*.pyc' -delete \ |
6 | | - && find /root/.local -name '__pycache__' -delete |
| 11 | + && find /root/.local -name '*.pyc' -delete \ |
| 12 | + && find /root/.local -name '__pycache__' -delete |
7 | 13 |
|
8 | | -# Stage 2: Main app |
| 14 | +# Stage 2: Main application image |
9 | 15 | FROM python:3.10-alpine AS main |
10 | | -WORKDIR /app |
| 16 | +WORKDIR /api |
| 17 | + |
| 18 | +# Install PostgreSQL client for pg_isready |
| 19 | +RUN apk add --no-cache postgresql-client |
| 20 | + |
| 21 | +# Copy installed Python packages from build stage |
11 | 22 | COPY --from=build /root/.local /root/.local |
12 | | -COPY . . |
| 23 | + |
| 24 | +# Copy the entire app folder |
| 25 | +COPY . ./app |
| 26 | + |
| 27 | +# Add pip binaries to PATH |
13 | 28 | ENV PATH=/root/.local/bin:$PATH |
14 | | -ENV FLASK_APP=wsgi.py |
| 29 | +ENV FLASK_APP=app/wsgi.py |
| 30 | + |
| 31 | +# Expose port |
15 | 32 | EXPOSE 5000 |
16 | 33 |
|
17 | | -# Use Gunicorn instead of Flask dev server |
18 | | -CMD ["gunicorn", "--bind", "0.0.0.0:5000", "wsgi:app", "--workers", "2"] |
| 34 | +# Start Gunicorn server |
| 35 | +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app.wsgi:app", "--workers", "2"] |
0 commit comments