Some checks failed
Workflow de prueba / Build and push images (push) Has been cancelled
58 lines
1.2 KiB
Docker
58 lines
1.2 KiB
Docker
# ---------------------------
|
||
# 1️⃣ Builder stage
|
||
# ---------------------------
|
||
FROM python:3.11-slim AS builder
|
||
|
||
ENV PYTHONDONTWRITEBYTECODE=1
|
||
ENV PYTHONUNBUFFERED=1
|
||
|
||
WORKDIR /app
|
||
|
||
# Solo herramientas necesarias para compilar dependencias
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
build-essential \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# Copiamos solo archivos de dependencias (mejor cache)
|
||
COPY pyproject.toml ./
|
||
|
||
# Generamos wheels
|
||
RUN pip install --upgrade pip && \
|
||
pip wheel --no-cache-dir --no-deps --wheel-dir /wheels .
|
||
|
||
|
||
# ---------------------------
|
||
# 2️⃣ Runtime stage
|
||
# ---------------------------
|
||
FROM python:3.11-slim
|
||
|
||
ENV PYTHONDONTWRITEBYTECODE=1
|
||
ENV PYTHONUNBUFFERED=1
|
||
|
||
WORKDIR /app
|
||
|
||
# Crear usuario no-root
|
||
RUN useradd --create-home appuser
|
||
|
||
# Copiar wheels desde builder
|
||
COPY --from=builder /wheels /wheels
|
||
|
||
# Instalar dependencias sin compilers
|
||
RUN pip install --upgrade pip && \
|
||
pip install --no-cache-dir /wheels/* && \
|
||
rm -rf /wheels
|
||
|
||
# Copiar código fuente
|
||
COPY . .
|
||
|
||
# Cambiar permisos
|
||
RUN chown -R appuser:appuser /app
|
||
|
||
USER appuser
|
||
|
||
ENV BASIC_AUTH_USERNAME=admin
|
||
ENV BASIC_AUTH_PASSWORD=admin
|
||
|
||
EXPOSE 8000
|
||
|
||
CMD ["uvicorn", "beyond_api.main:app", "--host", "0.0.0.0", "--port", "8000"] |