2025-01-03 13:06:07 +00:00
|
|
|
name: "Build and Push Images"
|
2024-11-03 20:28:20 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
2025-01-03 06:19:43 +00:00
|
|
|
inputs:
|
2025-01-03 13:06:07 +00:00
|
|
|
app:
|
2025-01-03 06:22:29 +00:00
|
|
|
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) Parse metadata.yaml -> produce JSON array of (channel, platform) items
|
|
|
|
#################################################################
|
|
|
|
read-channels:
|
|
|
|
runs-on: ci-os
|
|
|
|
outputs:
|
|
|
|
channels: ${{ steps.export-channels.outputs.channels }}
|
|
|
|
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"
|
|
|
|
|
2025-01-03 15:45:38 +00:00
|
|
|
ls -lhart /workspace/pub/containers/apps/
|
|
|
|
ls -lhart /workspace/pub/containers/apps/home-assistant
|
|
|
|
|
2025-01-03 15:30:52 +00:00
|
|
|
# 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..."
|
|
|
|
|
|
|
|
# First, get the total channel count:
|
2025-01-03 15:44:42 +00:00
|
|
|
channel_count=$(cat "$metadata_file" | yq '.channels | length')
|
2025-01-03 15:30:52 +00:00
|
|
|
|
|
|
|
# We'll build the array in bash:
|
|
|
|
result="["
|
|
|
|
for i in $(seq 0 $((channel_count - 1))); do
|
|
|
|
channel_name=$(yq e ".channels[$i].name" "$metadata_file")
|
|
|
|
# Number of platforms in this channel:
|
|
|
|
platform_count=$(yq e ".channels[$i].platforms | length" "$metadata_file")
|
|
|
|
|
|
|
|
for j in $(seq 0 $((platform_count - 1))); do
|
|
|
|
platform=$(yq e ".channels[$i].platforms[$j]" "$metadata_file")
|
|
|
|
|
|
|
|
# Append JSON object
|
|
|
|
result="${result}{\"channel\":\"${channel_name}\",\"platform\":\"${platform}\"},"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
# Remove trailing comma
|
|
|
|
result="${result%,}]"
|
|
|
|
|
|
|
|
echo "Found channel/platform combinations: $result"
|
|
|
|
|
|
|
|
# Expose as job output for the next job's matrix
|
|
|
|
echo "channels=$result" >> "$GITHUB_OUTPUT"
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
# 2) For each (channel, platform) combination -> build & push
|
|
|
|
#################################################################
|
2024-12-30 20:50:06 +00:00
|
|
|
build-and-push:
|
|
|
|
runs-on: ci-os
|
2025-01-03 15:30:52 +00:00
|
|
|
needs: read-channels
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
include: ${{ fromJSON(needs.read-channels.outputs.channels) }}
|
|
|
|
# This means: for each object in the array, we have "matrix.channel" and "matrix.platform"
|
2024-12-30 20:50:06 +00:00
|
|
|
steps:
|
2025-01-03 06:19:43 +00:00
|
|
|
- name: Checkout
|
2024-12-30 20:50:06 +00:00
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2025-01-03 13:06:07 +00:00
|
|
|
- id: set-context
|
|
|
|
name: Determine Context
|
2025-01-03 06:19:43 +00:00
|
|
|
run: |
|
2025-01-03 15:30:52 +00:00
|
|
|
# We'll reuse the same directory from job #1
|
2025-01-03 13:09:45 +00:00
|
|
|
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
|
2025-01-03 12:56:54 +00:00
|
|
|
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
|
|
|
|
|
2025-01-03 13:52:14 +00:00
|
|
|
- id: read-version
|
|
|
|
name: Read Version from version.sh
|
|
|
|
run: |
|
|
|
|
version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "")
|
2025-01-03 15:30:52 +00:00
|
|
|
echo "Building channel '${{ matrix.channel }}' with platform '${{ matrix.platform }}'"
|
|
|
|
echo "Version: $version"
|
2025-01-03 13:52:14 +00:00
|
|
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
|
|
|
2024-12-30 20:50:06 +00:00
|
|
|
- name: Build and Push with Kaniko
|
|
|
|
uses: https://code.252.no/pub/kaniko-action@latest
|
|
|
|
with:
|
2025-01-03 15:30:52 +00:00
|
|
|
# We pass the directory that holds Dockerfile, metadata.yaml, ci/version.sh, etc.
|
2025-01-03 13:06:07 +00:00
|
|
|
context: ${{ steps.set-context.outputs.context_dir }}
|
2025-01-03 15:30:52 +00:00
|
|
|
|
|
|
|
# We'll build two tags:
|
|
|
|
# 1) :<channel>
|
|
|
|
# 2) :<version>
|
|
|
|
# Example: code.252.no/org/repo:stable, code.252.no/org/repo:2023.5.0
|
2025-01-03 13:52:14 +00:00
|
|
|
destinations: >
|
2025-01-03 15:30:52 +00:00
|
|
|
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
|
2025-01-03 13:58:20 +00:00
|
|
|
build_args: |
|
2025-01-03 15:30:52 +00:00
|
|
|
TARGETPLATFORM=${{ matrix.platform }}
|
|
|
|
VERSION=${{ steps.read-version.outputs.version }}
|
|
|
|
|
2024-12-30 20:50:06 +00:00
|
|
|
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
|
|
|
push: "true"
|
2025-01-03 13:52:14 +00:00
|
|
|
cache: "false"
|