name: Docker Build and Push
on:
push:
branches:
- main
- 'releases/**'
tags:
- v*
env:
REGISTRY_IMAGE: ghcr.io/wouterdebie/putioarr
DOCKERFILE_PATH: ./docker/Dockerfile
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
name: Build and Push Docker Image (${{ matrix.platform }})
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Determine image tags
id: docker_tags
run: |
TAGS=""
REF="${{ github.ref }}"
REF_NAME="${{ github.ref_name }}"
REGISTRY="${{ env.REGISTRY_IMAGE }}"
if [[ "$REF" == refs/tags/* ]]; then
VERSION="$REF_NAME"
TAGS="$TAGS $REGISTRY:latest,$REGISTRY:$VERSION"
elif [[ "$REF" == refs/heads/main ]]; then
TAGS="$TAGS $REGISTRY:main-latest" # Or just '$REGISTRY:latest' if you prefer
elif [[ "$REF" == refs/heads/releases/* ]]; then
BRANCH_NAME="${{ github.ref_name }}"
TAGS="$TAGS $REGISTRY:${BRANCH_NAME}-latest"
else
TAGS="$TAGS $REGISTRY:${{ github.sha }}" # Fallback to commit SHA
fi
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ${{ env.DOCKERFILE_PATH }}
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.docker_tags.outputs.TAGS }}
labels: |
org.opencontainers.image.created=${{ github.event.inputs.timestamp || github.event.head_commit.timestamp }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}
org.opencontainers.image.title=${{ env.REGISTRY_IMAGE }}
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}