Skip to content

Commit

Permalink
build(python): only install uv at Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 21, 2024
1 parent 4c9410b commit 4212835
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions template/py/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ ENV PATH="/root/.cargo/bin:$PATH" \
PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"

# Install uv and tools
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
uv tool install hatch && \
uv tool install ruff
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

WORKDIR /app

COPY pyproject.toml .

# Create and install dependencies in the virtual environment
RUN uv venv venv && \
. venv/bin/activate && \
uv pip install .[dev]
RUN uv sync

# Separate stage for validation (build and test)
FROM builder AS validator
Expand All @@ -25,22 +21,21 @@ WORKDIR /app
COPY . .

# Run build and test as part of the validation
RUN hatch build && hatch test
RUN make build && make test

# Final image for running the application
FROM python:{{cookiecutter.python_version}}-slim-bullseye

LABEL author="{{cookiecutter.full_name}}"

ENV PATH="/app/venv/bin:/root/.local/bin:$PATH" \
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /app

# Copy the virtual environment and application code
COPY --from=builder /app/venv /app/venv
COPY --from=builder /root/.local /root/.local
COPY --from=builder /app/.venv /app/.venv
COPY src ./src

HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
Expand Down

0 comments on commit 4212835

Please sign in to comment.