Some checks failed
Build and Push Docker Images / build-and-push (push) Failing after 26s
52 lines
1.5 KiB
YAML
52 lines
1.5 KiB
YAML
name: Build and Push Docker Images
|
|
|
|
on:
|
|
push:
|
|
paths:
|
|
- '*/Dockerfile'
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: docker:latest
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
# Determine which image to build
|
|
- name: Set image details
|
|
id: image_details
|
|
run: |
|
|
# Extract the directory of the changed Dockerfile
|
|
CHANGED_FILE="${{ github.event.commits[0].modified[0] }}"
|
|
if [[ $CHANGED_FILE == */Dockerfile ]]; then
|
|
IMAGE_PATH=$(dirname "$CHANGED_FILE")
|
|
else
|
|
IMAGE_PATH="rust-latest" # Default
|
|
fi
|
|
|
|
# Set outputs
|
|
echo "image_path=$IMAGE_PATH" >> $GITHUB_OUTPUT
|
|
echo "image_name=$(basename $IMAGE_PATH)" >> $GITHUB_OUTPUT
|
|
|
|
echo "Building image from directory: $IMAGE_PATH"
|
|
echo "Image name: $(basename $IMAGE_PATH)"
|
|
|
|
- name: Login to Gitea Docker Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: git.hofer.link
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Build and Push Docker image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: ./${{ steps.image_details.outputs.image_path }}
|
|
push: true
|
|
tags: git.hofer.link/philipp/ci-images:${{ steps.image_details.outputs.image_name }}
|
|
|