-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathDockerfile
More file actions
203 lines (159 loc) · 7.25 KB
/
Dockerfile
File metadata and controls
203 lines (159 loc) · 7.25 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# The version of Python in the final image
ARG PYTHON_VERSION=3.10
# The base image to use for the final image; Prefect and its Python requirements will
# be installed in this image. The default is the official Python slim image.
# The following images are also available in this file:
# prefect-conda: Derivative of continuum/miniconda3 with a 'prefect' environment. Used for the 'conda' flavor.
# Any image tag can be used, but it must have apt and pip.
ARG BASE_IMAGE=python:${PYTHON_VERSION}-slim
# The version used to build the Python distributable.
ARG BUILD_PYTHON_VERSION=3.10
# The version used to build the V1 UI distributable.
ARG NODE_VERSION=20.19.0
# The version used to build the V2 UI distributable (requires Node 22+).
ARG NODE_V2_VERSION=22.12.0
# SQLite version — must match the tag published to prefecthq/prefect-sqlite on DockerHub
# See Dockerfile.sqlite-builder and .github/workflows/sqlite-builder.yaml
ARG SQLITE_VERSION=3.50.4
# Any extra Python requirements to install
ARG EXTRA_PIP_PACKAGES=""
# Pull pre-compiled SQLite binaries (built by .github/workflows/sqlite-builder.yaml).
# This avoids compiling SQLite from source on every build.
# To publish a new version: bump SQLITE_VERSION and run the sqlite-builder workflow.
FROM prefecthq/prefect-sqlite:${SQLITE_VERSION} AS sqlite-builder
# Build the V1 UI distributable.
FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-bullseye-slim AS ui-builder
WORKDIR /opt/ui
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install --no-install-recommends -y \
# Required for arm64 builds
chromium \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install dependencies separately so they cache
COPY ./ui/package*.json ./
RUN npm ci
# Build static UI files
COPY ./ui .
RUN npm run build
# Build the V2 UI distributable.
FROM --platform=$BUILDPLATFORM node:${NODE_V2_VERSION}-bullseye-slim AS ui-v2-builder
# Optional Amplitude API key for analytics (build still works without it)
ARG VITE_AMPLITUDE_API_KEY=""
ENV VITE_AMPLITUDE_API_KEY=$VITE_AMPLITUDE_API_KEY
WORKDIR /opt/ui-v2
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install --no-install-recommends -y \
# Required for arm64 builds
chromium \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install dependencies separately so they cache
COPY ./ui-v2/package*.json ./
RUN npm ci
# Build static UI files
COPY ./ui-v2 .
RUN npm run build
# Build the Python distributable.
# Without this build step, versioningit cannot infer the version without git
FROM python:${BUILD_PYTHON_VERSION}-slim AS python-builder
WORKDIR /opt/prefect
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install --no-install-recommends -y \
gpg \
git=1:2.* \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' git)" ge '1:2.47.3' || \
(echo "ERROR: git version must be >= 1:2.47.3" && exit 1)
# Install UV from official image - pin to specific version for build caching
COPY --from=ghcr.io/astral-sh/uv:0.6.17 /uv /bin/uv
# Copy the repository in; requires full git history for versions to generate correctly
COPY . ./
# Package the V1 UI into the distributable.
COPY --from=ui-builder /opt/ui/dist ./src/prefect/server/ui
# Package the V2 UI into the distributable.
COPY --from=ui-v2-builder /opt/ui-v2/dist ./src/prefect/server/ui-v2
# Create a source distributable archive; ensuring existing dists are removed first
RUN rm -rf dist && uv build --sdist --out-dir dist
RUN mv "dist/prefect-"*".tar.gz" "dist/prefect.tar.gz"
# Setup a base final image from miniconda
FROM continuumio/miniconda3:26.1.1 AS prefect-conda
# Create a new conda environment with our required Python version
ARG PYTHON_VERSION
RUN conda create \
python=${PYTHON_VERSION} \
--name prefect
# Use the prefect environment by default
RUN echo "conda activate prefect" >> ~/.bashrc
SHELL ["/bin/bash", "--login", "-c"]
# Build the final image with Prefect installed and our entrypoint configured
FROM ${BASE_IMAGE} AS final
# Redeclare ARGs needed in this stage
ARG PYTHON_VERSION
ARG SQLITE_VERSION
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
ENV UV_SYSTEM_PYTHON=1
# Ensure Python uses the upgraded SQLite library
ENV LD_LIBRARY_PATH=/usr/local/lib
LABEL maintainer="help@prefect.io" \
io.prefect.python-version=${PYTHON_VERSION} \
io.prefect.sqlite-version=${SQLITE_VERSION} \
org.label-schema.schema-version="1.0" \
org.label-schema.name="prefect" \
org.label-schema.url="https://www.prefect.io/"
WORKDIR /opt/prefect
# Install system requirements
# For Debian Bookworm (used by conda base), we need to add Trixie sources to get git >= 2.47.3
# This is because miniconda3 images are still based on Bookworm which only has git ~2.39
# We install tini and build-essential first (from the base distro), then handle git separately
RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install --no-install-recommends -y \
tini=0.19.* \
build-essential \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install git - for Bookworm, we need to use Trixie sources since git >= 2.47.3 is required
# and Bookworm only provides ~2.39. We allow apt to pull git's dependencies from Trixie as needed.
RUN DEBIAN_VERSION=$(. /etc/os-release && echo $VERSION_CODENAME) && \
if [ "$DEBIAN_VERSION" = "bookworm" ]; then \
echo "deb http://deb.debian.org/debian trixie main" > /etc/apt/sources.list.d/trixie.list; \
apt-get update; \
apt-get install --no-install-recommends -y -t trixie git; \
rm -f /etc/apt/sources.list.d/trixie.list; \
else \
apt-get update; \
apt-get install --no-install-recommends -y git; \
fi \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& dpkg --compare-versions "$(dpkg-query -W -f='${Version}' git)" ge '1:2.47.3' || \
(echo "ERROR: git version must be >= 1:2.47.3" && exit 1)
# Copy pre-compiled SQLite ${SQLITE_VERSION} from sqlite-builder stage
COPY --from=sqlite-builder /usr/local/lib/libsqlite3* /usr/local/lib/
COPY --from=sqlite-builder /usr/local/include/sqlite3*.h /usr/local/include/
COPY --from=sqlite-builder /usr/local/bin/sqlite3 /usr/local/bin/
COPY --from=sqlite-builder /usr/local/lib/pkgconfig/sqlite3.pc /usr/local/lib/pkgconfig/
RUN ldconfig
# Install UV from official image - pin to specific version for build caching
COPY --from=ghcr.io/astral-sh/uv:0.6.17 /uv /bin/uv
# Install prefect from the sdist
COPY --from=python-builder /opt/prefect/dist ./dist
# Extras to include during installation
ARG PREFECT_EXTRAS=[redis,client,otel]
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install "./dist/prefect.tar.gz${PREFECT_EXTRAS:-""}" && \
rm -rf dist/
# Remove setuptools
RUN uv pip uninstall setuptools
# Install any extra packages
ARG EXTRA_PIP_PACKAGES
RUN --mount=type=cache,target=/root/.cache/uv \
[ -z "${EXTRA_PIP_PACKAGES:-""}" ] || uv pip install "${EXTRA_PIP_PACKAGES}"
# Smoke test
RUN prefect version
# Setup entrypoint
COPY scripts/entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["/usr/bin/tini", "-g", "--", "/opt/prefect/entrypoint.sh"]