55 lines
1.7 KiB
YAML
55 lines
1.7 KiB
YAML
name: Publish Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
paths: [ "Dockerfile" ]
|
|
pull_request:
|
|
branches: [ "main" ]
|
|
paths: [ "Dockerfile" ]
|
|
workflow_dispatch: {}
|
|
|
|
env:
|
|
REGISTRY: https://cerebra.fz-juelich.de
|
|
IMAGE_NAME: ${{ forgejo.repository }}
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
runs-on: debian-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v7
|
|
- name: Install cosign
|
|
if: forgejo.event_name != 'pull_request'
|
|
uses: sigstore/cosign-installer@v4.1.2
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4.3.0
|
|
- name: Log into registry ${{ env.REGISTRY }}
|
|
if: forgejo.event_name != 'pull_request'
|
|
uses: docker/login-action@v4.6.0
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ forgejo.actor }}
|
|
password: ${{ secrets.FORGEJO_TOKEN }}
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v6.2.0
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
- name: Build and push Docker image
|
|
id: build-and-push
|
|
uses: docker/build-push-action@v7.3.0
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: ${{ forgejo.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
- name: Sign the published Docker image
|
|
if: ${{ forgejo.event_name != 'pull_request' }}
|
|
env:
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
|
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|