From a583bc80b9ed7ea6d1e39dfa1071221e5d858a97 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Tue, 23 Dec 2025 18:46:05 -0500 Subject: [PATCH] feat(stages): Add the ability to set the platform for a stage --- integration-tests/test-repo/recipes/stages.yml | 1 + recipe/src/stage.rs | 8 +++++++- template/templates/stages.j2 | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/integration-tests/test-repo/recipes/stages.yml b/integration-tests/test-repo/recipes/stages.yml index 7084c35d..dfc3f254 100644 --- a/integration-tests/test-repo/recipes/stages.yml +++ b/integration-tests/test-repo/recipes/stages.yml @@ -11,6 +11,7 @@ stages: - from-file: stages.yml - name: fedora-test from: fedora + platform: linux/amd64 modules: - from-file: stages.yml - name: alpine-test diff --git a/recipe/src/stage.rs b/recipe/src/stage.rs index 91147831..1c144abc 100644 --- a/recipe/src/stage.rs +++ b/recipe/src/stage.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use blue_build_utils::syntax_highlighting::highlight_ser; +use blue_build_utils::{platform::Platform, syntax_highlighting::highlight_ser}; use bon::Builder; use colored::Colorize; use miette::{Result, bail}; @@ -23,6 +23,12 @@ pub struct StageRequiredFields { /// This is set directly in a `FROM` instruction. pub from: String, + /// Run a stage on a specific platform. + /// + /// This sets the `--platform` arg on the + /// `FROM` instruction. + pub platform: Option, + /// The shell to use in the stage. #[builder(into)] #[serde(skip_serializing_if = "Option::is_none")] diff --git a/template/templates/stages.j2 b/template/templates/stages.j2 index e1cacdf3..4964e1e2 100644 --- a/template/templates/stages.j2 +++ b/template/templates/stages.j2 @@ -54,7 +54,11 @@ COPY cosign.pub /keys/{{ recipe.name|replace('/', "_") }}.pub {%- for stage in stages_ext.stages %} {%- if let Some(stage) = stage.required_fields %} # {{ stage.name|capitalize }} stage -FROM {{ stage.from }} AS {{ stage.name }} +FROM \ + {%- if let Some(platform) = stage.platform %} + --platform="{{ platform }}" \ + {%- endif %} + {{ stage.from }} AS {{ stage.name }} ARG TARGETARCH {%- if self::should_color() %}