diff --git a/core/startos/src/s9pk/v2/pack.rs b/core/startos/src/s9pk/v2/pack.rs index aa0fd39f2..27cad6e92 100644 --- a/core/startos/src/s9pk/v2/pack.rs +++ b/core/startos/src/s9pk/v2/pack.rs @@ -1,3 +1,4 @@ +use std::collections::BTreeMap; use std::collections::BTreeSet; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -62,6 +63,7 @@ impl SqfsDir { let path = self.tmpdir.join(guid.as_ref()).with_extension("squashfs"); if self.path.extension().and_then(|s| s.to_str()) == Some("tar") { Command::new("tar2sqfs") + .arg("-q") .arg(&path) .input(Some(&mut open_file(&self.path).await?)) .invoke(ErrorKind::Filesystem) @@ -70,6 +72,7 @@ impl SqfsDir { Command::new("mksquashfs") .arg(&self.path) .arg(&path) + .arg("-quiet") .invoke(ErrorKind::Filesystem) .await?; } @@ -294,6 +297,7 @@ impl TryFrom for ImageConfig { ImageSource::DockerBuild { dockerfile: value.dockerfile, workdir: value.workdir, + build_args: None } } else if let Some(tag) = value.docker_tag { ImageSource::DockerTag(tag) @@ -337,6 +341,17 @@ impl clap::FromArgMatches for ImageConfig { } } +#[derive(Debug, Clone, Deserialize, Serialize, TS)] +#[serde(rename_all = "camelCase")] +#[serde(untagged)] +#[ts(export)] +pub enum BuildArg { + String(String), + EnvVar { + env: String, + }, +} + #[derive(Debug, Clone, Deserialize, Serialize, TS)] #[serde(rename_all = "camelCase")] #[ts(export)] @@ -346,6 +361,9 @@ pub enum ImageSource { DockerBuild { workdir: Option, dockerfile: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[ts(optional)] + build_args: Option> }, DockerTag(String), } @@ -384,6 +402,7 @@ impl ImageSource { ImageSource::DockerBuild { workdir, dockerfile, + build_args } => { let workdir = workdir.as_deref().unwrap_or(Path::new(".")); let dockerfile = dockerfile @@ -398,7 +417,8 @@ impl ImageSource { }; // docker buildx build ${path} -o type=image,name=start9/${id} let tag = format!("start9/{id}/{image_id}:{}", new_guid()); - Command::new(CONTAINER_TOOL) + let mut command = Command::new(CONTAINER_TOOL); + command .arg("build") .arg(workdir) .arg("-f") @@ -406,6 +426,26 @@ impl ImageSource { .arg("-t") .arg(&tag) .arg(&docker_platform) + .arg("--build-arg").arg(format!("ARCH={}", arch)); + + // add build arguments + if let Some(build_args) = build_args { + for (key, value) in build_args { + let build_arg_value = match value { + BuildArg::String(val) => val.to_string(), + BuildArg::EnvVar { env } => { + match std::env::var(&env) { + Ok(val) => val, + Err(_) => continue, // skip if env var not set or invalid + } + }, + }; + + command.arg("--build-arg").arg(format!("{}={}", key, build_arg_value)); + } + } + + command .arg("-o") .arg("type=docker,dest=-") .capture(false) @@ -513,7 +553,7 @@ impl ImageSource { Command::new(CONTAINER_TOOL) .arg("export") .arg(container.trim()) - .pipe(Command::new("tar2sqfs").arg(&dest)) + .pipe(Command::new("tar2sqfs").arg("-q").arg(&dest)) .capture(false) .invoke(ErrorKind::Docker) .await?; diff --git a/sdk/base/lib/osBindings/BuildArg.ts b/sdk/base/lib/osBindings/BuildArg.ts new file mode 100644 index 000000000..1157828f5 --- /dev/null +++ b/sdk/base/lib/osBindings/BuildArg.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type BuildArg = string | { env: string } diff --git a/sdk/base/lib/osBindings/ImageSource.ts b/sdk/base/lib/osBindings/ImageSource.ts index a71684e46..58d2c2a79 100644 --- a/sdk/base/lib/osBindings/ImageSource.ts +++ b/sdk/base/lib/osBindings/ImageSource.ts @@ -1,6 +1,13 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { BuildArg } from "./BuildArg" export type ImageSource = | "packed" - | { dockerBuild: { workdir: string | null; dockerfile: string | null } } + | { + dockerBuild: { + workdir: string | null + dockerfile: string | null + buildArgs?: { [key: string]: BuildArg } + } + } | { dockerTag: string } diff --git a/sdk/base/lib/osBindings/index.ts b/sdk/base/lib/osBindings/index.ts index 6c18fa197..a4f734778 100644 --- a/sdk/base/lib/osBindings/index.ts +++ b/sdk/base/lib/osBindings/index.ts @@ -39,6 +39,7 @@ export { BindOptions } from "./BindOptions" export { BindParams } from "./BindParams" export { Blake3Commitment } from "./Blake3Commitment" export { BlockDev } from "./BlockDev" +export { BuildArg } from "./BuildArg" export { CallbackId } from "./CallbackId" export { Category } from "./Category" export { CheckDependenciesParam } from "./CheckDependenciesParam"