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

72 lines
2 KiB
YAML
Raw Normal View History

2024-12-30 20:50:06 +00:00
name: "Build and Push Images with Kaniko"
2024-11-03 20:28:20 +00:00
on:
push:
paths:
- 'apps/*/Dockerfile'
workflow_dispatch:
2024-12-30 20:50:06 +00:00
2024-11-03 20:28:20 +00:00
jobs:
2024-12-30 20:50:06 +00:00
# 1) Find all Dockerfiles under apps/* and output them as JSON
discover-dockerfiles:
runs-on: ci-os
outputs:
dockerfiles: ${{ steps.set-matrix.outputs.dockerfiles }}
2024-11-03 20:28:20 +00:00
steps:
2024-12-30 20:50:06 +00:00
- name: Checkout
2024-11-03 20:28:20 +00:00
uses: actions/checkout@v4
2024-12-30 20:50:06 +00:00
- id: set-matrix
name: Find Dockerfiles
2024-11-03 20:28:20 +00:00
run: |
2024-12-30 20:50:06 +00:00
# Find all Dockerfiles in apps/* subdirectories
files=$(find apps -mindepth 2 -maxdepth 2 -type f -name Dockerfile)
2024-11-03 20:28:20 +00:00
2024-12-30 20:50:06 +00:00
# If no Dockerfiles found, output an empty array to avoid parsing errors
if [ -z "$files" ]; then
echo 'dockerfiles=[]' >> "$GITHUB_OUTPUT"
exit 0
fi
2024-11-03 20:28:20 +00:00
2024-12-30 20:50:06 +00:00
# Build a JSON array of Dockerfile paths
json="["
for f in $files; do
json="${json}\"$f\","
2024-11-03 20:28:20 +00:00
done
2024-12-30 20:50:06 +00:00
# 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"