Skip to content

Commit c7adf56

Browse files
authored
feat: add pyhl container image for device plugin deployments (#109)
* feat: add pyhl container image for device plugin deployments Signed-off-by: danbugs <danilochiarlone@gmail.com> * ci: publish pyhl container image to GHCR Signed-off-by: danbugs <danilochiarlone@gmail.com> * feat: add --setup-only flag to entrypoint for init container use Signed-off-by: danbugs <danilochiarlone@gmail.com> * fix: use POSIX sh and add EXIT trap in entrypoint Signed-off-by: danbugs <danilochiarlone@gmail.com> --------- Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 71c543b commit c7adf56

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/publish-examples.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
tags: ['v*']
88
paths:
99
- 'examples/**'
10+
- 'host/**'
1011
- 'runtimes/**'
1112
- '.github/workflows/publish-examples.yml'
1213

@@ -230,6 +231,37 @@ jobs:
230231
docker push $VERSION_TAG
231232
fi
232233
234+
# Publish a runnable pyhl container image (pyhl + kernel + initrd).
235+
# Designed for the hyperlight-on-kubernetes device plugin — the pod
236+
# gets /dev/kvm and pyhl handles VM lifecycle internally.
237+
publish-pyhl:
238+
needs: [publish-pyhl-initrd, publish-kernels]
239+
runs-on: ubuntu-latest
240+
permissions:
241+
contents: read
242+
packages: write
243+
steps:
244+
- uses: actions/checkout@v4
245+
246+
- name: Log in to GHCR
247+
uses: docker/login-action@v3
248+
with:
249+
registry: ${{ env.REGISTRY }}
250+
username: ${{ github.actor }}
251+
password: ${{ secrets.GITHUB_TOKEN }}
252+
253+
- name: Build and push pyhl image
254+
run: |
255+
IMAGE=${{ env.IMAGE_BASE }}/pyhl:latest
256+
docker build --platform linux/amd64 \
257+
-f host/pyhl.Dockerfile -t $IMAGE .
258+
docker push $IMAGE
259+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
260+
VERSION_TAG=${{ env.IMAGE_BASE }}/pyhl:${{ github.ref_name }}
261+
docker tag $IMAGE $VERSION_TAG
262+
docker push $VERSION_TAG
263+
fi
264+
233265
# Publish the python-agent-driver rootfs CPIO as its own image so
234266
# `pyhl setup` can pull the initrd (and kernel, above) from GHCR
235267
# without having to build the driver image locally.

host/pyhl-entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ ! -f "$PYHL_HOME/snapshot/index.json" ]; then
5+
staging=$(mktemp -d)
6+
trap 'rm -rf "$staging"' EXIT
7+
mkdir -p "$staging/.unikraft/build"
8+
ln -s "$PYHL_HOME/kernel" "$staging/.unikraft/build/driver_hyperlight-x86_64"
9+
ln -s "$PYHL_HOME/initrd.cpio" "$staging/driver-initrd.cpio"
10+
pyhl setup --dest "$PYHL_HOME" --from "$staging" --net --force
11+
fi
12+
13+
if [ "$1" = "--setup-only" ]; then
14+
exit 0
15+
fi
16+
17+
exec pyhl run --dest "$PYHL_HOME" --net "$@"

host/pyhl.Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# pyhl container image — runs Python scripts in Hyperlight micro-VMs.
2+
#
3+
# Bundles the pyhl CLI, the python-agent-driver kernel, and its initrd
4+
# into a single runnable container. Designed for the
5+
# hyperlight-on-kubernetes device plugin: the pod gets /dev/kvm via
6+
# `hyperlight.dev/hypervisor: "1"` and pyhl handles the rest.
7+
#
8+
# Build (from repo root):
9+
# docker build -f host/pyhl.Dockerfile -t pyhl .
10+
#
11+
# Run:
12+
# docker run --rm --device /dev/kvm pyhl /path/to/script.py
13+
# echo 'print("hi")' | docker run --rm -i --device /dev/kvm pyhl -
14+
15+
FROM rust:1.87-bookworm AS builder
16+
COPY host/ /src/host/
17+
WORKDIR /src/host
18+
RUN cargo build --release --bin pyhl
19+
20+
FROM ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-kernel:latest AS kernel
21+
FROM ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-initrd:latest AS initrd
22+
23+
FROM debian:bookworm-slim
24+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
25+
&& rm -rf /var/lib/apt/lists/*
26+
COPY --from=builder /src/host/target/release/pyhl /usr/local/bin/
27+
COPY --from=kernel /kernel /opt/pyhl/kernel
28+
COPY --from=initrd /initrd.cpio /opt/pyhl/initrd.cpio
29+
COPY host/pyhl-entrypoint.sh /entrypoint.sh
30+
RUN chmod +x /entrypoint.sh && chown -R 65534:65534 /opt/pyhl
31+
ENV PYHL_HOME=/opt/pyhl
32+
USER 65534
33+
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)