fix: Allow user to not install Nushell in their system

This commit is contained in:
Gerald Pinder 2025-02-24 23:20:45 -05:00
parent c3f0e6712c
commit 7dc9c7e0c1
13 changed files with 271 additions and 182 deletions

View file

@ -1,6 +1,6 @@
use std::{borrow::Cow, fs, path::Path, process};
use blue_build_recipe::Recipe;
use blue_build_recipe::{MaybeVersion, Recipe};
use blue_build_utils::constants::{
CONFIG_PATH, CONTAINERFILES_PATH, CONTAINER_FILE, COSIGN_PUB_PATH, FILES_PATH,
};
@ -29,7 +29,23 @@ pub struct ContainerFileTemplate<'a> {
build_scripts_image: Cow<'a, str>,
repo: Cow<'a, str>,
base_digest: Cow<'a, str>,
nushell_version: Option<Cow<'a, str>>,
nushell_version: Option<&'a MaybeVersion>,
}
impl ContainerFileTemplate<'_> {
const fn should_install_nu(&self) -> bool {
match self.nushell_version {
None | Some(MaybeVersion::Version(_)) => true,
Some(MaybeVersion::None) => false,
}
}
fn get_nu_version(&self) -> String {
match self.nushell_version {
Some(MaybeVersion::None) | None => "default".to_string(),
Some(MaybeVersion::Version(version)) => version.to_string(),
}
}
}
#[derive(Debug, Clone, Template, Builder)]

View file

@ -35,15 +35,12 @@ RUN --mount=type=bind,from=stage-bins,src=/bins,dst=/tmp/bins \
&& cp /tmp/bins/* /usr/bin/ \
&& ostree container commit
RUN --mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:
{%- if let Some(version) = nushell_version -%}
{{ version }}
{%- else -%}
default
{%- endif %},src=/nu,dst=/tmp/nu \
{%- 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
{%- endif %}
RUN --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/scripts/ \
/scripts/pre_build.sh

View file

@ -23,6 +23,9 @@ RUN \
--mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \
{%- else %}
--mount=type=bind,from={{ module.get_module_image() }},src=/modules,dst=/tmp/modules,rw \
{%- endif %}
{%- if !should_install_nu() %}
--mount=type=bind,from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version() }},src=/nu,dst=/usr/libexec/bluebuild/nu \
{%- endif %}
{%- if module.module_type.typ() == "akmods" %}
--mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \

View file

@ -25,12 +25,10 @@ COPY ./modules /modules
# can be added to the ostree commits.
FROM scratch AS stage-bins
COPY --from={{ blue_build_utils::constants::COSIGN_IMAGE }} /ko-app/cosign /bins/cosign
COPY --from={{ blue_build_utils::constants::BLUE_BULID_IMAGE_REF }}:
{%- if let Some(tag) = recipe.blue_build_tag -%}
{{ tag }}
{%- else -%}
latest-installer
{%- endif %} /out/bluebuild /bins/bluebuild
{%- if recipe.should_install_bluebuild() %}
COPY --from={{ blue_build_utils::constants::BLUE_BULID_IMAGE_REF }}:{{ recipe.get_bluebuild_version() }} \
/out/bluebuild /bins/bluebuild
{%- endif %}
# Keys for pre-verified images
# Used to copy the keys into the final image
@ -59,12 +57,7 @@ ARG RUST_LOG_STYLE=always
{%- endif %}
{%- if stage.from != "scratch" %}
COPY --from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:
{%- if let Some(version) = nushell_version -%}
{{ version }}
{%- else -%}
default
{%- endif %} /nu/* /usr/libexec/bluebuild/nu/
COPY --from={{ blue_build_utils::constants::NUSHELL_IMAGE }}:{{ get_nu_version() }} /nu/* /usr/libexec/bluebuild/nu/
# Add compatibility for modules
RUN --mount=type=bind,from=stage-bins,src=/bins/,dst=/tmp/bins/ \