@@ -19,11 +19,13 @@ ARG TARGETARCH
19
19
20
20
WORKDIR /workspace
21
21
22
+ # Install system-level dependencies first. This layer is very stable.
22
23
USER root
23
24
# Install EPEL repository directly and then ZeroMQ, as epel-release is not in default repos.
25
+ # Install all necessary dependencies including Python 3.12 for chat-completions templating.
24
26
# The builder is based on UBI8, so we need epel-release-8.
25
27
RUN dnf install -y 'https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm' && \
26
- dnf install -y gcc-c++ libstdc++ libstdc++-devel clang zeromq-devel pkgconfig && \
28
+ dnf install -y gcc-c++ libstdc++ libstdc++-devel clang zeromq-devel pkgconfig python3.12-devel python3.12-pip && \
27
29
dnf clean all
28
30
29
31
# Copy the Go Modules manifests
@@ -33,6 +35,12 @@ COPY go.sum go.sum
33
35
# and so that source changes don't invalidate our downloaded layer
34
36
RUN go mod download
35
37
38
+ # Copy only the requirements file.
39
+ COPY pkg/preprocessing/chat_completions/requirements.txt ./requirements.txt
40
+ # Install Python dependencies. This layer will be cached unless requirements.txt changes.
41
+ RUN python3.12 -m pip install --upgrade pip setuptools wheel && \
42
+ python3.12 -m pip install -r ./requirements.txt
43
+
36
44
# Copy the go source
37
45
COPY examples/kv_events examples/kv_events
38
46
COPY . .
@@ -43,13 +51,17 @@ ARG RELEASE_VERSION=v1.22.1
43
51
RUN curl -L https://github.com/daulet/tokenizers/releases/download/${RELEASE_VERSION}/libtokenizers.${TARGETOS}-${TARGETARCH}.tar.gz | tar -xz -C lib
44
52
RUN ranlib lib/*.a
45
53
46
- # Build
47
- # the GOARCH has not a default value to allow the binary be built according to the host where the command
48
- # was called. For example, if we call make image-build in a local env which has the Apple Silicon M1 SO
49
- # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
50
- # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
54
+ # Set up Python environment variables needed for the build
55
+ ENV PYTHONPATH=/workspace/pkg/preprocessing/chat_completions:/usr/lib64/python3.9/site-packages:/usr/lib/python3.9/site-packages
56
+ ENV PYTHON=python3.9
51
57
52
- RUN CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} go build -ldflags="-extldflags '-L$(pwd)/lib'" -a -o bin/kv-cache-manager examples/kv_events/online/main.go
58
+ # Build the application with CGO enabled.
59
+ # We export CGO_CFLAGS and CGO_LDFLAGS using python3.12-config to ensure the Go compiler
60
+ # can find the Python headers and libraries correctly. This mirrors the fix from the Makefile.
61
+ RUN export CGO_CFLAGS="$(python3.12-config --cflags) -I/workspace/lib" && \
62
+ export CGO_LDFLAGS="$(python3.12-config --ldflags --embed) -L/workspace/lib -ltokenizers -ldl -lm" && \
63
+ CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
64
+ go build -a -o bin/kv-cache-manager examples/kv_events/online/main.go
53
65
54
66
# Use distroless as minimal base image to package the manager binary
55
67
# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -59,8 +71,25 @@ WORKDIR /
59
71
# The final image is UBI9, so we need epel-release-9.
60
72
USER root
61
73
RUN dnf install -y 'https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm' && \
62
- dnf install -y zeromq
74
+ dnf install -y zeromq libxcrypt-compat python3.12 python3.12-pip && \
75
+ dnf clean all
76
+
77
+
78
+
79
+ # Install Python dependencies in the final image.
80
+ COPY --from=builder /workspace/requirements.txt /tmp/requirements.txt
81
+ RUN python3.12 -m pip install --upgrade pip setuptools wheel && \
82
+ python3.12 -m pip install --no-cache-dir -r /tmp/requirements.txt \
83
+ && rm -rf /tmp/requirements.txt
84
+
85
+ # Copy this project's own Python source code into the final image
86
+ COPY --from=builder /workspace/pkg/preprocessing/chat_completions /app/pkg/preprocessing/chat_completions
87
+
88
+ # Set the PYTHONPATH. This mirrors the Makefile's export, ensuring both this project's
89
+ # Python code and the installed libraries (site-packages) are found at runtime.
90
+ ENV PYTHONPATH=/app/pkg/preprocessing/chat_completions:/usr/lib64/python3.12/site-packages
63
91
92
+ # Copy the compiled Go application
64
93
COPY --from=builder /workspace/bin/kv-cache-manager /app/kv-cache-manager
65
94
USER 65532:65532
66
95
0 commit comments