From b744359e5aac202e0efc5da2f0f82fcaa869a944 Mon Sep 17 00:00:00 2001 From: victorbjelkholm Date: Fri, 2 Mar 2018 12:32:09 +0100 Subject: [PATCH] Various improvements to Docker Image - Smaller size (from 1.52GB to 875MB) - Ignore errors with init as repository could already be initialized if we restart a running container for example - Locks down version of wrtc - Upgrade from node@6 to node@9.5 Docker --- Dockerfile | 24 ++++++++++++++---------- init-and-daemon.sh | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 603a6182f0..4e0db17242 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,6 @@ -FROM node:6 - -RUN apt-get update -RUN apt-get install --yes python2.7 git-all pkg-config libncurses5-dev libssl-dev libnss3-dev libexpat-dev libc6 +FROM node:9.5.0 WORKDIR /usr/src/app - -COPY package.json /usr/src/app/package.json - -RUN npm install -RUN npm install wrtc - COPY . /usr/src/app ENV IPFS_WRTC_LINUX_WINDOWS=1 @@ -17,9 +8,22 @@ ENV IPFS_BOOTSTRAP=1 ENV IPFS_MONITORING=1 ENV IPFS_PATH=/root/.jsipfs +ENV BUILD_DEPS='libnspr4 libnspr4-dev libnss3' + EXPOSE 4002 EXPOSE 4003 EXPOSE 5002 EXPOSE 9090 +RUN apt-get update \ + && apt-get install --yes $BUILD_DEPS \ + && rm -rf /var/lib/apt/lists/* \ + && npm install --production \ + && npm install wrtc@0.0.67 --production \ + && npm cache clear --force \ + && apt-get purge --yes $BUILD_DEPS \ + && rm -rf /usr/share/doc /usr/share/locale \ + && rm -rf /usr/local/share/.cache \ + && rm -rf node_modules/go-ipfs-dep/go-ipfs/ipfs + CMD ./init-and-daemon.sh diff --git a/init-and-daemon.sh b/init-and-daemon.sh index a01721e436..0085bce4a5 100755 --- a/init-and-daemon.sh +++ b/init-and-daemon.sh @@ -1,6 +1,18 @@ -#! /bin/sh -e -node src/cli/bin.js init +#! /usr/bin/env bash + +set -e + +if [ -n $IPFS_PATH ]; then + echo "Using $IPFS_PATH as IPFS repository" +else + echo "You need to set IPFS_PATH environment variable to use this script" + exit 1 +fi sed -i.bak 's/127.0.0.1/0.0.0.0/g' $IPFS_PATH/config +# Initialize the repo but ignore if error if it already exists +# This can be the case when we restart a container without stopping/removing it +node src/cli/bin.js init || true + node src/cli/bin.js daemon