-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (49 loc) · 1.94 KB
/
Dockerfile
File metadata and controls
64 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Multi-stage build
FROM python:3.12-slim AS base
ARG UV_VERSION=0.9.16
ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
# Keeps Python from generating .pyc files in the container
PYTHONDONTWRITEBYTECODE=1 \
# Turns off buffering for easier container logging
PYTHONUNBUFFERED=1
WORKDIR /app
FROM base AS builder
ENV UV_VERSION=${UV_VERSION} \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
# Disable Python downloads, because we want to use the system interpreter
# across both images. If using a managed Python version, it needs to be
# copied from the build image into the final image; see `standalone.Dockerfile`
# for an example.
ENV UV_PYTHON_DOWNLOADS=0
# Install uv
RUN pip install --no-cache-dir "uv==${UV_VERSION}"
ARG DEPENDENCY_INSTALL_OPTION="--no-dev"
# Install Python dependencies
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 ${DEPENDENCY_INSTALL_OPTION}
FROM base AS final
ENV UV_VERSION=${UV_VERSION} \
VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:${PATH}" \
PYTHONPATH="/app/src/"
WORKDIR /app
# Copy installed Python dependencies to final container
COPY --from=builder /app/.venv ${VIRTUAL_ENV}
# Copy your code into container
COPY src/ /app/src/
# This is needed to for running locally
ARG INSTALL_UV=false
RUN sh -c "if [ $INSTALL_UV = 'true' ] ; then pip install 'uv==$UV_VERSION' ; fi"
# Install Task for local development
ARG INSTALL_TASK=false
RUN sh -c "if [ $INSTALL_TASK = 'true' ] ; then \
python -c 'import urllib.request; urllib.request.urlretrieve(\"https://github.com/go-task/task/releases/download/v3.38.0/task_linux_amd64.tar.gz\", \"task_linux_amd64.tar.gz\")' && \
tar -zxf task_linux_amd64.tar.gz && \
mv task /usr/local/bin/task && \
chmod +x /usr/local/bin/task && \
rm task_linux_amd64.tar.gz ; \
fi"