My deploys keeps exiting with this error: Exited with status 128. I don’t know why and I have tried everything and it just keeps failing
# ========================
# Stage 1: Builder
# ========================
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
libcairo2-dev \
python3-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy dependency file and install dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
# ========================
# Stage 2: Production Image
# ========================
FROM python:3.11-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libcairo2 \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Create a non-privileged user and set up directory
RUN useradd -m -r appuser && \
mkdir -p /app && \
chown appuser:appuser /app
WORKDIR /app
# Copy Python installation and packages
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Copy application code with proper ownership
COPY --chown=appuser:appuser . .
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
# Switch to non-root user
USER appuser
# Expose the application port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/', timeout=2)" || exit 1
# Run the FastAPI application
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--log-level", "info", "--access-logfile", "-", "--error-logfile", "-", "--capture-output", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "app.main:app"]