Files
2025-04-14 03:39:15 +02:00

76 lines
2.1 KiB
YAML

name: Build and Push Docker Image
permissions:
contents: read
packages: write
on:
push:
branches:
- main
- develop
tags:
- 'v*'
- '[0-9]+.*'
pull_request:
branches:
- main
env:
IMAGE_NAME: christianlouis/leagueledger
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Git Tag (if applicable)
if: startsWith(github.ref, 'refs/tags/')
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Extract metadata for tags
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/leagueledger
- name: Build and Push Docker Image with Provenance and SBOM
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
sbom: true
provenance: mode=max
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/leagueledger:latest
ghcr.io/${{ github.repository_owner }}/leagueledger:${{ github.sha }}
${{ startsWith(github.ref, 'refs/tags/') && format('{0}:{1}', env.IMAGE_NAME, env.VERSION) || '' }}
${{ startsWith(github.ref, 'refs/tags/') && format('ghcr.io/{0}/leagueledger:{1}', github.repository_owner, env.VERSION) || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max