containers/.forgejo/workflows/build-images.yaml

125 lines
4.3 KiB
YAML
Raw Normal View History

name: "Build and Push Images"
2024-11-03 20:28:20 +00:00
on:
workflow_dispatch:
inputs:
app:
type: string
2025-01-03 13:52:14 +00:00
description: "App to build, e.g. 'home-assistant'"
required: true
2024-12-30 20:50:06 +00:00
2024-11-03 20:28:20 +00:00
jobs:
2025-01-03 15:30:52 +00:00
#################################################################
# 1) Collect channel/platform JSON -> Upload artifact
2025-01-03 15:30:52 +00:00
#################################################################
matrix:
runs-on: ci-os
2025-01-03 15:30:52 +00:00
steps:
- name: Checkout
uses: actions/checkout@v4
- id: export-channels
name: Read channels from metadata.yaml
shell: bash
run: |
# Path to the directory with metadata.yaml
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
metadata_file="$context_dir/metadata.yaml"
# If metadata.yaml doesn't exist, fail early
if [ ! -f "$metadata_file" ]; then
echo "metadata.yaml not found at $metadata_file"
exit 1
fi
echo "Parsing channels from $metadata_file..."
channel_count=$(yq '.channels | length' "$metadata_file")
result="["
for i in $(seq 0 $((channel_count - 1))); do
channel_name=$(yq ".channels[$i].name" "$metadata_file")
platform_count=$(yq ".channels[$i].platforms | length" "$metadata_file")
for j in $(seq 0 $((platform_count - 1))); do
platform=$(yq ".channels[$i].platforms[$j]" "$metadata_file")
# Append JSON object
result="${result}{\"channel\":${channel_name},\"platform\":${platform}},"
done
2025-01-03 15:30:52 +00:00
done
# Remove trailing comma
result="${result%,}]"
echo "Channel/Platform matrix: $result"
echo "$result" > matrix.json
2025-01-03 15:30:52 +00:00
- name: Upload matrix artifact
uses: actions/upload-artifact@v3
with:
name: matrix
path: matrix.json
2025-01-03 15:30:52 +00:00
#################################################################
# 2) Download + parse matrix artifact -> set output
#################################################################
check-matrix:
runs-on: ci-os
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"
2025-01-03 15:30:52 +00:00
#################################################################
# 3) For each (channel, platform) combination -> build & push
2025-01-03 15:30:52 +00:00
#################################################################
2024-12-30 20:50:06 +00:00
build-and-push:
runs-on: ci-os
needs: [ check-matrix ]
2025-01-03 15:30:52 +00:00
strategy:
fail-fast: false
matrix:
# Convert the string output from check-matrix back to a JSON array
includes: ${{ fromJSON(needs.check-matrix.outputs.matrix) }}
2024-12-30 20:50:06 +00:00
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set-context
name: Determine Context
run: |
# We'll reuse the same directory from job #1
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
- id: read-version
name: Read Version from version.sh
run: |
version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "")
echo "Building channel '${{ matrix.channel }}' with platform '${{ matrix.platform }}'"
echo "Version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Build and Push with Kaniko
uses: https://code.252.no/pub/kaniko-action@latest
with:
context: ${{ steps.set-context.outputs.context_dir }}
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 }}
build_args: |
TARGETPLATFORM=${{ matrix.platform }}
VERSION=${{ steps.read-version.outputs.version }}
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
push: "true"
cache: "false"