Skip to content

Commit 9beca55

Browse files
authored
Optimize Dockerfile and add action for pushing it to DockerHub (#16)
Add a GitHub action that automatically builds an image and pushes it to the docker registry. Use the occasion to optimize the `Dockerfile`.
1 parent 8c28800 commit 9beca55

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

.github/workflows/build-docker.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Docker build and publish
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
concurrency:
8+
# We want all containers to be pushed. Don't cancel any concurent jobs.
9+
group: '${{ github.workflow }} @ ${{ github.sha}}'
10+
cancel-in-progress: true
11+
12+
jobs:
13+
docker:
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: 'recursive'
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
- name: Login to Docker Hub
25+
if: github.event_name != 'pull_request'
26+
uses: docker/login-action@v3
27+
with:
28+
username: ${{ secrets.DOCKERHUB_USERNAME }}
29+
password: ${{ secrets.DOCKERHUB_TOKEN }}
30+
- name: Get short SHA
31+
id: sha
32+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
33+
- name: Generate image metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
env:
37+
# We build multiplatform images which have an image index above the
38+
# image manifests. Attach the annotations directly to the image index.
39+
DOCKER_METADATA_ANNOTATIONS_LEVELS: "index"
40+
41+
- name: Build and push
42+
if: github.event_name != 'pull_request'
43+
uses: docker/build-push-action@v6
44+
with:
45+
context: .
46+
target: runtime
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
# We have to explicitly add the "qlever-petrimaps:latest" tag for it to work correctly,
50+
# see e.g. https://stackoverflow.com/questions/27643017/do-i-need-to-manually-tag-latest-when-pushing-to-docker-public-repository
51+
tags: >
52+
adfreiburg/qlever-petrimaps:latest,
53+
adfreiburg/qlever-petrimaps:${{ github.ref_name }},
54+
adfreiburg/qlever-petrimaps:commit-${{ steps.sha.outputs.sha_short }},
55+
56+
# Set annotations and labels that conform to the OpenContainers
57+
# Annotations Spec
58+
annotations: ${{ steps.meta.outputs.annotations }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+

Dockerfile

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:24.04 AS builder
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

5-
RUN apt-get update \
6-
&& apt-get install --no-install-recommends -y\
7-
ca-certificates \
8-
make \
9-
cmake \
10-
xxd \
11-
# careful, OpenSSL is not thread safe, you MUST use GnuTLS
12-
libcurl4-gnutls-dev \
13-
default-jre \
14-
libpng-dev \
15-
libomp-dev \
16-
g++
5+
# NOTE: OpenSSL is not thread safe, you MUST use GnuTLS.
6+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates make cmake xxd libcurl4-gnutls-dev default-jre libpng-dev libomp-dev g++
177

188
COPY CMakeLists.txt /
199
ADD cmake /cmake
2010
ADD src /src
2111
ADD web /web
2212

23-
RUN mkdir build && cd build && cmake .. && make -j8
13+
RUN mkdir build && cd build && cmake .. && make -j
14+
15+
FROM ubuntu:24.04 AS runtime
16+
17+
ENV DEBIAN_FRONTEND=noninteractive
2418

2519
WORKDIR /
20+
RUN apt update && apt install -y --no-install-recommends ca-certificates xxd libgomp1 libpng-dev libcurl4-gnutls-dev dumb-init && rm -rf /var/lib/apt/lists/*
21+
COPY --from=builder /build/petrimaps /petrimaps
2622

27-
ENTRYPOINT ["./build/petrimaps"]
23+
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
24+
CMD ["/petrimaps"]

0 commit comments

Comments
 (0)