Files
ci-images/.gitea/workflows/docker-build.yml
Philipp Hofer d6e4ece79b
Some checks failed
Build and Push Docker Images / build-and-push (push) Failing after 53s
ci
2025-05-19 18:03:09 +02:00

64 lines
2.1 KiB
YAML

name: Build and Push Docker Images
on:
push:
paths:
- '*/Dockerfile'
jobs:
build-and-push:
runs-on: ubuntu-latest
container: git.hofer.link/philipp/ci-images:rust-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# Install Docker if not available
- name: Install Docker
run: |
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
else
echo "Docker is already installed"
fi
# 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 }}