Update .forgejo/workflows/build-images.yaml
This commit is contained in:
parent
cde3ca5290
commit
4b889d9bb0
1 changed files with 91 additions and 84 deletions
|
@ -10,12 +10,10 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
#################################################################
|
#################################################################
|
||||||
# 1) Parse metadata.yaml -> produce JSON array of (channel, platform) items
|
# 1) Collect channel/platform JSON -> Upload artifact
|
||||||
#################################################################
|
#################################################################
|
||||||
read-channels:
|
matrix:
|
||||||
runs-on: ci-os
|
runs-on: ubuntu-22.04
|
||||||
outputs:
|
|
||||||
channels: ${{ steps.export-channels.outputs.channels }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -28,10 +26,7 @@ jobs:
|
||||||
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
|
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
|
||||||
metadata_file="$context_dir/metadata.yaml"
|
metadata_file="$context_dir/metadata.yaml"
|
||||||
|
|
||||||
ls -lhart /workspace/pub/containers/apps/
|
# If metadata.yaml doesn't exist, fail early
|
||||||
ls -lhart /workspace/pub/containers/apps/home-assistant
|
|
||||||
|
|
||||||
# If metadata.yaml doesn't exist, fail early.
|
|
||||||
if [ ! -f "$metadata_file" ]; then
|
if [ ! -f "$metadata_file" ]; then
|
||||||
echo "metadata.yaml not found at $metadata_file"
|
echo "metadata.yaml not found at $metadata_file"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -39,19 +34,14 @@ jobs:
|
||||||
|
|
||||||
echo "Parsing channels from $metadata_file..."
|
echo "Parsing channels from $metadata_file..."
|
||||||
|
|
||||||
# First, get the total channel count:
|
channel_count=$(yq '.channels | length' "$metadata_file")
|
||||||
channel_count=$(cat "$metadata_file" | yq '.channels | length')
|
|
||||||
|
|
||||||
# We'll build the array in bash:
|
|
||||||
result="["
|
result="["
|
||||||
for i in $(seq 0 $((channel_count - 1))); do
|
for i in $(seq 0 $((channel_count - 1))); do
|
||||||
channel_name=$(cat "$metadata_file" | yq ".channels[$i].name" )
|
channel_name=$(yq ".channels[$i].name" "$metadata_file")
|
||||||
# Number of platforms in this channel:
|
platform_count=$(yq ".channels[$i].platforms | length" "$metadata_file")
|
||||||
platform_count=$(cat "$metadata_file" | yq ".channels[$i].platforms | length")
|
|
||||||
|
|
||||||
for j in $(seq 0 $((platform_count - 1))); do
|
for j in $(seq 0 $((platform_count - 1))); do
|
||||||
platform=$(cat "$metadata_file" | yq ".channels[$i].platforms[$j]")
|
platform=$(yq ".channels[$i].platforms[$j]" "$metadata_file")
|
||||||
|
|
||||||
# Append JSON object
|
# Append JSON object
|
||||||
result="${result}{\"channel\":${channel_name},\"platform\":${platform}},"
|
result="${result}{\"channel\":${channel_name},\"platform\":${platform}},"
|
||||||
done
|
done
|
||||||
|
@ -59,22 +49,47 @@ jobs:
|
||||||
# Remove trailing comma
|
# Remove trailing comma
|
||||||
result="${result%,}]"
|
result="${result%,}]"
|
||||||
|
|
||||||
echo "Found channel/platform combinations: $result"
|
echo "Channel/Platform matrix: $result"
|
||||||
|
echo "$result" > matrix.json
|
||||||
|
|
||||||
# Expose as job output for the next job's matrix
|
- name: Upload matrix artifact
|
||||||
echo "channels=$result" >> "$GITHUB_OUTPUT"
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: matrix
|
||||||
|
path: matrix.json
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
# 2) For each (channel, platform) combination -> build & push
|
# 2) Download + parse matrix artifact -> set output
|
||||||
|
#################################################################
|
||||||
|
check-matrix:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
needs: [ matrix ]
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.extract.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: matrix
|
||||||
|
|
||||||
|
- id: extract
|
||||||
|
name: Read matrix.json
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# Using jq to "compact" the JSON into one line:
|
||||||
|
matrix="$(jq -c . matrix.json)"
|
||||||
|
echo "::set-output name=matrix::$matrix"
|
||||||
|
|
||||||
|
#################################################################
|
||||||
|
# 3) For each (channel, platform) combination -> build & push
|
||||||
#################################################################
|
#################################################################
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ci-os
|
runs-on: ubuntu-22.04
|
||||||
needs: read-channels
|
needs: [ check-matrix ]
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include: ${{ needs.read-channels.outputs.channels }}
|
# Convert the string output from check-matrix back to a JSON array
|
||||||
# This means: for each object in the array, we have "matrix.channel" and "matrix.platform"
|
includes: ${{ fromJSON(needs.check-matrix.outputs.matrix) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -97,21 +112,13 @@ jobs:
|
||||||
- name: Build and Push with Kaniko
|
- name: Build and Push with Kaniko
|
||||||
uses: https://code.252.no/pub/kaniko-action@latest
|
uses: https://code.252.no/pub/kaniko-action@latest
|
||||||
with:
|
with:
|
||||||
# We pass the directory that holds Dockerfile, metadata.yaml, ci/version.sh, etc.
|
|
||||||
context: ${{ steps.set-context.outputs.context_dir }}
|
context: ${{ steps.set-context.outputs.context_dir }}
|
||||||
|
|
||||||
# We'll build two tags:
|
|
||||||
# 1) :<channel>
|
|
||||||
# 2) :<version>
|
|
||||||
# Example: code.252.no/org/repo:stable, code.252.no/org/repo:2023.5.0
|
|
||||||
destinations: >
|
destinations: >
|
||||||
code.252.no/${{ github.repository }}/${{ github.event.inputs.app }}:${{ matrix.channel }} code.252.no/${{ github.repository }}/${{ github.event.inputs.app }}:${{ steps.read-version.outputs.version }}
|
code.252.no/${{ github.repository }}/${{ github.event.inputs.app }}:${{ matrix.channel }}
|
||||||
|
code.252.no/${{ github.repository }}/${{ github.event.inputs.app }}:${{ steps.read-version.outputs.version }}
|
||||||
# If your Dockerfile uses ARG TARGETPLATFORM (e.g. in FROM lines), pass it in build_args
|
|
||||||
build_args: |
|
build_args: |
|
||||||
TARGETPLATFORM=${{ matrix.platform }}
|
TARGETPLATFORM=${{ matrix.platform }}
|
||||||
VERSION=${{ steps.read-version.outputs.version }}
|
VERSION=${{ steps.read-version.outputs.version }}
|
||||||
|
|
||||||
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
||||||
push: "true"
|
push: "true"
|
||||||
cache: "false"
|
cache: "false"
|
||||||
|
|
Loading…
Reference in a new issue