chore(forgejo): try something new with the build workflow
This commit is contained in:
parent
c3c21547ea
commit
566e74674f
1 changed files with 35 additions and 17 deletions
|
@ -5,25 +5,38 @@ on:
|
||||||
paths:
|
paths:
|
||||||
- 'apps/*/Dockerfile'
|
- 'apps/*/Dockerfile'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
dockerfile:
|
||||||
|
description: "Optional Dockerfile path to build. Example: 'apps/ci-os/Dockerfile'"
|
||||||
|
required: false
|
||||||
|
image:
|
||||||
|
description: "Optional container image name. Example: 'my-org/my-image:latest'"
|
||||||
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# 1) Find all Dockerfiles under apps/* and output them as JSON
|
# 1) Find all Dockerfiles under apps/* OR use the user-specified Dockerfile
|
||||||
discover-dockerfiles:
|
discover-dockerfiles:
|
||||||
runs-on: ci-os
|
runs-on: ci-os
|
||||||
outputs:
|
outputs:
|
||||||
dockerfiles: ${{ steps.set-matrix.outputs.dockerfiles }}
|
dockerfiles: ${{ steps.set-dockerfiles.outputs.dockerfiles }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- id: set-matrix
|
- id: set-dockerfiles
|
||||||
name: Find Dockerfiles
|
name: Resolve Dockerfiles
|
||||||
run: |
|
run: |
|
||||||
# Find all Dockerfiles in apps/* subdirectories
|
# If 'dockerfile' was provided via workflow_dispatch, use it directly:
|
||||||
|
if [ -n "${{ github.event.inputs.dockerfile }}" ]; then
|
||||||
|
echo "Single Dockerfile specified: ${{ github.event.inputs.dockerfile }}"
|
||||||
|
echo "dockerfiles=[\"${{ github.event.inputs.dockerfile }}\"]" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Otherwise, discover all Dockerfiles in apps/*:
|
||||||
files=$(find apps -mindepth 2 -maxdepth 2 -type f -name Dockerfile)
|
files=$(find apps -mindepth 2 -maxdepth 2 -type f -name Dockerfile)
|
||||||
|
|
||||||
# If no Dockerfiles found, output an empty array to avoid parsing errors
|
# If no Dockerfiles found, output an empty array
|
||||||
if [ -z "$files" ]; then
|
if [ -z "$files" ]; then
|
||||||
echo 'dockerfiles=[]' >> "$GITHUB_OUTPUT"
|
echo 'dockerfiles=[]' >> "$GITHUB_OUTPUT"
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -34,10 +47,8 @@ jobs:
|
||||||
for f in $files; do
|
for f in $files; do
|
||||||
json="${json}\"$f\","
|
json="${json}\"$f\","
|
||||||
done
|
done
|
||||||
# Remove trailing comma and close array
|
|
||||||
json="${json%,}]"
|
json="${json%,}]"
|
||||||
|
|
||||||
# Write to job output
|
|
||||||
echo "dockerfiles=$json" >> "$GITHUB_OUTPUT"
|
echo "dockerfiles=$json" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# 2) For each Dockerfile discovered, build & push with Kaniko
|
# 2) For each Dockerfile discovered, build & push with Kaniko
|
||||||
|
@ -50,21 +61,28 @@ jobs:
|
||||||
dockerfile: ${{ fromJSON(needs.discover-dockerfiles.outputs.dockerfiles) }}
|
dockerfile: ${{ fromJSON(needs.discover-dockerfiles.outputs.dockerfiles) }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- id: set-image
|
||||||
|
name: Determine Image Name
|
||||||
|
run: |
|
||||||
|
# If the user provided a container image name, use it
|
||||||
|
if [ -n "${{ github.event.inputs.image }}" ]; then
|
||||||
|
echo "image=${{ github.event.inputs.image }}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
# Otherwise parse from the Dockerfile path
|
||||||
|
# e.g. "apps/ci-os/Dockerfile" => "ci-os"
|
||||||
|
image=$(echo "${{ matrix.dockerfile }}" | sed 's|apps/||g' | sed 's|/Dockerfile||g')
|
||||||
|
echo "image=$image" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
- 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:
|
||||||
context: ./
|
context: ./
|
||||||
dockerfile: ${{ matrix.dockerfile }}
|
dockerfile: ${{ matrix.dockerfile }}
|
||||||
destinations: >
|
destinations: "code.252.no/${{ github.repository }}/${{ steps.set-image.outputs.image }}:latest"
|
||||||
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 }}"
|
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
||||||
push: "true"
|
push: "true"
|
||||||
cache: "false"
|
cache: "false"
|
||||||
|
|
Loading…
Reference in a new issue