Skip to content

Commit e658e3b

Browse files
committed
feat: Add support for NuShell scripts
1 parent 4a72938 commit e658e3b

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

bacon.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ command = ["cargo", "install", "--path", ".", "--debug", "--locked", "--color",
7474
need_stdout = false
7575
allow_warnings = true
7676
default_watch = false
77-
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs"]
77+
watch = ["src", "process", "recipe", "template", "utils", "scripts", "Cargo.toml", "build.rs"]
7878

7979
[jobs.install-all]
8080
command = ["cargo", "install", "--all-features", "--path", ".", "--debug", "--locked", "--color", "always"]
8181
need_stdout = false
8282
allow_warnings = true
8383
default_watch = false
84-
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs"]
84+
watch = ["src", "process", "recipe", "template", "utils", "scripts", "Cargo.toml", "build.rs"]
8585

8686
# You may define here keybindings that would be specific to
8787
# a project, for example a shortcut to launch a specific job.

recipe/src/module.rs

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ impl<'a> ModuleRequiredFields<'a> {
9191
}
9292
}
9393

94+
#[must_use]
95+
pub fn is_local_source(&self) -> bool {
96+
self.source
97+
.as_deref()
98+
.is_some_and(|source| source == "local")
99+
}
100+
94101
#[must_use]
95102
pub fn generate_akmods_info(&'a self, os_version: &u64) -> AkmodsInfo {
96103
#[derive(Debug, Default, Copy, Clone)]

scripts/run_module.sh

+38-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,51 @@ print_banner() {
1919
printf '%*.*s%s%*.*s\n' 0 "$padlen" "$padding" "$text" 0 "$padlen" "$padding"
2020
}
2121

22+
get_script_path() {
23+
local script_name="$1"
24+
local extensions=("sh" "bash" "nu")
25+
local base_script_path="/tmp/modules/${script_name}/${script_name}"
26+
local tried_scripts=()
27+
28+
# See if
29+
if [[ -f "${base_script_path}" ]]; then
30+
echo "${base_script_path}"
31+
return 0
32+
fi
33+
tried_scripts+=("${script_name}")
34+
35+
# Iterate through each extension and check if the file exists
36+
for ext in "${extensions[@]}"; do
37+
local script_path="${base_script_path}.${ext}"
38+
tried_scripts+=("${script_name}.${ext}")
39+
40+
if [[ -f "$script_path" ]]; then
41+
# Output only the script path without extra information
42+
echo "$script_path"
43+
return 0 # Exit the function when the first matching file is found
44+
fi
45+
done
46+
47+
# If no matching file was found
48+
echo "Failed to find scripts matching: ${tried_scripts[*]}" >&2
49+
return 1
50+
}
51+
2252
module="$1"
2353
params="$2"
24-
script_path="/tmp/modules/${module}/${module}.sh"
54+
script_path="$(get_script_path "$module")"
2555

2656
color_string "$(print_banner "Start '${module}' Module")" "33"
27-
chmod +x ${script_path}
57+
chmod +x "${script_path}"
2858

29-
if ${script_path} "${params}"; then
59+
if "${script_path}" "${params}"; then
3060
color_string "$(print_banner "End '${module}' Module")" "32"
61+
3162
else
3263
color_string "$(print_banner "Failed '${module}' Module")" "31"
3364
exit 1
3465
fi
66+
67+
if command -v ostree > /dev/null; then
68+
ostree container commit
69+
fi

template/templates/modules/modules.j2

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ RUN \
1919
{%- endif %}
2020
{%- if let Some(source) = module.get_non_local_source() %}
2121
--mount=type=bind,from={{ source }},src=/modules,dst=/tmp/modules,rw \
22-
{%- else %}
22+
{%- else if module.is_local_source() %}
2323
--mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \
24+
{%- else %}
25+
--mount=type=bind,from=ghcr.io/blue-build/modules/{{ module.module_type }}:latest,src=/modules,dst=/tmp/modules,rw \
2426
{%- endif %}
2527
{%- if module.module_type == "akmods" %}
2628
--mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \
2729
{%- endif %}
2830
--mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/tmp/scripts/ \
2931
--mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
3032
--mount=type=cache,dst=/var/cache/libdnf5,id=dnf-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
31-
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}' \
32-
&& ostree container commit
33+
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}'
3334
{%- endif %}
3435
{%- endif %}
3536
{%- endfor %}
@@ -57,8 +58,10 @@ RUN \
5758
{%- endif %}
5859
{%- if let Some(source) = module.get_non_local_source() %}
5960
--mount=type=bind,from={{ source }},src=/modules,dst=/tmp/modules,rw \
60-
{%- else %}
61+
{%- else if module.is_local_source() %}
6162
--mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \
63+
{%- else %}
64+
--mount=type=bind,from=ghcr.io/blue-build/modules/{{ module.module_type }}:latest,src=/modules,dst=/tmp/modules,rw \
6265
{%- endif %}
6366
--mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/tmp/scripts/ \
6467
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}'

template/templates/stages.j2

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ FROM scratch AS stage-config
99
COPY ./config /config
1010
{% endif %}
1111

12+
{%- if self::modules_exists() %}
1213
# Copy modules
1314
# The default modules are inside blue-build/modules
1415
# Custom modules overwrite defaults
1516
FROM scratch AS stage-modules
16-
COPY --from=ghcr.io/blue-build/modules:latest /modules /modules
17-
{%- if self::modules_exists() %}
1817
COPY ./modules /modules
1918
{% endif %}
2019

@@ -25,7 +24,8 @@ COPY ./modules /modules
2524
# can be added to the ostree commits.
2625
FROM scratch AS stage-bins
2726
COPY --from={{ blue_build_utils::constants::COSIGN_IMAGE }} /ko-app/cosign /bins/cosign
28-
COPY --from=ghcr.io/blue-build/cli:
27+
COPY --from={{ blue_build_utils::constants::NUSHELL_IMAGE }} /nu/nu* /bins/
28+
COPY --from={{ blue_build_utils::constants::BLUE_BULID_IMAGE_REF }}:
2929
{%- if let Some(tag) = recipe.blue_build_tag -%}
3030
{{ tag }}
3131
{%- else -%}

utils/src/constants.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ pub const XDG_RUNTIME_DIR: &str = "XDG_RUNTIME_DIR";
7474

7575
// Misc
7676
pub const BUILD_SCRIPTS_IMAGE_REF: &str = "ghcr.io/blue-build/cli/build-scripts";
77+
pub const BLUE_BULID_IMAGE_REF: &str = "ghcr.io/blue-build/cli";
7778
pub const COSIGN_IMAGE: &str = "ghcr.io/sigstore/cosign/cosign:v2.4.1";
79+
pub const NUSHELL_IMAGE: &str = "ghcr.io/blue-build/nushell-image:latest";
7880
pub const OCI_ARCHIVE: &str = "oci-archive";
7981
pub const OSTREE_IMAGE_SIGNED: &str = "ostree-image-signed";
8082
pub const OSTREE_UNVERIFIED_IMAGE: &str = "ostree-unverified-image";

0 commit comments

Comments
 (0)