From 33bebb5e294e6e166ea6675368cf99bf02f51f7b Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 31 May 2025 00:35:16 -0400 Subject: [PATCH] fix: Parse Version from container and remove ostree commit --- integration-tests/legacy-test-repo/config/recipe.yml | 2 +- integration-tests/test-repo/recipes/common.yml | 2 +- integration-tests/test-repo/recipes/recipe-gts.yml | 2 +- .../test-repo/recipes/recipe-invalid-from-file.yml | 2 +- .../test-repo/recipes/recipe-invalid-module.yml | 2 +- .../test-repo/recipes/recipe-invalid-stage.yml | 2 +- integration-tests/test-repo/recipes/recipe-invalid.yml | 2 +- process/drivers.rs | 10 ++++++---- process/drivers/types.rs | 8 ++++++-- scripts/post_build.sh | 1 - scripts/pre_build.sh | 8 +++++--- scripts/run_module.sh | 4 ---- src/commands/validate/yaml_span.rs | 2 +- template/templates/Containerfile.j2 | 9 +++------ test-files/recipes/recipe-fail.yml | 2 +- test-files/recipes/recipe-pass.yml | 2 +- 16 files changed, 30 insertions(+), 30 deletions(-) diff --git a/integration-tests/legacy-test-repo/config/recipe.yml b/integration-tests/legacy-test-repo/config/recipe.yml index de4f31d..0706db8 100644 --- a/integration-tests/legacy-test-repo/config/recipe.yml +++ b/integration-tests/legacy-test-repo/config/recipe.yml @@ -41,4 +41,4 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" diff --git a/integration-tests/test-repo/recipes/common.yml b/integration-tests/test-repo/recipes/common.yml index 90c844e..af48d17 100644 --- a/integration-tests/test-repo/recipes/common.yml +++ b/integration-tests/test-repo/recipes/common.yml @@ -41,7 +41,7 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/integration-tests/test-repo/recipes/recipe-gts.yml b/integration-tests/test-repo/recipes/recipe-gts.yml index 917d861..212e67c 100644 --- a/integration-tests/test-repo/recipes/recipe-gts.yml +++ b/integration-tests/test-repo/recipes/recipe-gts.yml @@ -44,4 +44,4 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" diff --git a/integration-tests/test-repo/recipes/recipe-invalid-from-file.yml b/integration-tests/test-repo/recipes/recipe-invalid-from-file.yml index 0c9ebba..8865680 100644 --- a/integration-tests/test-repo/recipes/recipe-invalid-from-file.yml +++ b/integration-tests/test-repo/recipes/recipe-invalid-from-file.yml @@ -38,7 +38,7 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/integration-tests/test-repo/recipes/recipe-invalid-module.yml b/integration-tests/test-repo/recipes/recipe-invalid-module.yml index f2ec249..dc721db 100644 --- a/integration-tests/test-repo/recipes/recipe-invalid-module.yml +++ b/integration-tests/test-repo/recipes/recipe-invalid-module.yml @@ -37,7 +37,7 @@ modules: containerfiles: labels: labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/integration-tests/test-repo/recipes/recipe-invalid-stage.yml b/integration-tests/test-repo/recipes/recipe-invalid-stage.yml index 4398e53..ac55fab 100644 --- a/integration-tests/test-repo/recipes/recipe-invalid-stage.yml +++ b/integration-tests/test-repo/recipes/recipe-invalid-stage.yml @@ -41,7 +41,7 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/integration-tests/test-repo/recipes/recipe-invalid.yml b/integration-tests/test-repo/recipes/recipe-invalid.yml index 9f29c46..13346ce 100644 --- a/integration-tests/test-repo/recipes/recipe-invalid.yml +++ b/integration-tests/test-repo/recipes/recipe-invalid.yml @@ -39,7 +39,7 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/process/drivers.rs b/process/drivers.rs index c9af3b7..72a6a1c 100644 --- a/process/drivers.rs +++ b/process/drivers.rs @@ -14,13 +14,14 @@ use std::{ time::Duration, }; +use blue_build_utils::semver::Version; use bon::{Builder, bon}; use cached::proc_macro::cached; use clap::Args; use colored::Colorize; use indicatif::{ProgressBar, ProgressStyle}; use log::{info, trace, warn}; -use miette::{IntoDiagnostic, Result, miette}; +use miette::{Result, miette}; use oci_distribution::Reference; use opts::{ BuildOpts, BuildTagPushOpts, CheckKeyPairOpts, CreateContainerOpts, GenerateImageNameOpts, @@ -216,6 +217,7 @@ impl Driver { .build(), ) .and_then(|inspection| { + trace!("{inspection:?}"); inspection.get_version().ok_or_else(|| { miette!( "Failed to parse version from metadata for {}", @@ -300,10 +302,10 @@ fn get_version_run_image(oci_ref: &Reference) -> Result { progress.finish_and_clear(); Logger::multi_progress().remove(&progress); - String::from_utf8_lossy(&output.stdout) + Ok(String::from_utf8_lossy(&output.stdout) .trim() - .parse() - .into_diagnostic() + .parse::()? + .major) } macro_rules! impl_build_driver { diff --git a/process/drivers/types.rs b/process/drivers/types.rs index 88ae80f..6c1dac1 100644 --- a/process/drivers/types.rs +++ b/process/drivers/types.rs @@ -10,7 +10,7 @@ use blue_build_utils::{ semver::Version, }; use clap::ValueEnum; -use log::trace; +use log::{trace, warn}; use oci_distribution::Reference; use serde::Deserialize; use serde_json::Value; @@ -247,7 +247,11 @@ impl ImageMetadata { self.labels .get(IMAGE_VERSION_LABEL) .map(ToOwned::to_owned) - .and_then(|v| serde_json::from_value::(v).ok())? + .and_then(|v| { + serde_json::from_value::(v) + .inspect_err(|e| warn!("Failed to parse version:\n{e}")) + .ok() + })? .major, ) } diff --git a/scripts/post_build.sh b/scripts/post_build.sh index 48e1b89..73f0f55 100644 --- a/scripts/post_build.sh +++ b/scripts/post_build.sh @@ -3,4 +3,3 @@ set -euo pipefail rm -rf /tmp/* /var/* -ostree container commit diff --git a/scripts/pre_build.sh b/scripts/pre_build.sh index 4a58aa0..26b3b1d 100644 --- a/scripts/pre_build.sh +++ b/scripts/pre_build.sh @@ -3,7 +3,9 @@ set -euo pipefail if ! command -v jq > /dev/null; then - rpm-ostree install jq + if command -v rpm-ostree > /dev/null; then + rpm-ostree install jq + else + dnf -y install jq + fi fi - -ostree container commit diff --git a/scripts/run_module.sh b/scripts/run_module.sh index fe09327..2332c6d 100644 --- a/scripts/run_module.sh +++ b/scripts/run_module.sh @@ -66,7 +66,3 @@ else color_string "$(print_banner "Failed '${module}' Module")" "31" exit 1 fi - -if command -v ostree > /dev/null; then - ostree container commit -fi diff --git a/src/commands/validate/yaml_span.rs b/src/commands/validate/yaml_span.rs index d5daa86..5511e1f 100644 --- a/src/commands/validate/yaml_span.rs +++ b/src/commands/validate/yaml_span.rs @@ -306,7 +306,7 @@ mod test { #[case(RECIPE, "/description", (109, 29))] #[case(RECIPE, "/image-version", (199, 6))] #[case(RECIPE, "/modules/4/source", (761, 5))] - #[case(RECIPE, "/modules/8/from", (1067, 11))] + #[case(RECIPE, "/modules/8/from", (1040, 11))] #[case(RECIPE_INVALID, "/image-version", (199, 6))] fn test_getspan(#[case] file: &str, #[case] path: &str, #[case] expected: (usize, usize)) { dbg!(path, expected); diff --git a/template/templates/Containerfile.j2 b/template/templates/Containerfile.j2 index 0d4d797..f1a559e 100644 --- a/template/templates/Containerfile.j2 +++ b/template/templates/Containerfile.j2 @@ -26,20 +26,17 @@ ARG RUST_LOG_STYLE=always # Key RUN RUN --mount=type=bind,from=stage-keys,src=/keys,dst=/tmp/keys \ mkdir -p /etc/pki/containers/ \ - && cp /tmp/keys/* /etc/pki/containers/ \ - && ostree container commit + && cp /tmp/keys/* /etc/pki/containers/ # Bin RUN RUN --mount=type=bind,from=stage-bins,src=/bins,dst=/tmp/bins \ mkdir -p /usr/bin/ \ - && cp /tmp/bins/* /usr/bin/ \ - && ostree container commit + && cp /tmp/bins/* /usr/bin/ {%- if should_install_nu() %} RUN --mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version() }},src=/nu,dst=/tmp/nu \ mkdir -p /usr/libexec/bluebuild/nu \ - && cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/ \ - && ostree container commit + && cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/ {%- endif %} RUN --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/scripts/ \ diff --git a/test-files/recipes/recipe-fail.yml b/test-files/recipes/recipe-fail.yml index e3540ed..fb28bac 100644 --- a/test-files/recipes/recipe-fail.yml +++ b/test-files/recipes/recipe-fail.yml @@ -39,7 +39,7 @@ modules: - type: containerfile containerfiles: labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test diff --git a/test-files/recipes/recipe-pass.yml b/test-files/recipes/recipe-pass.yml index 5ee8177..9eabb78 100644 --- a/test-files/recipes/recipe-pass.yml +++ b/test-files/recipes/recipe-pass.yml @@ -40,7 +40,7 @@ modules: containerfiles: - labels snippets: - - RUN echo "This is a snippet" && ostree container commit + - RUN echo "This is a snippet" - type: copy from: alpine-test