Skip to content

Commit

Permalink
Updated kiwix-serve dockerfile from upstream
Browse files Browse the repository at this point in the history
Reusing upstream's arch logic (even though we don't need it all)
Kept our flexible VERSION handling for dev/release/nightly
Solely extracting kiwix-serve from archive
  • Loading branch information
rgaudin committed May 25, 2023
1 parent d5feaa1 commit a62019b
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions kiwix-serve/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
# dumb-init to use as entrypoint so it can forward signals to our CMD
FROM debian:bullseye-slim as builder
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
build-essential ca-certificates musl-tools wget unzip make \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
# compile dumb-init ; \
&& wget -nv https://github.com/Yelp/dumb-init/archive/refs/tags/v1.2.5.zip \
&& unzip v1.2.5.zip && cd dumb-init-1.2.5 && CC=musl-gcc make

# declare build option ARCH if not using buildx
ARG ARCH=
# declare version to build image for
ARG VERSION=

# alpine is a multi-arch image
FROM alpine:3
LABEL org.opencontainers.image.source https://github.com/offspot/container-images

# TARGETARCH is injected by buildx
ARG TARGETARCH
# TARGETPLATFORM is injected by docker build
ARG TARGETPLATFORM
ARG VERSION
ARG ARCH

# copy built dumb-init
COPY --from=builder /dumb-init-1.2.5/dumb-init /usr/bin/dumb-init

# find and store arch in image, using (in this order):
# $TARGETARCH || --build-arg ARCH (not using buildx) || amd64
RUN echo "amd64" > /etc/docker_arch && \
if [ ! -z "$ARCH" ] ; then echo "$ARCH" > /etc/docker_arch ; fi && \
if [ ! -z "$TARGETARCH" ] ; then echo "$TARGETARCH" > /etc/docker_arch ; fi \
# decide which kiwix arch to download later (`armhf` for all arm* and x86_64 otherwise); \
&& if [ $(cat /etc/docker_arch) = "arm64" ] ; then echo "aarch64" > /etc/kiwix_arch ; elif [ $(cut -c 1-3 /etc/docker_arch) = "arm" ] ; then echo "armhf" > /etc/kiwix_arch ; else echo "x86_64" > /etc/kiwix_arch ; fi \
# dev version means latest
&& if [ "$VERSION" = "dev" ] ; then export VERSION="" ; fi \
RUN set -e && \
# default (no VERSION set) means latest release
# `dev` version means today's nightly
if [ "$VERSION" = "dev" ] ; then export VERSION="$(date +"%Y-%m-%d")" ; fi && \
apk --no-cache add dumb-init curl && \
echo "TARGETPLATFORM: $TARGETPLATFORM" && \
if [ "$TARGETPLATFORM" = "linux/386" ]; then ARCH="i586"; \
# linux/arm64/v8 points to linux/arm64
elif [ "$TARGETPLATFORM" = "linux/arm64/v8" \
-o "$TARGETPLATFORM" = "linux/arm64" ]; then ARCH="aarch64"; \
# linux/arm translates to linux/arm/v7
elif [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then ARCH="armv8"; \
elif [ "$TARGETPLATFORM" = "linux/arm/v6" ]; then ARCH="armv6"; \
elif [ "$TARGETPLATFORM" = "linux/amd64/v3" \
-o "$TARGETPLATFORM" = "linux/amd64/v2" \
-o "$TARGETPLATFORM" = "linux/amd64" ]; then ARCH="x86_64"; \
# we dont suppot any other arch so let it fail
else ARCH="unknown"; fi && \
# default download source is releases
export DLFROM="https://download.kiwix.org/release/kiwix-tools" && \
# change download source for nightlies (VERSION is a date)
&& export DLFROM="https://download.kiwix.org/release/kiwix-tools/" \
&& if [[ "$VERSION" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ; then export DLFROM="https://download.kiwix.org/nightly/${VERSION}" ; fi \
# fallback version if not suppplied; \
&& if [ ! -z "$VERSION" ] ; then export VERSION="-$VERSION" ; fi \
# Install kiwix-tools
&& url="$DLFROM/kiwix-tools_linux-$(cat /etc/kiwix_arch)$VERSION.tar.gz" \
&& echo "URL: $url" \
&& wget -q -O - $url | tar -xz \
&& mv kiwix-tools*/kiwix-serve /usr/local/bin/ \
&& rm -r kiwix-tools*
if [[ "$VERSION" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] ; then \
export DLFROM="https://download.kiwix.org/nightly/${VERSION}" ; fi && \
# only non-specified (latest) release doesnt include VERSION in filename (sep by dash)
if [ ! -z "$VERSION" ] ; then export VERSION="-$VERSION" ; fi && \
export filename="kiwix-tools_linux-$ARCH$VERSION.tar.gz" && \
# download requested kiwix-tools version
url="$DLFROM/$filename" && \
echo "URL: $url" && \
if [ -z "$VERSION" ] ; then \
# fetch actual filename (latest release is a redirect)
export foldername="$(curl --head --insecure --location --silent --no-buffer $url |grep -m 1 'location:' | cut -d '/' -f 6 | sed 's/.tar.gz//' | sed 's/\r//')"; \
else export foldername=$(echo -n $filename|sed 's/.tar.gz//'); fi && \
echo "foldername: $foldername" && \
# download and extract just kiwix-serve
curl --insecure --location $url | tar -xzo -f - -C /usr/local/bin/ --strip-components 1 -- "$foldername/kiwix-serve" && \
# only needed in dockerfile
apk del curl

# expose kiwix-serve default port
EXPOSE 80
Expand Down

0 comments on commit a62019b

Please sign in to comment.