-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (44 loc) · 2.25 KB
/
Copy pathDockerfile
File metadata and controls
49 lines (44 loc) · 2.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
# python-agent-driver — Python runtime driver for Hyperlight.
#
# Same deps as python-agent (numpy + pandas + the usual stack) PLUS
# a small C program `hl_pydriver` that embeds libpython3.12, does
# Py_Initialize + warm-up imports on its first invocation, and then
# installs an FC-aware dispatch callback that handles every
# subsequent host->guest call without re-running main().
ARG BASE=ghcr.io/hyperlight-dev/hyperlight-unikraft/python-base:latest
# Stage 1: Python deps (same as python-agent).
FROM python:3.12-slim AS deps
RUN pip install --target=/deps --no-cache-dir \
tqdm pyyaml jinja2 beautifulsoup4 tabulate click tenacity \
python-dotenv pypdf openpyxl markdown-it-py pydantic pillow \
lxml cryptography python-dateutil numpy pandas
RUN set -eux; \
find /deps -maxdepth 1 -type d -name '*.dist-info' -exec rm -rf {} + 2>/dev/null || true; \
find /deps \( -type d -name tests -o -type d -name test \) -exec rm -rf {} + 2>/dev/null || true; \
find /deps -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true; \
find /deps -type f -name '*.pyc' -delete 2>/dev/null || true; \
find /deps -name '*.so*' -exec strip --strip-unneeded {} + 2>/dev/null || true
# Stage 2: build hl_pydriver against the SAME Python 3.12-from-source
# that produces local-python-base, so the glibc/libpython3.12.so ABI
# matches the runtime.
FROM local-python-base-dev AS driver-build
COPY hl_pydriver.c /src/hl_pydriver.c
RUN PY_INC=$(python3.12 -c 'import sysconfig; print(sysconfig.get_path("include"))') && \
PY_LIBDIR=$(python3.12 -c 'import sysconfig; print(sysconfig.get_config_var("LIBDIR"))') && \
gcc -O2 -fPIE -pie -Wl,-E \
-fno-stack-protector \
-I$PY_INC \
-o /src/hl_pydriver /src/hl_pydriver.c \
-L$PY_LIBDIR \
-Wl,-rpath,/usr/local/lib \
-Wl,-rpath,/lib/x86_64-linux-gnu \
-lpython3.12 -ldl -lpthread -lm -lutil
# Stage 3: assemble rootfs.
FROM ${BASE} AS rootfs
COPY --from=deps /deps /usr/local/lib/python3.12/site-packages
COPY --from=driver-build /src/hl_pydriver /bin/hl_pydriver
# Stage 4: pack CPIO.
FROM alpine:3.20 AS cpio
RUN apk add --no-cache cpio findutils
COPY --from=rootfs / /rootfs/
RUN cd /rootfs && find . | cpio -o -H newc > /output.cpio 2>/dev/null