chore: use context instead of Dockerfile
This commit is contained in:
parent
823c66003c
commit
ffbb0ec425
1 changed files with 12 additions and 73 deletions
|
@ -1,96 +1,35 @@
|
||||||
name: "Build and Push Images with Kaniko"
|
name: "Build and Push Images"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
#push:
|
||||||
paths:
|
# paths:
|
||||||
- 'apps/*/Dockerfile'
|
# - 'apps/*/Dockerfile'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
dockerfile:
|
app:
|
||||||
type: string
|
type: string
|
||||||
description: "Optional Dockerfile path to build. Example: 'apps/ci-os/Dockerfile'"
|
description: "Optional app to build. Example: 'home-assistant'"
|
||||||
required: false
|
|
||||||
image:
|
|
||||||
type: string
|
|
||||||
description: "Optional container image name. Example: 'my-org/my-image:latest'"
|
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Find all Dockerfiles under apps/* OR use the user-specified Dockerfile
|
|
||||||
discover-dockerfiles:
|
|
||||||
runs-on: ci-os
|
|
||||||
outputs:
|
|
||||||
dockerfiles: ${{ steps.set-dockerfiles.outputs.dockerfiles }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- id: set-dockerfiles
|
|
||||||
name: Resolve Dockerfiles
|
|
||||||
run: |
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# If no Dockerfiles found, output an empty array
|
|
||||||
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
|
|
||||||
json="${json%,}]"
|
|
||||||
|
|
||||||
echo "dockerfiles=$json" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
# For each Dockerfile discovered, build & push with Kaniko
|
# For each Dockerfile discovered, build & push with Kaniko
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: ci-os
|
runs-on: ci-os
|
||||||
needs: discover-dockerfiles
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
dockerfile: ${{ fromJSON(needs.discover-dockerfiles.outputs.dockerfiles) }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- id: set-image-and-context
|
- id: set-context
|
||||||
name: Determine Image Name and Context
|
name: Determine Context
|
||||||
run: |
|
run: |
|
||||||
# If the user provided a container image name, use it
|
context_dir="/workspace/apps/${{ github.event.inputs.app }}
|
||||||
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
|
|
||||||
|
|
||||||
# Derive the context directory from the Dockerfile path
|
|
||||||
# e.g. "apps/ci-os/Dockerfile" => "apps/ci-os"
|
|
||||||
context_dir=$(dirname "${{ matrix.dockerfile }}")
|
|
||||||
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
|
echo "context_dir=$context_dir" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- 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:
|
||||||
# Kaniko will look for a file named "Dockerfile" by default.
|
cache: false
|
||||||
context: ${{ steps.set-image-and-context.outputs.context_dir }}
|
context: ${{ steps.set-context.outputs.context_dir }}
|
||||||
destinations: "code.252.no/${{ github.repository }}/${{ steps.set-image-and-context.outputs.image }}:latest"
|
destinations: "code.252.no/${{ github.repository }}/${{ github.event.inputs.app }}:latest"
|
||||||
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
credentials: "code.252.no=tommy:${{ secrets.REGISTRY_TOKEN }}"
|
||||||
push: "true"
|
push: "true"
|
||||||
cache: "false"
|
|
||||||
# cache_repo: "code.252.no/${{ github.repository }}/cache"
|
|
||||||
|
|
Loading…
Reference in a new issue