diff --git a/.forgejo/workflows/build-images.yaml b/.forgejo/workflows/build-images.yaml index b0b3825..3cee27f 100644 --- a/.forgejo/workflows/build-images.yaml +++ b/.forgejo/workflows/build-images.yaml @@ -1,4 +1,4 @@ -name: "Build and Push Images" +name: "Build and Push Image" on: workflow_dispatch: @@ -9,108 +9,69 @@ on: required: true 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 - - - 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" - - ls -lhart /workspace/pub/containers/apps/ - ls -lhart /workspace/pub/containers/apps/home-assistant - - # 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: - channel_count=$(cat "$metadata_file" | yq '.channels | length') - - # We'll build the array in bash: - result="[" - for i in $(seq 0 $((channel_count - 1))); do - channel_name=$(cat "$metadata_file" | yq ".channels[$i].name" ) - # Number of platforms in this channel: - platform_count=$(cat "$metadata_file" | yq ".channels[$i].platforms | length") - - for j in $(seq 0 $((platform_count - 1))); do - platform=$(cat "$metadata_file" | yq ".channels[$i].platforms[$j]") - - # 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: runs-on: ci-os - needs: read-channels - strategy: - #fail-fast: false - matrix: ${{ needs.read-channels.outputs.channels }} # This means: for each object in the array, we have "matrix.channel" and "matrix.platform" steps: - name: Checkout uses: actions/checkout@v4 - id: set-context - name: Determine Context + name: Determine build 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" + echo "context_dir=$context_dir" >> $GITHUB_OUTPUT + + - id: parse-channel-platform + name: Read channel + platform from metadata.yaml + shell: bash + run: | + metadata_file="${{ steps.set-context.outputs.context_dir }}/metadata.yaml" + + echo "Looking for ${metadata_file}..." + if [ ! -f "$metadata_file" ]; then + echo "metadata.yaml not found at $metadata_file" + exit 1 + fi + + # Grab the FIRST channel name: + channel=$(yq '.channels[0].name' "$metadata_file") + + # Grab the FIRST platform under that channel: + platform=$(yq '.channels[0].platforms[0]' "$metadata_file") + + echo "Using channel='$channel' and platform='$platform'" + + # Expose for later steps + echo "channel=$channel" >> "$GITHUB_OUTPUT" + echo "platform=$platform" >> "$GITHUB_OUTPUT" - id: read-version - name: Read Version from version.sh + name: Read version from version.sh + shell: bash 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 "Discovered version: $version" echo "version=$version" >> "$GITHUB_OUTPUT" - - run: echo "Channel is ${{ matrix.channel }} and platform is ${{ matrix.platform }}" - - run: echo "Channel is ${{ matrix }}" + - name: Log chosen channel/platform + run: | + echo "Channel: ${{ steps.parse-channel-platform.outputs.channel }}" + echo "Platform: ${{ steps.parse-channel-platform.outputs.platform }}" + echo "Version: ${{ steps.read-version.outputs.version }}" - name: Build and Push with Kaniko uses: https://code.252.no/pub/kaniko-action@latest with: - # We pass the directory that holds Dockerfile, metadata.yaml, ci/version.sh, etc. + # Path that holds Dockerfile, metadata.yaml, etc. context: ${{ steps.set-context.outputs.context_dir }} - # We'll build two tags: - # 1) : - # 2) : - # Example: code.252.no/org/repo:stable, code.252.no/org/repo:2023.5.0 + # Build & push two tags: : and : 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 }}:${{ steps.parse-channel-platform.outputs.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 + # Pass any build arguments the Dockerfile expects build_args: | - TARGETPLATFORM=${{ matrix.platform }} + TARGETPLATFORM=${{ steps.parse-channel-platform.outputs.platform }} VERSION=${{ steps.read-version.outputs.version }} credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"