From 21e2b60cf35b516f3305c64273bf0b6a0cb07676 Mon Sep 17 00:00:00 2001 From: Robert Sturla Date: Sat, 1 Feb 2025 18:15:28 +0000 Subject: [PATCH] fix: refactor workflow to support multiple images --- .github/workflows/build-dx.yml | 27 +++++++ .github/workflows/build-hwe-dx.yml | 27 +++++++ .github/workflows/build-hwe.yml | 27 +++++++ .github/workflows/build-regular.yml | 26 +++++++ ...ild-image.yml => reusable-build-image.yml} | 74 ++++++++++++------- 5 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/build-dx.yml create mode 100644 .github/workflows/build-hwe-dx.yml create mode 100644 .github/workflows/build-hwe.yml create mode 100644 .github/workflows/build-regular.yml rename .github/workflows/{build-image.yml => reusable-build-image.yml} (89%) diff --git a/.github/workflows/build-dx.yml b/.github/workflows/build-dx.yml new file mode 100644 index 0000000..a3ade5c --- /dev/null +++ b/.github/workflows/build-dx.yml @@ -0,0 +1,27 @@ +name: Build Bluefin LTS DX + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC + merge_group: + push: + branches: + - main + paths-ignore: + - "**/README.md" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + uses: ./.github/workflows/reusable-build-image.yml + with: + image-name: bluefin-dx + image-desc: "Bluefin LTS, built on CentOS Stream with bootc" + flavor: dx diff --git a/.github/workflows/build-hwe-dx.yml b/.github/workflows/build-hwe-dx.yml new file mode 100644 index 0000000..d40fcf3 --- /dev/null +++ b/.github/workflows/build-hwe-dx.yml @@ -0,0 +1,27 @@ +name: Build Bluefin LTS HWE DX + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC + merge_group: + push: + branches: + - main + paths-ignore: + - "**/README.md" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + uses: ./.github/workflows/reusable-build-image.yml + with: + image-name: bluefin-hwe-dx + image-desc: "Bluefin LTS, built on CentOS Stream with bootc" + flavor: hwe-dx diff --git a/.github/workflows/build-hwe.yml b/.github/workflows/build-hwe.yml new file mode 100644 index 0000000..cacba16 --- /dev/null +++ b/.github/workflows/build-hwe.yml @@ -0,0 +1,27 @@ +name: Build Bluefin LTS HWE + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC + merge_group: + push: + branches: + - main + paths-ignore: + - "**/README.md" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + uses: ./.github/workflows/reusable-build-image.yml + with: + image-name: bluefin-hwe + image-desc: "Bluefin LTS, built on CentOS Stream with bootc" + flavor: hwe diff --git a/.github/workflows/build-regular.yml b/.github/workflows/build-regular.yml new file mode 100644 index 0000000..c63836b --- /dev/null +++ b/.github/workflows/build-regular.yml @@ -0,0 +1,26 @@ +name: Build Bluefin LTS + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC + merge_group: + push: + branches: + - main + paths-ignore: + - "**/README.md" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + build: + uses: ./.github/workflows/reusable-build-image.yml + with: + image-name: bluefin + image-desc: "Bluefin LTS, built on CentOS Stream with bootc" diff --git a/.github/workflows/build-image.yml b/.github/workflows/reusable-build-image.yml similarity index 89% rename from .github/workflows/build-image.yml rename to .github/workflows/reusable-build-image.yml index 9d59b44..b397c53 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/reusable-build-image.yml @@ -1,40 +1,62 @@ --- name: Build Image on: - pull_request: - branches: - - main - schedule: - - cron: "0 1 * * TUE" # Every Tuesday at 1am UTC - merge_group: - push: - branches: - - main - paths-ignore: - - "**/README.md" - workflow_dispatch: + workflow_call: + inputs: + image-name: + description: "The name of the image to build" + required: true + type: string + image-desc: + description: "The description of the image to build" + required: true + type: string + flavor: + description: "The flavor of the image to build" + required: false + type: string + default: "" + platforms: + description: "The platforms to build the image for" + required: false + type: string + default: "amd64,arm64" env: - IMAGE_NAME: "bluefin" # the name of the image produced by this build, matches repo names - IMAGE_DESC: "Bluefin LTS, built on CentOS Stream with bootc" + IMAGE_NAME: ${{ inputs.image-name }} + IMAGE_DESC: ${{ inputs.image-desc }} IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}" DEFAULT_TAG: "lts" CENTOS_VERSION: "stream10" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref || github.run_id }} - cancel-in-progress: true + PLATFORMS: ${{ inputs.platforms }} jobs: + generate_matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Set matrix + id: set-matrix + run: | + # turn the comma separated string into a list + platforms=() + IFS=',' read -r -a platforms <<< "${{ inputs.platforms }}" + + MATRIX="{\"include\":[]}" + for platform in "${platforms[@]}"; do + MATRIX=$(echo $MATRIX | jq ".include += [{\"platform\": \"$platform\"}]") + done + echo "matrix=$(echo $MATRIX | jq -c '.')" >> $GITHUB_OUTPUT + build_push: name: Build and push image runs-on: ${{ matrix.platform == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }} timeout-minutes: 30 + needs: generate_matrix strategy: fail-fast: false - matrix: - platform: ["amd64", "arm64"] - flavor: ["","hwe", "dx", "hwe-dx"] + matrix: ${{fromJson(needs.generate_matrix.outputs.matrix)}} permissions: contents: read packages: write @@ -67,22 +89,22 @@ jobs: - name: Build Image id: build-image shell: bash + env: + FLAVOR: ${{ inputs.flavor }} + IMAGE_NAME: ${{ env.IMAGE_NAME }} run: | set -x just=$(which just) - IMAGE_NAME=$IMAGE_NAME - FLAVOR=${{ matrix.flavor }} + ENABLE_DX=0 ENABLE_HWE=0 if [[ "$FLAVOR" =~ "dx" ]] ; then ENABLE_DX=1 - IMAGE_NAME="${IMAGE_NAME}-dx" fi if [[ "$FLAVOR" =~ "hwe" ]] ; then ENABLE_HWE=1 - IMAGE_NAME="${IMAGE_NAME}-hwe" fi - echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV + sudo $just build "${IMAGE_NAME}" "${DEFAULT_TAG}" "$ENABLE_DX" "$ENABLE_HWE" - name: Run Rechunker