Skip to content

Fix tag names

Fix tag names #2

Workflow file for this run

name: Docker Build
on:
workflow_dispatch:
push:
branches:
- feature/host_terraform_modules
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract and sanitize branch name
shell: bash
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Replace forward slashes with hyphens and remove any invalid characters
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/^-//;s/-$//')
echo "BRANCH_NAME=$SANITIZED_BRANCH" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}
cache-from: type=gha
cache-to: type=gha,mode=max