Skip to content

Commit

Permalink
feat: update python Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 17, 2024
1 parent ed2c1b1 commit 0bfeb9d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions template/py/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM python:{{cookiecutter.python_version}}-bullseye AS venv
# Base image for building the virtual environment
FROM python:{{cookiecutter.python_version}}-bullseye AS builder

ENV PATH="/root/.cargo/bin:$PATH" \
PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"

ENV PATH="/root/.cargo/bin/:$PATH"
ENV PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
uv tool install hatch && \
uv tool install ruff
Expand All @@ -14,25 +16,21 @@ RUN uv venv venv && \
. venv/bin/activate && \
uv pip install .[dev]


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

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

COPY --from=venv /app/venv /app/venv
COPY --from=venv /root/.local/bin/hatch /root/.local/bin/hatch
COPY --from=venv /root/.local/bin/ruff /root/.local/bin/ruff
ENV PATH="/app/venv/bin:$PATH"
ENV PATH="/root/.local/bin/:$PATH"
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PATH="/app/venv/bin:/root/.local/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /app

# if something you want ignore it, add it to .dockerignore
COPY --from=builder /app/venv /app/venv
COPY --from=builder /root/.local /root/.local
COPY . .

RUN hatch build && hatch test

# CMD . .venv/bin/activate && python src/app.py
CMD python src/app.py
CMD ["python", "src/app.py"]

0 comments on commit 0bfeb9d

Please sign in to comment.