Browse Source

base image: switch from alpine to debian to support ipfs >= v0.6.0 (libc incompatibility)

increases image size from 67MB to 134MB
Fabian Peter Hammerle 3 years ago
parent
commit
a1c0b7cd2e
2 changed files with 37 additions and 22 deletions
  1. 25 18
      Dockerfile
  2. 12 4
      entrypoint.sh

+ 25 - 18
Dockerfile

@@ -1,27 +1,34 @@
-FROM alpine:3.12
+# on alpine with libc6-compat=1.1.24-r9:
+# > Error relocating /usr/local/bin/ipfs: __fprintf_chk: symbol not found
+# > Error relocating /usr/local/bin/ipfs: __vfprintf_chk: symbol not found
+FROM debian:buster-slim
 
-ARG JQ_PACKAGE_VERSION=1.6-r1
-# libc6-compat required due to:
-# $ readelf -l /tmp/go-ipfs/ipfs | grep 'program interpreter'
-#   [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
-ARG LIBC6_COMPAT_PACKAGE_VERSION=1.1.24-r9
-ARG TINI_PACKAGE_VERSION=0.19.0-r0
-RUN find / -xdev -type f -perm /u+s -exec chmod --changes u-s {} \; \
-    && find / -xdev -type f -perm /g+s -exec chmod --changes g-s {} \; \
-    && apk add --no-cache \
+ARG JQ_PACKAGE_VERSION=1.5+dfsg-2+b1
+ARG TINI_PACKAGE_VERSION=0.18.0-1
+ENV IPFS_PATH /ipfs-repo
+RUN apt-get update \
+    && apt-get install --no-install-recommends --yes \
         jq=$JQ_PACKAGE_VERSION \
-        libc6-compat=$LIBC6_COMPAT_PACKAGE_VERSION \
         tini=$TINI_PACKAGE_VERSION \
-    && adduser -S ipfs
-
-ENV IPFS_PATH /ipfs-repo
-RUN mkdir -m u=rwx,g=,o= $IPFS_PATH && chown ipfs $IPFS_PATH
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists \
+    && find / -xdev -type f -perm /u+s -exec chmod --changes u-s {} \; \
+    && find / -xdev -type f -perm /g+s -exec chmod --changes g-s {} \; \
+    && useradd --system ipfs \
+    && mkdir --mode u=rwx,g=,o= $IPFS_PATH \
+    && chown ipfs $IPFS_PATH
 VOLUME $IPFS_PATH
 
-ARG IPFS_VERSION=0.5.0
+ARG IPFS_VERSION=0.7.0
 COPY ipfs-arch.sh /
-RUN wget -O- https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-$(/ipfs-arch.sh).tar.gz \
+ARG INSTALL_DEPENDENCIES="wget ca-certificates"
+RUN apt-get update \
+    && apt-get install --no-install-recommends --yes $INSTALL_DEPENDENCIES \
+    && wget -O- https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-$(/ipfs-arch.sh).tar.gz \
         | tar -xz -C /tmp \
+    && apt-get purge --yes --autoremove $INSTALL_DEPENDENCIES \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists \
     && mv /tmp/go-ipfs/ipfs /usr/local/bin \
     && rm -r /tmp/go-ipfs
 
@@ -32,7 +39,7 @@ ENV IPFS_CONFIG_PATH="${IPFS_PATH}/config" \
     IPFS_BOOTSTRAP_ADD=
 COPY entrypoint.sh /
 RUN chmod a=rx /entrypoint.sh
-ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
+ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"]
 
 USER ipfs
 # swarm

+ 12 - 4
entrypoint.sh

@@ -1,29 +1,37 @@
 #!/bin/sh
+set -eu
 
-function ipfs_config_jq_edit {
+ipfs_config_jq_edit() {
     tmp=$(mktemp)
     (set -x; jq "$@" < "$IPFS_CONFIG_PATH" > "$tmp")
     mv "$tmp" "$IPFS_CONFIG_PATH"
 }
 
+# --args available in jq >= 1.6
+# https://github.com/stedolan/jq/commit/66fb962a6608805f4d7667d39ad0d88158bd1262
+# compare fphammerle/docker-ipfs v0.2.0
+args_to_json_array() {
+    printf '%s\n' "$@" | jq -R . | jq -sc .
+}
+
 if [ ! -e "$IPFS_CONFIG_PATH" ]; then
     (set -x; ipfs init --empty-repo --profile $IPFS_INIT_PROFILE)
 fi
 
 if [ "$IPFS_API_ADDR" != "default" ]; then
-    ipfs_config_jq_edit '.Addresses.API = $ARGS.positional[0]' --args "$IPFS_API_ADDR"
+    ipfs_config_jq_edit '.Addresses.API = $ARGS[0]' --argjson ARGS "$(args_to_json_array "$IPFS_API_ADDR")"
 fi
 
 if [ "$IPFS_SWARM_ADDRS" != "default" ]; then
     # + ipfs config --json Addresses.Swarm '["/ip4/0.0.0.0/tcp/4001"]'
     # Error: api not running
-    ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS.positional' --args $IPFS_SWARM_ADDRS
+    ipfs_config_jq_edit '.Addresses.Swarm |= $ARGS' --argjson ARGS "$(args_to_json_array $IPFS_SWARM_ADDRS)"
 fi
 
 if [ ! -z "$IPFS_BOOTSTRAP_ADD" ]; then
     # + ipfs bootstrap add -- /dnsaddr/...
     # Error: api not running
-    ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS.positional | unique)' --args $IPFS_BOOTSTRAP_ADD
+    ipfs_config_jq_edit '.Bootstrap |= (. + $ARGS | unique)' --argjson ARGS "$(args_to_json_array $IPFS_BOOTSTRAP_ADD)"
 fi
 
 (set -x; exec "$@")