containers/.forgejo/workflows/build-images.yaml
Tommy Skaug 14a76a5d7c
Some checks failed
Build and Push Images with Kaniko / discover-dockerfiles (push) Successful in 59s
Build and Push Images with Kaniko / build-and-push (push) Failing after 4s
misc
2024-12-30 21:50:06 +01:00

71 lines
2 KiB
YAML

name: "Build and Push Images with Kaniko"
on:
push:
paths:
- 'apps/*/Dockerfile'
workflow_dispatch:
jobs:
# 1) Find all Dockerfiles under apps/* and output them as JSON
discover-dockerfiles:
runs-on: ci-os
outputs:
dockerfiles: ${{ steps.set-matrix.outputs.dockerfiles }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set-matrix
name: Find Dockerfiles
run: |
# Find all Dockerfiles in apps/* subdirectories
files=$(find apps -mindepth 2 -maxdepth 2 -type f -name Dockerfile)
# If no Dockerfiles found, output an empty array to avoid parsing errors
if [ -z "$files" ]; then
echo 'dockerfiles=[]' >> "$GITHUB_OUTPUT"
exit 0
fi
# Build a JSON array of Dockerfile paths
json="["
for f in $files; do
json="${json}\"$f\","
done
# Remove trailing comma and close array
json="${json%,}]"
# Write to job output
echo "dockerfiles=$json" >> "$GITHUB_OUTPUT"
# 2) For each Dockerfile discovered, build & push with Kaniko
build-and-push:
runs-on: ci-os
needs: discover-dockerfiles
strategy:
fail-fast: false
matrix:
dockerfile: ${{ fromJSON(needs.discover-dockerfiles.outputs.dockerfiles) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build and Push with Kaniko
uses: https://code.252.no/pub/kaniko-action@latest
with:
context: ./
dockerfile: ${{ matrix.dockerfile }}
destinations: >
code.252.no/${{ github.repository }}/${ { matrix.dockerfile
// remove `apps/`
// remove `/Dockerfile`
// e.g. "apps/ci-os/Dockerfile" => "ci-os"
// There's no built-in function to do this inline, so consider a real approach:
}}:latest
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
push: "true"
cache: "false"
# cache_repo: "code.252.no/${{ github.repository }}/cache"