-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDockerfile
More file actions
101 lines (74 loc) · 3.15 KB
/
Dockerfile
File metadata and controls
101 lines (74 loc) · 3.15 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
#----------------------------------------------------------#
# See LICENSE in the project root for license information. #
#----------------------------------------------------------#
ARG PYTHON_VERSION="3.11"
ARG BASE_APE_IMAGE="ghcr.io/apeworx/ape:python${PYTHON_VERSION}-stable-slim"
# Stage 1: Build dependencies
# NOTE: Build with builder image to reduce image size
FROM ${BASE_APE_IMAGE} AS slim-builder
# NOTE: Switch back to root for building
USER root
WORKDIR /home/harambe/project
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/
# Only copy dependency files first (locked deps change less often)
# NOTE: In CI, you need to cache `uv.lock` (or create it if it doesn't exist)
COPY pyproject.toml uv.lock ./
# UV Configurations
# NOTE: use system python (better for our images, that inherit from `python:$VERSION`)
ENV UV_MANAGED_PYTHON=false
# NOTE: skip installing dev-only dependencies
ENV UV_NO_DEV=true
# NOTE: use `uv.lock` that we loaded into build
ENV UV_FROZEN=true
# NOTE: installs everything as non-editable (faster)
ENV UV_NO_EDITABLE=true
# NOTE: improves load speed of dependencies
ENV UV_COMPILE_BYTECODE=true
# NOTE: link mode "copy" silences warnings about hard links in other commands
ENV UV_LINK_MODE=copy
# Install dependencies first
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-install-project
# NOTE: Needed to mock version for `setuptools-scm` (pass at build time)
ARG VERSION
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_SILVERBACK=${VERSION}
# Now copy Silverback's source code over
COPY silverback silverback
# Install Silverback using pre-installed dependencies
# NOTE: --extra build to include build-only dependencies (for cloud use)
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --extra build
# TODO: Figure out why `cluster/` subfolder isn't copying over from above command
RUN SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])") && \
cp -r silverback/cluster $SITE_PACKAGES/silverback/cluster
# Stage 2: Slim image (Based on Ape slim)
FROM ${BASE_APE_IMAGE} AS slim
COPY --from=slim-builder --chown=harambe:harambe \
/home/harambe/project/.venv /home/harambe/project/.venv
# NOTE: Switch back to user again for final image
USER harambe
# Add the virtual environment to PATH so Silverback is callable
ENV PATH="/home/harambe/project/.venv/bin:$PATH"
# See version of Ape
RUN ape --version
# See version of Silverback
RUN silverback --version
ENTRYPOINT ["silverback"]
CMD ["--help"]
# Stage 3: Add plugins on top of slim-builder
FROM slim-builder AS full-builder
# Install recommended plugins
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --extra build --extra recommended-plugins
# Stage 4: Full image (slim with recommended plugins from full-builder)
FROM slim AS full
# Install anvil (for the Foundry plugin to be useful)
# NOTE: Adds 33MB to build
COPY --from=ghcr.io/foundry-rs/foundry:stable \
/usr/local/bin/anvil /home/harambe/.local/bin/anvil
COPY --from=full-builder --chown=harambe:harambe \
/home/harambe/project/.venv /home/harambe/project/.venv
# See state of Ape plugins
RUN ape plugins list
# NOTE: Use same WORKDIR, USER, ENTRYPOINT and CMD as slim