Skip to content

Commit

Permalink
Build and push Docker image after each commit to the master (#98)
Browse files Browse the repository at this point in the history
So far, Docker images were built and pushed to Docker Hub irregularly by Hannah. Now there is a GitHub action for this, which runs after each commit to the master. Also, unlike before, these are now multiarch builds (for `linux/amd64` and `linux/arm64`). Addresses #96
  • Loading branch information
Qup42 authored Aug 15, 2024
1 parent cc7407b commit f549b97
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker build and publish

on:
push:
branches: [ master ]

concurrency:
# When this is not a pull request, then we want all the docker containers to be pushed, we therefore
# directly fall back to the commit hash which will be distinct for each push to master.
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.sha}}'
cancel-in-progress: true

jobs:
docker:
runs-on: ubuntu-24.04
steps:
- name: Checkout
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: Login to Docker Hub
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: Get PR number
id: pr
run: echo "pr_num=$(git log --format=%s -n 1 | sed -nr 's/.*\(\#([0-9]+)\)/\1/p')" >> $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
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64

# Push to dockerhub, reuse the cached steps from the previous build.
push: true

# If this is a push on master, publish with short commit sha
# else use the ref name, which has to be the tag in this case.
# We have to explicitly add the "qlever: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-ui:latest,
# Set Annotations and Labels that conform to the OpenContainers
# Annotations Spec
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}

8 changes: 0 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
FROM index.docker.io/library/python:3.12.4-alpine3.20

LABEL "org.opencontainers.image.url"="https://github.com/ad-freiburg/qlever-ui"
LABEL "org.opencontainers.image.documentation"="https://github.com/ad-freiburg/qlever-ui"
LABEL "org.opencontainers.image.source"="https://github.com/ad-freiburg/qlever-ui"
LABEL "org.opencontainers.image.licenses"="Apache-2.0"
LABEL "org.opencontainers.image.title"="QLever UI"
LABEL "org.opencontainers.image.description"="A user interface for QLever"
LABEL "org.opencontainers.image.base"="index.docker.io/library/python:3.12.4-alpine3.20"

ADD requirements.txt /app/requirements.txt

RUN set -ex \
Expand Down

0 comments on commit f549b97

Please sign in to comment.