deploy(Dockerfile): Ajusta o dockerfile para deploy
This commit is contained in:
parent
910f08b0a6
commit
c9c0741ecc
1 changed files with 16 additions and 56 deletions
72
Dockerfile
72
Dockerfile
|
|
@ -1,66 +1,26 @@
|
|||
# ==============================
|
||||
# STAGE 1 – Build das dependências
|
||||
# ==============================
|
||||
FROM python:3.12-slim AS builder
|
||||
# Usa a imagem oficial do Python
|
||||
FROM python:3.12-slim
|
||||
|
||||
# Define diretório de trabalho no container
|
||||
WORKDIR /app
|
||||
|
||||
# Copia apenas requirements para cache eficiente
|
||||
# Copia o arquivo de dependências
|
||||
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 \
|
||||
# Instala dependências no sistema e no Python
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc libffi-dev libssl-dev python3-dev firebird-dev \
|
||||
&& 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)
|
||||
# ==============================
|
||||
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 todo o código do projeto
|
||||
COPY . .
|
||||
|
||||
# Define timezone e variáveis de ambiente padrão
|
||||
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"
|
||||
|
||||
# Instala utilitários para debug e health checks
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends curl nano \
|
||||
&& pip install --no-cache-dir -r requirements.txt \
|
||||
&& apt-get remove -y gcc \
|
||||
&& apt-get autoremove -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Expõe a porta padrão do app
|
||||
# Copia o restante do projeto para o container
|
||||
COPY . .
|
||||
|
||||
# Expõe a porta padrão do Uvicorn/FastAPI
|
||||
EXPOSE 8000
|
||||
|
||||
# # ==============================
|
||||
# # HEALTHCHECK automático
|
||||
# # ==============================
|
||||
# HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
# CMD curl -f http://localhost:8000/health || exit 1
|
||||
|
||||
# ==============================
|
||||
# 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 '-' \
|
||||
"]
|
||||
# Comando para iniciar o servidor
|
||||
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 8000"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue