From 19c93ce74209c4cd71fe15b4d0692507af052f44 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Wed, 27 Mar 2024 00:08:58 -0400 Subject: [PATCH] fix: Put export script in own image HEREDOC support for podman doesn't work exactly 1-1 with Dockerfiles. This fix gives the export script its own image that we mount. --- .github/workflows/build-pr.yml | 4 ++++ .github/workflows/build.yml | 4 ++++ Earthfile | 9 +++++++++ template/templates/export.sh => exports.sh | 0 recipe/src/module.rs | 10 ++++------ template/src/lib.rs | 6 ------ template/templates/Containerfile.j2 | 1 + template/templates/modules/modules.j2 | 15 +++++++-------- template/templates/stages.j2 | 8 -------- 9 files changed, 29 insertions(+), 28 deletions(-) rename template/templates/export.sh => exports.sh (100%) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index f95b5e8..b48712c 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -44,6 +44,8 @@ jobs: packages: write timeout-minutes: 60 runs-on: ubuntu-latest + needs: + - build steps: - name: Maximize build space @@ -78,6 +80,8 @@ jobs: contents: read packages: write id-token: write + needs: + - build steps: - name: Maximize build space diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf0c601..232abeb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,6 +58,8 @@ jobs: packages: write timeout-minutes: 60 runs-on: ubuntu-latest + needs: + - build steps: - name: Maximize build space @@ -92,6 +94,8 @@ jobs: contents: read packages: write id-token: write + needs: + - build steps: - name: Maximize build space diff --git a/Earthfile b/Earthfile index d638bfb..03c0d04 100644 --- a/Earthfile +++ b/Earthfile @@ -10,6 +10,9 @@ all: BUILD ./integration-tests+all build: + WAIT + BUILD +exports-script + END BUILD +lint BUILD +test BUILD +blue-build-cli @@ -33,6 +36,12 @@ install: SAVE ARTIFACT target/$BUILD_TARGET/release/bluebuild +exports-script: + FROM alpine + COPY exports.sh / + RUN chmod +x exports.sh + SAVE IMAGE --push ghcr.io/blue-build/cli/exports + common: FROM ghcr.io/blue-build/earthly-lib/cargo-builder diff --git a/template/templates/export.sh b/exports.sh similarity index 100% rename from template/templates/export.sh rename to exports.sh diff --git a/recipe/src/module.rs b/recipe/src/module.rs index 68c6f41..17d23c4 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -75,12 +75,10 @@ impl<'a> Module<'a> { #[must_use] pub fn print_module_context(&'a self) -> String { - serde_json::to_string(self) - .unwrap_or_else(|e| { - error!("Failed to parse module!!!!!: {e}"); - process::exit(1); - }) - .replace('"', r#"\""#) + serde_json::to_string(self).unwrap_or_else(|e| { + error!("Failed to parse module!!!!!: {e}"); + process::exit(1); + }) } #[must_use] diff --git a/template/src/lib.rs b/template/src/lib.rs index 1c37e22..1f4a953 100644 --- a/template/src/lib.rs +++ b/template/src/lib.rs @@ -75,12 +75,6 @@ pub struct GithubIssueTemplate<'a> { terminal_version: Cow<'a, str>, } -fn print_export_script() -> String { - trace!("print_export_script()"); - - include_str!("../templates/export.sh").replace('$', r"\$") -} - fn has_cosign_file() -> bool { trace!("has_cosign_file()"); std::env::current_dir() diff --git a/template/templates/Containerfile.j2 b/template/templates/Containerfile.j2 index a7afaf3..cb04655 100644 --- a/template/templates/Containerfile.j2 +++ b/template/templates/Containerfile.j2 @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 {%- include "stages.j2" %} FROM {{ recipe.base_image }}:{{ recipe.image_version }} diff --git a/template/templates/modules/modules.j2 b/template/templates/modules/modules.j2 index 0e5a991..4ffd7b3 100644 --- a/template/templates/modules/modules.j2 +++ b/template/templates/modules/modules.j2 @@ -27,15 +27,14 @@ 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=stage-exports,src=/exports.sh,dst=/tmp/exports.sh \ + --mount=type=bind,from=ghcr.io/blue-build/cli/exports,src=/exports.sh,dst=/tmp/exports.sh \ --mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \ - /bin/bash -c " \ - 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" + 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 {%- endif %} {%- endif %} {%- endfor %} diff --git a/template/templates/stages.j2 b/template/templates/stages.j2 index db9fbc6..9c56fa3 100644 --- a/template/templates/stages.j2 +++ b/template/templates/stages.j2 @@ -42,11 +42,3 @@ COPY cosign.pub /keys/{{ recipe.name|replace('/', "_") }}.pub {%- endif %} {%- include "modules/akmods/akmods.j2" %} - -# This stage is responsible for holding onto -# exports like the exports.sh -FROM docker.io/alpine as stage-exports -COPY <