Optimize Dockerfile
and add action for pushing it to DockerHub
(…
#1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker build and publish | |
on: | |
push: | |
branches: [ master ] | |
concurrency: | |
# We want all containers to be pushed. Don't cancel any concurent jobs. | |
group: '${{ github.workflow }} @ ${{ github.sha}}' | |
cancel-in-progress: true | |
jobs: | |
docker: | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Get short SHA | |
id: sha | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Generate image metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
env: | |
# We build multiplatform images which have an image index above the | |
# image manifests. Attach the annotations directly to the image index. | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: "index" | |
- name: Build and push | |
if: github.event_name != 'pull_request' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
target: runtime | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
# We have to explicitly add the "qlever-petrimaps:latest" tag for it to work correctly, | |
# see e.g. https://stackoverflow.com/questions/27643017/do-i-need-to-manually-tag-latest-when-pushing-to-docker-public-repository | |
tags: > | |
adfreiburg/qlever-petrimaps:latest, | |
adfreiburg/qlever-petrimaps:${{ github.ref_name }}, | |
adfreiburg/qlever-petrimaps:commit-${{ steps.sha.outputs.sha_short }}, | |
# Set annotations and labels that conform to the OpenContainers | |
# Annotations Spec | |
annotations: ${{ steps.meta.outputs.annotations }} | |
labels: ${{ steps.meta.outputs.labels }} | |