Files
BeyondCXAnalytics-Demo/backend/Dockerfile
Guillermo d6db3d3e70
All checks were successful
Workflow de prueba / Build and push images (push) Successful in 1m39s
trying to reduce image size 2 fix typo
2026-02-15 11:28:20 +00:00

54 lines
1.6 KiB
Docker

# ---------------------------
# Builder stage
# ---------------------------
FROM python:3.11-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Solo para compilar dependencias
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copiamos archivos de dependencias primero (mejor cache)
COPY pyproject.toml ./
# Creamos wheels (más limpio para producción)
#RUN pip install --upgrade pip && \
# pip wheel --no-cache-dir --no-deps --wheel-dir /wheels .
RUN pip install --upgrade pip && \
pip install --prefix=/install --no-warn-script-location .
RUN find /install -type d -name '__pycache__' -exec rm -rf {} + && \
find /install -type f -name '*.pyc' -delete && \
find /install -type f -name '*.pyo' -delete
# ---------------------------
# Runtime stage
# ---------------------------
FROM python:3.11-alpine
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/usr/local
WORKDIR /app
# Crear usuario no-root (mejor seguridad)
#RUN useradd --create-home appuser
# Copiar wheels generados
#COPY --from=builder /wheels /wheels
# Instalar dependencias sin herramientas de compilación
#RUN pip install --upgrade pip && \
# pip install --no-cache-dir /wheels/* && \
# rm -rf /wheels
# Copiar código
#COPY . .
# Cambiar propietario
RUN apk add --no-cache libstdc++ libgcc && \
adduser -D -h /app appuser
COPY --from=builder /install /usr/local
RUN chown -R appuser:appuser /app
USER appuser
ENV BASIC_AUTH_USERNAME=admin
ENV BASIC_AUTH_PASSWORD=admin
EXPOSE 8000