misc
This commit is contained in:
parent
947d007297
commit
d6a0a3f248
1 changed files with 94 additions and 6 deletions
|
@ -1,9 +1,6 @@
|
||||||
name: "Build and Push Images"
|
name: "Build and Push Images"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
#push:
|
|
||||||
# paths:
|
|
||||||
# - 'apps/*/Dockerfile'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
app:
|
app:
|
||||||
|
@ -12,8 +9,87 @@ on:
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
#################################################################
|
||||||
|
# 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
|
||||||
|
|
||||||
|
- name: Install yq
|
||||||
|
run: |
|
||||||
|
# Adjust for your environment. Example for Debian/Ubuntu:
|
||||||
|
sudo apt-get update && sudo apt-get install -y yq
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
|
# We want a JSON array of objects like:
|
||||||
|
# [
|
||||||
|
# {"channel":"stable","platform":"linux/amd64"},
|
||||||
|
# {"channel":"beta","platform":"linux/amd64"},
|
||||||
|
# {"channel":"beta","platform":"linux/arm64"}
|
||||||
|
# ]
|
||||||
|
# We'll parse channels[].name and channels[].platforms[].
|
||||||
|
|
||||||
|
echo "Parsing channels from $metadata_file..."
|
||||||
|
|
||||||
|
# We'll produce a JSON array using yq + bash:
|
||||||
|
# for each channel in .channels[], take channel.name as "channel",
|
||||||
|
# and for each p in channel.platforms, create an object { channel, platform }.
|
||||||
|
# You can do it purely in yq or mix with shell logic. Here's one example:
|
||||||
|
|
||||||
|
# First, get the total channel count:
|
||||||
|
channel_count=$(yq e '.channels | length' "$metadata_file")
|
||||||
|
|
||||||
|
# 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
|
||||||
|
#################################################################
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ci-os
|
runs-on: ci-os
|
||||||
|
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"
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -21,6 +97,7 @@ jobs:
|
||||||
- id: set-context
|
- id: set-context
|
||||||
name: Determine Context
|
name: Determine Context
|
||||||
run: |
|
run: |
|
||||||
|
# We'll reuse the same directory from job #1
|
||||||
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
|
context_dir="/workspace/pub/containers/apps/${{ github.event.inputs.app }}"
|
||||||
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
|
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
@ -28,17 +105,28 @@ jobs:
|
||||||
name: Read Version from version.sh
|
name: Read Version from version.sh
|
||||||
run: |
|
run: |
|
||||||
version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "")
|
version=$(bash "${{ steps.set-context.outputs.context_dir }}/ci/version.sh" || echo "")
|
||||||
echo "Version being built: $version"
|
echo "Building channel '${{ matrix.channel }}' with platform '${{ matrix.platform }}'"
|
||||||
|
echo "Version: $version"
|
||||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- 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 }}:latest 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: |
|
||||||
VERSION="${{ steps.read-version.outputs.version }}"
|
TARGETPLATFORM=${{ matrix.platform }}
|
||||||
|
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