WIP proxy #3
@@ -1,45 +1,54 @@
|
|||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# Builder stage
|
# Builder stage
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
FROM python:3.11-slim AS builder
|
FROM python:3.11-slim AS builder
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
WORKDIR /app
|
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 .
|
||||||
|
|
||||||
# Instalar uv (más rápido que pip)
|
RUN pip install --upgrade pip && \
|
||||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
pip install --prefix=/install --no-warn-script-location .
|
||||||
|
|
||||||
ENV UV_COMPILE_BYTECODE=1 \
|
RUN find /install -type d -name '__pycache__' -exec rm -rf {} + && \
|
||||||
UV_LINK_MODE=copy
|
find /install -type f -name '*.pyc' -delete && \
|
||||||
|
find /install -type f -name '*.pyo' -delete
|
||||||
COPY pyproject.toml uv.lock* ./
|
|
||||||
|
|
||||||
# Instalar dependencias con uv
|
|
||||||
RUN uv sync --frozen --no-install-project --no-dev
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
FROM python:3.11-alpine
|
FROM python:3.11-alpine
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONUNBUFFERED=1
|
||||||
PYTHONUNBUFFERED=1 \
|
ENV PYTHONPATH=/usr/local
|
||||||
PATH="/app/.venv/bin:$PATH"
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
# Crear usuario no-root (mejor seguridad)
|
||||||
RUN apk add --no-cache libstdc++ && \
|
#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
|
adduser -D -h /app appuser
|
||||||
|
|
||||||
# Copiar virtualenv
|
COPY --from=builder /install /usr/local
|
||||||
COPY --from=builder /app/.venv /app/.venv
|
|
||||||
|
|
||||||
# Copiar código
|
|
||||||
COPY --chown=appuser:appuser ./backend ./backend
|
|
||||||
#COPY --chown=appuser:appuser ./main.py* ./app.py* ./
|
|
||||||
|
|
||||||
|
RUN chown -R appuser:appuser /app
|
||||||
USER appuser
|
USER appuser
|
||||||
|
ENV BASIC_AUTH_USERNAME=admin
|
||||||
EXPOSE 8000
|
ENV BASIC_AUTH_PASSWORD=admin
|
||||||
|
EXPOSE 8000
|
||||||
CMD ["uvicorn", "beyond_api.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
||||||
Reference in New Issue
Block a user