ci-images/.gitea/workflows/docker-build.yml
Philipp Hofer 93b7710451
Some checks failed
Build and Push Docker Images / build (push) Failing after 11s
use variables
2025-04-06 13:24:05 +02:00

48 lines
1.4 KiB
YAML

name: Build and Push Docker Images
on:
push:
branches: [ main, ci ]
paths:
- '*/Dockerfile'
- '.gitea/workflows/docker-build.yml'
jobs:
build:
runs-on: ubuntu-latest
container: git.hofer.link/philipp/ci-images:rust-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Gitea Container Registry
uses: docker/login-action@v2
with:
registry: git.hofer.link
username: ${{ secrets.USERNAME_GITEA }}
password: ${{ secrets.PASSWORD_GITEA }}
- name: Find changed Dockerfiles
id: find-changes
run: |
# Get list of changed files
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