Skip to content

Commit 7bfb820

Browse files
committed
pyhl: support tagged GHCR pulls via InstallSource::Ghcr { tag }
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent ad90d23 commit 7bfb820

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

host/src/pyhl.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! // One-time install (no-op if already present).
2626
//! pyhl::install(&pyhl::InstallOptions {
2727
//! home,
28-
//! source: pyhl::InstallSource::Ghcr,
28+
//! source: pyhl::InstallSource::Ghcr { tag: None }, // None = :latest
2929
//! mounts: &[],
3030
//! network: None,
3131
//! listen_ports: None,
@@ -104,8 +104,9 @@ pub struct InstallOptions<'a> {
104104
/// Where `install` pulls its kernel and CPIO from.
105105
#[derive(Debug)]
106106
pub enum InstallSource<'a> {
107-
/// Pull the default published image from GHCR via docker/podman.
108-
Ghcr,
107+
/// Pull the published image from GHCR via docker/podman.
108+
/// `tag`: `None` pulls `:latest`; `Some("v0.3.1")` pins a release.
109+
Ghcr { tag: Option<&'a str> },
109110
/// Copy from a local python-agent-driver build tree.
110111
LocalDir(&'a Path),
111112
/// Explicit files — useful for custom image pipelines.
@@ -164,15 +165,17 @@ pub fn install(opts: &InstallOptions<'_>) -> Result<InstallReport> {
164165
kernel.to_path_buf(),
165166
initrd.to_path_buf(),
166167
),
167-
InstallSource::Ghcr => {
168+
InstallSource::Ghcr { tag } => {
169+
let kernel_image = ghcr_image_ref(GHCR_KERNEL_REPO, *tag);
170+
let initrd_image = ghcr_image_ref(GHCR_INITRD_REPO, *tag);
168171
let scratch = home.join(".pyhl.download");
169172
fs::create_dir_all(&scratch)?;
170173
let k = scratch.join("kernel");
171174
let i = scratch.join("initrd.cpio");
172-
extract_from_ghcr(GHCR_KERNEL_IMAGE, "/kernel", &k)?;
173-
extract_from_ghcr(GHCR_INITRD_IMAGE, "/initrd.cpio", &i)?;
175+
extract_from_ghcr(&kernel_image, "/kernel", &k)?;
176+
extract_from_ghcr(&initrd_image, "/initrd.cpio", &i)?;
174177
(
175-
format!("ghcr: {GHCR_KERNEL_IMAGE} + {GHCR_INITRD_IMAGE}"),
178+
format!("ghcr: {kernel_image} + {initrd_image}"),
176179
k,
177180
i,
178181
)
@@ -394,13 +397,18 @@ pub fn discover_source_artifacts(dir: &Path) -> Result<(PathBuf, PathBuf)> {
394397
// through InstallSource::Ghcr.
395398
// ---------------------------------------------------------------------------
396399

397-
/// OCI image references published by `.github/workflows/publish-examples.yml`.
398-
/// Both images are FROM-scratch payloads: kernel image has a single /kernel,
399-
/// initrd image has a single /initrd.cpio.
400-
pub const GHCR_KERNEL_IMAGE: &str =
401-
"ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-kernel:latest";
402-
pub const GHCR_INITRD_IMAGE: &str =
403-
"ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-initrd:latest";
400+
/// GHCR repository base (without tag) for the kernel image.
401+
pub const GHCR_KERNEL_REPO: &str =
402+
"ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-kernel";
403+
/// GHCR repository base (without tag) for the initrd image.
404+
pub const GHCR_INITRD_REPO: &str =
405+
"ghcr.io/hyperlight-dev/hyperlight-unikraft/python-agent-driver-initrd";
406+
407+
/// Build a full OCI image reference from a repo base and an optional tag.
408+
/// `None` resolves to `:latest`.
409+
pub fn ghcr_image_ref(repo: &str, tag: Option<&str>) -> String {
410+
format!("{}:{}", repo, tag.unwrap_or("latest"))
411+
}
404412

405413
/// Pull a single file out of an OCI image hosted on GHCR. Uses whichever
406414
/// of `docker` / `podman` is on `$PATH`. The published images are

0 commit comments

Comments
 (0)