fix: Parse Version from container and remove ostree commit

This commit is contained in:
Gerald Pinder 2025-05-31 00:35:16 -04:00
parent 783b9cb2d6
commit 33bebb5e29
16 changed files with 30 additions and 30 deletions

View file

@ -41,4 +41,4 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"

View file

@ -41,7 +41,7 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -44,4 +44,4 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"

View file

@ -38,7 +38,7 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -37,7 +37,7 @@ modules:
containerfiles: containerfiles:
labels: labels labels: labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -41,7 +41,7 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -39,7 +39,7 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -14,13 +14,14 @@ use std::{
time::Duration, time::Duration,
}; };
use blue_build_utils::semver::Version;
use bon::{Builder, bon}; use bon::{Builder, bon};
use cached::proc_macro::cached; use cached::proc_macro::cached;
use clap::Args; use clap::Args;
use colored::Colorize; use colored::Colorize;
use indicatif::{ProgressBar, ProgressStyle}; use indicatif::{ProgressBar, ProgressStyle};
use log::{info, trace, warn}; use log::{info, trace, warn};
use miette::{IntoDiagnostic, Result, miette}; use miette::{Result, miette};
use oci_distribution::Reference; use oci_distribution::Reference;
use opts::{ use opts::{
BuildOpts, BuildTagPushOpts, CheckKeyPairOpts, CreateContainerOpts, GenerateImageNameOpts, BuildOpts, BuildTagPushOpts, CheckKeyPairOpts, CreateContainerOpts, GenerateImageNameOpts,
@ -216,6 +217,7 @@ impl Driver {
.build(), .build(),
) )
.and_then(|inspection| { .and_then(|inspection| {
trace!("{inspection:?}");
inspection.get_version().ok_or_else(|| { inspection.get_version().ok_or_else(|| {
miette!( miette!(
"Failed to parse version from metadata for {}", "Failed to parse version from metadata for {}",
@ -300,10 +302,10 @@ fn get_version_run_image(oci_ref: &Reference) -> Result<u64> {
progress.finish_and_clear(); progress.finish_and_clear();
Logger::multi_progress().remove(&progress); Logger::multi_progress().remove(&progress);
String::from_utf8_lossy(&output.stdout) Ok(String::from_utf8_lossy(&output.stdout)
.trim() .trim()
.parse() .parse::<Version>()?
.into_diagnostic() .major)
} }
macro_rules! impl_build_driver { macro_rules! impl_build_driver {

View file

@ -10,7 +10,7 @@ use blue_build_utils::{
semver::Version, semver::Version,
}; };
use clap::ValueEnum; use clap::ValueEnum;
use log::trace; use log::{trace, warn};
use oci_distribution::Reference; use oci_distribution::Reference;
use serde::Deserialize; use serde::Deserialize;
use serde_json::Value; use serde_json::Value;
@ -247,7 +247,11 @@ impl ImageMetadata {
self.labels self.labels
.get(IMAGE_VERSION_LABEL) .get(IMAGE_VERSION_LABEL)
.map(ToOwned::to_owned) .map(ToOwned::to_owned)
.and_then(|v| serde_json::from_value::<Version>(v).ok())? .and_then(|v| {
serde_json::from_value::<Version>(v)
.inspect_err(|e| warn!("Failed to parse version:\n{e}"))
.ok()
})?
.major, .major,
) )
} }

View file

@ -3,4 +3,3 @@
set -euo pipefail set -euo pipefail
rm -rf /tmp/* /var/* rm -rf /tmp/* /var/*
ostree container commit

View file

@ -3,7 +3,9 @@
set -euo pipefail set -euo pipefail
if ! command -v jq > /dev/null; then 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 fi
ostree container commit

View file

@ -66,7 +66,3 @@ else
color_string "$(print_banner "Failed '${module}' Module")" "31" color_string "$(print_banner "Failed '${module}' Module")" "31"
exit 1 exit 1
fi fi
if command -v ostree > /dev/null; then
ostree container commit
fi

View file

@ -306,7 +306,7 @@ mod test {
#[case(RECIPE, "/description", (109, 29))] #[case(RECIPE, "/description", (109, 29))]
#[case(RECIPE, "/image-version", (199, 6))] #[case(RECIPE, "/image-version", (199, 6))]
#[case(RECIPE, "/modules/4/source", (761, 5))] #[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))] #[case(RECIPE_INVALID, "/image-version", (199, 6))]
fn test_getspan(#[case] file: &str, #[case] path: &str, #[case] expected: (usize, usize)) { fn test_getspan(#[case] file: &str, #[case] path: &str, #[case] expected: (usize, usize)) {
dbg!(path, expected); dbg!(path, expected);

View file

@ -26,20 +26,17 @@ ARG RUST_LOG_STYLE=always
# Key RUN # Key RUN
RUN --mount=type=bind,from=stage-keys,src=/keys,dst=/tmp/keys \ RUN --mount=type=bind,from=stage-keys,src=/keys,dst=/tmp/keys \
mkdir -p /etc/pki/containers/ \ mkdir -p /etc/pki/containers/ \
&& cp /tmp/keys/* /etc/pki/containers/ \ && cp /tmp/keys/* /etc/pki/containers/
&& ostree container commit
# Bin RUN # Bin RUN
RUN --mount=type=bind,from=stage-bins,src=/bins,dst=/tmp/bins \ RUN --mount=type=bind,from=stage-bins,src=/bins,dst=/tmp/bins \
mkdir -p /usr/bin/ \ mkdir -p /usr/bin/ \
&& cp /tmp/bins/* /usr/bin/ \ && cp /tmp/bins/* /usr/bin/
&& ostree container commit
{%- if should_install_nu() %} {%- if should_install_nu() %}
RUN --mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version() }},src=/nu,dst=/tmp/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 \ mkdir -p /usr/libexec/bluebuild/nu \
&& cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/ \ && cp -r /tmp/nu/* /usr/libexec/bluebuild/nu/
&& ostree container commit
{%- endif %} {%- endif %}
RUN --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/scripts/ \ RUN --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/scripts/ \

View file

@ -39,7 +39,7 @@ modules:
- type: containerfile - type: containerfile
containerfiles: labels containerfiles: labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test

View file

@ -40,7 +40,7 @@ modules:
containerfiles: containerfiles:
- labels - labels
snippets: snippets:
- RUN echo "This is a snippet" && ostree container commit - RUN echo "This is a snippet"
- type: copy - type: copy
from: alpine-test from: alpine-test