From a1c72be2a9e33aa9c3e731d94c9589792eb8031f Mon Sep 17 00:00:00 2001 From: Darknet Villain Date: Sun, 4 Jun 2017 02:47:27 -0400 Subject: [PATCH] Add updated Dockerfile --- contrib/docker/Dockerfile | 54 ++++++++++++++++++++++++++++++++++++ contrib/docker/entrypoint.sh | 16 +++++++++++ 2 files changed, 70 insertions(+) create mode 100644 contrib/docker/Dockerfile create mode 100644 contrib/docker/entrypoint.sh diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile new file mode 100644 index 00000000..2c2c4a03 --- /dev/null +++ b/contrib/docker/Dockerfile @@ -0,0 +1,54 @@ +FROM alpine:latest +LABEL authors "Mikal Villa , Darknet Villain " + +# Expose git branch, tag and URL variables as arguments +ARG GIT_BRANCH="master" +ENV GIT_BRANCH=${GIT_BRANCH} +ARG GIT_TAG="" +ENV GIT_TAG=${GIT_TAG} +ARG REPO_URL="https://github.com/PurpleI2P/i2pd.git" +ENV REPO_URL=${REPO_URL} + +ENV I2PD_HOME="/home/i2pd" +ENV DATA_DIR="${I2PD_HOME}/data" + +RUN mkdir -p "$I2PD_HOME" \ + && adduser -S -h "$I2PD_HOME" i2pd \ + && chown -R i2pd:nobody "$I2PD_HOME" + +# +# Each RUN is a layer, adding the dependencies and building i2pd in one layer takes around 8-900Mb, so to keep the +# image under 20mb we need to remove all the build dependencies in the same "RUN" / layer. +# + +# 1. install deps, clone and build. +# 2. strip binaries. +# 3. Purge all dependencies and other unrelated packages, including build directory. +RUN apk --no-cache --virtual build-dependendencies add make gcc g++ libtool boost-dev build-base openssl-dev openssl git \ + && mkdir -p /tmp/build \ + && cd /tmp/build && git clone -b ${GIT_BRANCH} ${REPO_URL} \ + && cd i2pd \ + && if [ -n "${GIT_TAG}" ]; then git checkout tags/${GIT_TAG}; fi \ + && make \ + && cp -R contrib/certificates /i2pd_certificates \ + && mkdir -p /usr/local/bin \ + && mv i2pd /usr/local/bin \ + && cd /usr/local/bin \ + && strip i2pd \ + && rm -fr /tmp/build && apk --purge del build-dependendencies build-base fortify-headers boost-dev zlib-dev openssl-dev \ + boost-python3 python3 gdbm boost-unit_test_framework boost-python linux-headers boost-prg_exec_monitor \ + boost-serialization boost-signals boost-wave boost-wserialization boost-math boost-graph boost-regex git pcre \ + libtool g++ gcc pkgconfig + +# 2. Adding required libraries to run i2pd to ensure it will run. +RUN apk --no-cache add boost-filesystem boost-system boost-program_options boost-date_time boost-thread boost-iostreams openssl musl-utils libstdc++ + +COPY entrypoint.sh /entrypoint.sh +RUN chmod a+x /entrypoint.sh + +RUN echo "export DATA_DIR=${DATA_DIR}" >> /etc/profile +VOLUME "$DATA_DIR" +EXPOSE 7070 4444 4447 7656 2827 7654 7650 +USER i2pd + +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/contrib/docker/entrypoint.sh b/contrib/docker/entrypoint.sh new file mode 100644 index 00000000..670ff577 --- /dev/null +++ b/contrib/docker/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +COMMAND=/usr/local/bin/i2pd +# To make ports exposeable +# Note: $DATA_DIR is defined in /etc/profile +DEFAULT_ARGS=" --datadir=$DATA_DIR --reseed.verify=true --upnp.enabled=false --http.enabled=true --http.address=0.0.0.0 --httpproxy.enabled=true --httpproxy.address=0.0.0.0 --socksproxy.enabled=true --socksproxy.address=0.0.0.0 --sam.enabled=true --sam.address=0.0.0.0" + +if [ "$1" = "--help" ]; then + set -- $COMMAND --help +else + # Create datadir + mkdir -p "$DATA_DIR" + ln -s /i2pd_certificates "$DATA_DIR"/certificates + set -- $COMMAND $DEFAULT_ARGS $@ +fi + +exec "$@"