one more try
This commit is contained in:
parent
e9572c86e2
commit
53a917009f
@ -2,37 +2,15 @@ name: Build and Push Docker Images
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main, master ]
|
||||||
paths:
|
paths:
|
||||||
- '*/Dockerfile'
|
- '*/Dockerfile'
|
||||||
- '.gitea/workflows/docker-build.yml'
|
- '.gitea/workflows/docker-build.yml'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
detect-changes:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: git.hofer.link/philipp/ci-images:rust-latest
|
|
||||||
outputs:
|
|
||||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Detect changed directories
|
|
||||||
id: set-matrix
|
|
||||||
run: |
|
|
||||||
CHANGED_DIRS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'Dockerfile' | xargs -L1 dirname | sort | uniq | jq -R -s -c 'split("\n") | map(select(length > 0))')
|
|
||||||
echo "matrix=${CHANGED_DIRS}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: detect-changes
|
|
||||||
if: ${{ needs.detect-changes.outputs.matrix != '[]' && needs.detect-changes.outputs.matrix != '' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: git.hofer.link/philipp/ci-images:rust-latest
|
container: git.hofer.link/philipp/ci-images:rust-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
image_dir: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@ -44,16 +22,26 @@ jobs:
|
|||||||
username: ${{ secrets.GITEA_USERNAME }}
|
username: ${{ secrets.GITEA_USERNAME }}
|
||||||
password: ${{ secrets.GITEA_PASSWORD }}
|
password: ${{ secrets.GITEA_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract image name from directory
|
- name: Find changed Dockerfiles
|
||||||
id: image-name
|
id: find-changes
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME=$(basename ${{ matrix.image_dir }})
|
# Get list of changed files
|
||||||
echo "name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
|
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} || git diff --name-only HEAD~1 HEAD)
|
||||||
|
|
||||||
|
# Find directories with changed Dockerfiles
|
||||||
|
for file in $CHANGED_FILES; do
|
||||||
|
if [[ $file == */Dockerfile ]]; then
|
||||||
|
dir=$(echo $file | sed 's/\/Dockerfile$//')
|
||||||
|
echo "Building image for directory: $dir"
|
||||||
|
|
||||||
|
# Extract image name from directory
|
||||||
|
IMAGE_NAME=$(basename $dir)
|
||||||
|
echo "Building image: $IMAGE_NAME"
|
||||||
|
|
||||||
|
# Build and push the Docker image
|
||||||
|
docker build -t git.hofer.link/philipp/ci-images:$IMAGE_NAME $dir
|
||||||
|
docker push git.hofer.link/philipp/ci-images:$IMAGE_NAME
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: ${{ matrix.image_dir }}
|
|
||||||
push: true
|
|
||||||
tags: git.hofer.link/philipp/ci-images:${{ steps.image-name.outputs.name }}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user