diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 618b0dc..abb50c7 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -53,7 +53,7 @@ jobs: id: build run: | if [ -n "${{ github.token }}" ]; then - earthly --ci --push +exports-script + earthly --ci --push +build-scripts echo "export=true" >> "$GITHUB_OUTPUT" fi earthly --ci +build diff --git a/Earthfile b/Earthfile index b402033..1e7dc9a 100644 --- a/Earthfile +++ b/Earthfile @@ -11,7 +11,7 @@ all: build: WAIT - BUILD +exports-script + BUILD +build-scripts END BUILD +lint BUILD +test @@ -36,14 +36,17 @@ install: SAVE ARTIFACT target/$BUILD_TARGET/release/bluebuild -exports-script: +build-scripts: FROM alpine LABEL org.opencontainers.image.source="https://github.com/blue-build/cli" - COPY exports.sh / - RUN chmod +x exports.sh + COPY --dir scripts/ / + FOR script IN $(ls /scripts | grep -e '.*\.sh$') + RUN echo "Making ${script} executable" && \ + chmod +x scripts/${script} + END ARG EARTHLY_GIT_HASH - SAVE IMAGE --push $IMAGE:$EARTHLY_GIT_HASH-exports + SAVE IMAGE --push $IMAGE:$EARTHLY_GIT_HASH-build-scripts common: FROM ghcr.io/blue-build/earthly-lib/cargo-builder diff --git a/exports.sh b/scripts/exports.sh similarity index 100% rename from exports.sh rename to scripts/exports.sh diff --git a/scripts/run_module.sh b/scripts/run_module.sh new file mode 100644 index 0000000..88f089f --- /dev/null +++ b/scripts/run_module.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Function to print a centered text banner within a specified width +print_banner() { + local term_width=120 + + local text=" ${1} " # Text to print + local padding="$(printf '%0.1s' '='{1..600})" + local padlen=0 + + if (( ${#text} < term_width )); then + padlen=$(( (term_width - ${#text}) / 2 )) + fi + + printf '%*.*s%s%*.*s\n' 0 "$padlen" "$padding" "$text" 0 "$padlen" "$padding" +} + +title_case() { + echo $(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1} +} + +module=$1 +params=$2 +script_path="/tmp/modules/${module}/${module}.sh" + +print_banner "Start $(title_case ${module}) Module" +chmod +x ${script_path} +${script_path} ${params} +print_banner "End $(title_case ${module}) Module" +ostree container commit diff --git a/template/templates/modules/modules.j2 b/template/templates/modules/modules.j2 index e396bc1..2699b4a 100644 --- a/template/templates/modules/modules.j2 +++ b/template/templates/modules/modules.j2 @@ -30,14 +30,10 @@ RUN \ {%- if type == "akmods" %} --mount=type=bind,from=stage-akmods-{{ module.generate_akmods_info(os_version).stage_name }},src=/rpms,dst=/tmp/rpms,rw \ {%- endif %} - --mount=type=bind,from=ghcr.io/blue-build/cli:{{ exports_tag }}-exports,src=/exports.sh,dst=/tmp/exports.sh \ + --mount=type=bind,from=ghcr.io/blue-build/cli:{{ exports_tag }}-build-scripts,src=/scripts/,dst=/tmp/scripts/ \ --mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \ - echo "========== Start {{ type|capitalize }} module ==========" \ - && chmod +x /tmp/modules/{{ type }}/{{ type }}.sh \ - && source /tmp/exports.sh \ - && /tmp/modules/{{ type }}/{{ type }}.sh '{{ module.print_module_context() }}' \ - && echo "========== End {{ type|capitalize }} module ==========" \ - && ostree container commit + source /tmp/scripts/exports.sh \ + && /tmp/scripts/run_module.sh {{ type }} '{{ module.print_module_context() }}' {%- endif %} {%- endif %} {%- endfor %}