Skip to content

Commit

Permalink
feat: add uv support to dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Nov 26, 2024
1 parent 700e7b0 commit a5a3a5f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions {{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
{% if cookiecutter.dependency_management_tool == "uv" -%}
FROM ghcr.io/astral-sh/uv:python{{ cookiecutter.python_version }}-bookworm-slim AS builder

ARG USERNAME={{ cookiecutter.github_username.lower().replace(' ', '_').replace('-', '_') }}

ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

RUN useradd --create-home $USERNAME
USER $USERNAME
WORKDIR /app/$USERNAME

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev

COPY . /app/$USERNAME

RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev


FROM python{{ cookiecutter.python_version }}-slim-bookworm

RUN useradd --create-home $USERNAME
USER $USERNAME
WORKDIR /app/$USERNAME

COPY --from=builder --chown=$USERNAME:$USERNAME /app/$USERNAME /app/$USERNAME

ENV PYTHONUNBUFFERED=1 \
PYTHONFAULTHANDLER=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/app/$USERNAME/.venv/bin:$PATH"

COPY . /app/$USERNAME/
{%- else %}
FROM python:{{ cookiecutter.python_version }}-slim-stretch

ARG USERNAME={{ cookiecutter.github_username.lower().replace(' ', '_').replace('-', '_') }}
Expand All @@ -15,3 +52,4 @@ COPY . /home/$USERNAME/

RUN python3 -m pip install--no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir -r requirements.txt
{%- endif %}

0 comments on commit a5a3a5f

Please sign in to comment.