saas_api/Dockerfile
2025-12-08 12:51:01 -03:00

57 lines
1.6 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ==============================
# STAGE 1 Build das dependências
# ==============================
FROM python:3.12-slim AS builder
WORKDIR /app
# Copia apenas requirements para cache eficiente
COPY requirements.txt .
# Instala dependências necessárias apenas para build
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc libffi-dev libssl-dev python3-dev firebird-dev build-essential curl nano \
&& pip install --upgrade pip \
&& pip install --no-cache-dir --prefix=/install -r requirements.txt \
&& apt-get purge -y gcc build-essential python3-dev \
&& apt-get autoremove -y && rm -rf /var/lib/apt/lists/*
# ==============================
# STAGE 2 Runtime (produção)
# ==============================
# comnent´pario teste
FROM python:3.12-slim AS runtime
# Define diretório de trabalho
WORKDIR /app
# Copia dependências instaladas do estágio builder
COPY --from=builder /install /usr/local
# Copia o restante do código da aplicação
COPY . .
# Define timezone e ambiente
ENV TZ=America/Sao_Paulo \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
UVICORN_WORKERS=4 \
UVICORN_PORT=8000 \
UVICORN_HOST=0.0.0.0 \
GUNICORN_CMD_ARGS="--log-level info --timeout 60 --graceful-timeout 30 --keep-alive 10"
# Expõe a porta padrão do app
EXPOSE 8000
# ==============================
# Comando de inicialização
# (Gunicorn + Uvicorn Workers)
# ==============================
CMD ["sh", "-c", "\
gunicorn main:app \
--worker-class uvicorn.workers.UvicornWorker \
--workers ${UVICORN_WORKERS:-4} \
--bind ${UVICORN_HOST:-0.0.0.0}:${UVICORN_PORT:-8000} \
--access-logfile '-' \
--error-logfile '-' \
"]