diff --git a/bacon.toml b/bacon.toml index bf6551db..7b9b9d94 100644 --- a/bacon.toml +++ b/bacon.toml @@ -74,14 +74,14 @@ command = ["cargo", "install", "--path", ".", "--debug", "--locked", "--color", need_stdout = false allow_warnings = true default_watch = false -watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs"] +watch = ["src", "process", "recipe", "template", "utils", "scripts", "Cargo.toml", "build.rs"] [jobs.install-all] command = ["cargo", "install", "--all-features", "--path", ".", "--debug", "--locked", "--color", "always"] need_stdout = false allow_warnings = true default_watch = false -watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs"] +watch = ["src", "process", "recipe", "template", "utils", "scripts", "Cargo.toml", "build.rs"] # You may define here keybindings that would be specific to # a project, for example a shortcut to launch a specific job. diff --git a/recipe/src/module.rs b/recipe/src/module.rs index 98ee8910..e9701577 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -91,6 +91,13 @@ impl<'a> ModuleRequiredFields<'a> { } } + #[must_use] + pub fn is_local_source(&self) -> bool { + self.source + .as_deref() + .is_some_and(|source| source == "local") + } + #[must_use] pub fn generate_akmods_info(&'a self, os_version: &u64) -> AkmodsInfo { #[derive(Debug, Default, Copy, Clone)] diff --git a/scripts/run_module.sh b/scripts/run_module.sh index 41918554..0c138b27 100644 --- a/scripts/run_module.sh +++ b/scripts/run_module.sh @@ -19,16 +19,51 @@ print_banner() { printf '%*.*s%s%*.*s\n' 0 "$padlen" "$padding" "$text" 0 "$padlen" "$padding" } +get_script_path() { + local script_name="$1" + local extensions=("sh" "bash" "nu") + local base_script_path="/tmp/modules/${script_name}/${script_name}" + local tried_scripts=() + + # See if + if [[ -f "${base_script_path}" ]]; then + echo "${base_script_path}" + return 0 + fi + tried_scripts+=("${script_name}") + + # Iterate through each extension and check if the file exists + for ext in "${extensions[@]}"; do + local script_path="${base_script_path}.${ext}" + tried_scripts+=("${script_name}.${ext}") + + if [[ -f "$script_path" ]]; then + # Output only the script path without extra information + echo "$script_path" + return 0 # Exit the function when the first matching file is found + fi + done + + # If no matching file was found + echo "Failed to find scripts matching: ${tried_scripts[*]}" >&2 + return 1 +} + module="$1" params="$2" -script_path="/tmp/modules/${module}/${module}.sh" +script_path="$(get_script_path "$module")" color_string "$(print_banner "Start '${module}' Module")" "33" -chmod +x ${script_path} +chmod +x "${script_path}" -if ${script_path} "${params}"; then +if "${script_path}" "${params}"; then color_string "$(print_banner "End '${module}' Module")" "32" + 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/template/templates/modules/modules.j2 b/template/templates/modules/modules.j2 index 8d522e2c..b819ab5b 100644 --- a/template/templates/modules/modules.j2 +++ b/template/templates/modules/modules.j2 @@ -19,8 +19,10 @@ RUN \ {%- endif %} {%- if let Some(source) = module.get_non_local_source() %} --mount=type=bind,from={{ source }},src=/modules,dst=/tmp/modules,rw \ - {%- else %} + {%- else if module.is_local_source() %} --mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \ + {%- else %} + --mount=type=bind,from=ghcr.io/blue-build/modules/{{ module.module_type }}:latest,src=/modules,dst=/tmp/modules,rw \ {%- endif %} {%- if module.module_type == "akmods" %} --mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \ @@ -28,8 +30,7 @@ RUN \ --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/tmp/scripts/ \ --mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \ --mount=type=cache,dst=/var/cache/libdnf5,id=dnf-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \ - /tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}' \ - && ostree container commit + /tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}' {%- endif %} {%- endif %} {%- endfor %} @@ -57,8 +58,10 @@ RUN \ {%- endif %} {%- if let Some(source) = module.get_non_local_source() %} --mount=type=bind,from={{ source }},src=/modules,dst=/tmp/modules,rw \ - {%- else %} + {%- else if module.is_local_source() %} --mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \ + {%- else %} + --mount=type=bind,from=ghcr.io/blue-build/modules/{{ module.module_type }}:latest,src=/modules,dst=/tmp/modules,rw \ {%- endif %} --mount=type=bind,from={{ build_scripts_image }},src=/scripts/,dst=/tmp/scripts/ \ /tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}' diff --git a/template/templates/stages.j2 b/template/templates/stages.j2 index a61075f9..97f41497 100644 --- a/template/templates/stages.j2 +++ b/template/templates/stages.j2 @@ -9,12 +9,11 @@ FROM scratch AS stage-config COPY ./config /config {% endif %} +{%- if self::modules_exists() %} # Copy modules # The default modules are inside blue-build/modules # Custom modules overwrite defaults FROM scratch AS stage-modules -COPY --from=ghcr.io/blue-build/modules:latest /modules /modules -{%- if self::modules_exists() %} COPY ./modules /modules {% endif %} @@ -25,7 +24,8 @@ 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=ghcr.io/blue-build/cli: +COPY --from={{ blue_build_utils::constants::NUSHELL_IMAGE }} /nu/nu* /bins/ +COPY --from={{ blue_build_utils::constants::BLUE_BULID_IMAGE_REF }}: {%- if let Some(tag) = recipe.blue_build_tag -%} {{ tag }} {%- else -%} diff --git a/utils/src/constants.rs b/utils/src/constants.rs index 90ff050f..80d5790d 100644 --- a/utils/src/constants.rs +++ b/utils/src/constants.rs @@ -74,7 +74,9 @@ pub const XDG_RUNTIME_DIR: &str = "XDG_RUNTIME_DIR"; // Misc pub const BUILD_SCRIPTS_IMAGE_REF: &str = "ghcr.io/blue-build/cli/build-scripts"; +pub const BLUE_BULID_IMAGE_REF: &str = "ghcr.io/blue-build/cli"; pub const COSIGN_IMAGE: &str = "ghcr.io/sigstore/cosign/cosign:v2.4.1"; +pub const NUSHELL_IMAGE: &str = "ghcr.io/blue-build/nushell-image:latest"; pub const OCI_ARCHIVE: &str = "oci-archive"; pub const OSTREE_IMAGE_SIGNED: &str = "ostree-image-signed"; pub const OSTREE_UNVERIFIED_IMAGE: &str = "ostree-unverified-image";