switch to uv
This commit is contained in:
43
Dockerfile
43
Dockerfile
@@ -1,18 +1,13 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
## base image
|
||||
FROM python:3.12-slim as base
|
||||
FROM python:3.12-slim AS base
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
||||
PIP_DEFAULT_TIMEOUT=100 \
|
||||
POETRY_VERSION="1.8.3" \
|
||||
POETRY_HOME="/opt/poetry" \
|
||||
POETRY_NO_INTERACTION=1 \
|
||||
VENV_PATH="/opt/venv" \
|
||||
VENV_PATH="/opt/app/.venv" \
|
||||
APP_HOME="/opt/app"
|
||||
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
|
||||
ENV PATH="$VENV_PATH/bin:$PATH"
|
||||
ENV VIRTUAL_ENV=$VENV_PATH
|
||||
|
||||
RUN set -ex \
|
||||
@@ -23,7 +18,7 @@ RUN set -ex \
|
||||
|
||||
|
||||
## builder-base image
|
||||
FROM base as builder-base
|
||||
FROM base AS builder-base
|
||||
RUN apt-get update && \
|
||||
apt-get install --no-install-recommends -y \
|
||||
curl \
|
||||
@@ -32,32 +27,25 @@ RUN apt-get update && \
|
||||
python3-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache \
|
||||
curl -sSL https://install.python-poetry.org | python -
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.5.18 /uv /uvx /bin/
|
||||
|
||||
WORKDIR $APP_HOME
|
||||
COPY poetry.lock pyproject.toml ./
|
||||
COPY uv.lock pyproject.toml ./
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache \
|
||||
python -m venv $VENV_PATH && \
|
||||
poetry install --no-root --only=main
|
||||
RUN uv sync --frozen
|
||||
|
||||
COPY . .
|
||||
RUN --mount=type=cache,target=/root/.cache \
|
||||
poetry install --only-root
|
||||
|
||||
|
||||
## dev image
|
||||
FROM base as dev
|
||||
FROM base AS dev
|
||||
|
||||
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
|
||||
COPY --from=builder-base $VENV_PATH $VENV_PATH
|
||||
COPY --from=builder-base $APP_HOME $APP_HOME
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.5.18 /uv /uvx /bin/
|
||||
|
||||
WORKDIR $APP_HOME
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache \
|
||||
poetry install --with=dev && \
|
||||
RUN uv sync --frozen --dev && \
|
||||
rm -rf $APP_HOME
|
||||
|
||||
EXPOSE 8000
|
||||
@@ -67,22 +55,19 @@ CMD ["server", "--dev"]
|
||||
|
||||
|
||||
## ci image
|
||||
FROM base as ci
|
||||
FROM base AS ci
|
||||
|
||||
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
|
||||
COPY --from=builder-base $VENV_PATH $VENV_PATH
|
||||
COPY --from=builder-base $APP_HOME $APP_HOME
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.5.18 /uv /uvx /bin/
|
||||
|
||||
WORKDIR $APP_HOME
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache \
|
||||
poetry install --with=test
|
||||
RUN uv sync --frozen --group=test
|
||||
|
||||
|
||||
## prod image
|
||||
FROM base as prod
|
||||
FROM base AS prod
|
||||
|
||||
COPY --from=builder-base $VENV_PATH $VENV_PATH
|
||||
COPY --from=builder-base /opt/app /opt/app
|
||||
|
||||
WORKDIR $APP_HOME
|
||||
|
Reference in New Issue
Block a user