Skip to content

Commit

Permalink
fetch_variant: fetch optional repository files
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhballal committed Sep 25, 2024
1 parent 15344e5 commit 21741fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tools/pubsys/src/repo/fetch_variant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use url::Url;

use buildsys::manifest::{ImageFormat, ManifestInfo, PartitionPlan};

/// fetching and downdloaing the image targets of a given variant
/// fetching and downloading the image targets of a given variant
#[derive(Debug, Parser)]
pub(crate) struct FetchVariantArgs {
#[arg(long)]
Expand Down Expand Up @@ -49,6 +49,9 @@ pub(crate) struct FetchVariantArgs {
/// The variant name without extension
filename_prefix: String,

#[arg(long)]
fetch_repo_files: bool,

#[arg(long)]
/// The manifest of the variant
variant_manifest: PathBuf,
Expand Down Expand Up @@ -122,6 +125,7 @@ async fn fetch_variant(
filename_prefix: &str,
variant_manifest: &PathBuf,
variant: &str,
fetch_repo_files: bool,
) -> Result<(), Error> {
// Load the repository
let repo = RepositoryLoader::new(
Expand All @@ -134,7 +138,7 @@ async fn fetch_variant(
.context(repo_error::RepoLoadSnafu {
metadata_base_url: metadata_url.clone(),
})?;

let repo_file_types = vec!["boot.ext4.lz4", "root.ext4.lz4", "root.verity.lz4"];
let manifest_info = ManifestInfo::new(variant_manifest).context(error::ManifestParseSnafu)?;

let image_layout = manifest_info
Expand All @@ -147,7 +151,7 @@ async fn fetch_variant(
Some(ImageFormat::Vmdk) => "ova",
};

let targets = match image_format {
let mut targets = match image_format {
// Since the OVA will contain all of the necessary VMDKs, the partition plan is irrelevant.
Some(ImageFormat::Vmdk) => {
vec![format!("{filename_prefix}.{image_ext}")]
Expand All @@ -162,6 +166,16 @@ async fn fetch_variant(
PartitionPlan::Unified => vec![format!("{filename_prefix}.{image_ext}")],
},
};

if fetch_repo_files {
// Fetch required TUF Repo file names.
let repo_files = repo_file_types
.into_iter()
.map(|ext| format!("{filename_prefix}-{ext}"))
.collect();
targets.push(repo_files);
}

handle_download(&repo, outdir, &targets).await
}

Expand Down Expand Up @@ -205,6 +219,7 @@ pub(crate) async fn run(args: &Args, fetch_variant_args: &FetchVariantArgs) -> R
&fetch_variant_args.filename_prefix,
&fetch_variant_args.variant_manifest,
&fetch_variant_args.variant,
fetch_variant_args.fetch_repo_files,
)
.await
}
Expand Down
4 changes: 4 additions & 0 deletions twoliter/embedded/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,10 @@ run_task = "fetch-variant"
[tasks.fetch-ova]
run_task = "fetch-friendly-variant"

[tasks.fetch-repo]
env = { "FETCH_REPO_FILES" = "true" }
run_task = "fetch-variant"

[tasks.check-repo-expirations]
dependencies = ["publish-setup-without-key"]
script_runner = "bash"
Expand Down

0 comments on commit 21741fb

Please sign in to comment.