Refactor GitHub Actions workflow for image building

This commit is contained in:
2026-02-12 17:28:58 +09:00
committed by GitHub
parent 2fd4b5b958
commit c92dec828e

View File

@@ -1,8 +1,6 @@
name: Build Container Images
on:
push:
branches: [ "main" ]
schedule:
- cron: "0 4 * * *"
workflow_dispatch:
@@ -12,8 +10,26 @@ env:
IMAGE_PREFIX: ${{ github.repository }}
jobs:
build:
discover:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.find.outputs.images }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Find image directories
id: find
run: |
images=$(find . -name Dockerfile -not -path './.github/*' \
| sed 's|/Dockerfile||; s|^\./||' \
| jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "images=${images}" >> "$GITHUB_OUTPUT"
build:
needs: discover
runs-on: ubuntu-latest
if: ${{ needs.discover.outputs.images != '[]' }}
permissions:
contents: read
packages: write
@@ -21,11 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
image:
- name: rpmbuild
context: ./rpmbuild
- name: kernel
context: ./kernel
image: ${{ fromJson(needs.discover.outputs.images) }}
steps:
- name: Checkout repository
@@ -45,15 +57,15 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.image.name }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.image }}
tags: |
type=raw,value=latest
type=raw,value={{date 'YYYYMMDD'}}
- name: Build and push ${{ matrix.image.name }}
- name: Build and push ${{ matrix.image }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image.context }}
context: ./${{ matrix.image }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}