diff --git a/Docker.expt b/Docker.expt deleted file mode 100644 index 022c966fc9709c4185ead67a02ef794e827354a1..0000000000000000000000000000000000000000 --- a/Docker.expt +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/expect -set timeout 15; -spawn java -jar /tmp/i2pinstall.jar -console -expect { - -re ".*press 1 to continue, 2 to quit, 3 to redisplay" {send "1\r"; exp_continue;} - -re "Select target path *" {send "/opt/i2p\r"; exp_continue;} -} diff --git a/Dockerfile b/Dockerfile index 8f591f87fe48bcaf9711b0a6188326601377ecc3..4d78585c09887ff6e54f03274ce12d02eeade6f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,47 +1,32 @@ -# Use a multi-stage build to reduce the size of the resulting image -# We need alpine >v3 in order to install an apache-ant > 1.9 -FROM alpine:3 as builder -ENV I2P_PREFIX="/opt/i2p" +FROM jlesage/baseimage:alpine-3.10-glibc +ENV APP_HOME="/i2p" WORKDIR /tmp/build -COPY . ./ +COPY . . -# Build installer -RUN apk --no-cache add build-base gettext tar bzip2 apache-ant openjdk8 expect +# Build package +RUN add-pkg openjdk8-jre +RUN add-pkg --virtual build-base gettext tar bzip2 apache-ant openjdk8 RUN echo "noExe=true" >> build.properties -RUN ant installer-linux -RUN mkdir -p /opt -RUN mv i2pinstall*.jar /tmp/i2pinstall.jar +RUN ant clean pkg +RUN del-pkg build-base gettext tar bzip2 apache-ant openjdk8 -# Install i2p using the installer into I2P_PREFIX -RUN expect -f ./Docker.expt -RUN cd ${I2P_PREFIX} -RUN rm -fr man docs *.bat *.command *.app - -# Second stage only using the installer from the last stage -# --------------------------------------------------------- -# We can't use alpine here as the java service wrapper is built with glibc -# alpine uses musl -FROM openjdk:11.0-jre-slim - -ARG I2P_UID=1000 -ARG I2P_USER=i2p -ENV I2P_PREFIX="/opt/i2p" -ENV PATH=${I2P_PREFIX}/bin:$PATH +# "install" files +RUN mkdir -p ${APP_HOME} +RUN mv pkg-temp/* ${APP_HOME} # "install" i2p by copying over installed files -COPY --from=builder /opt/i2p ${I2P_PREFIX} -COPY docker/* /opt/i2p/ +COPY docker/rootfs/ / -# Setup user and fix permissions in -RUN adduser --system --uid ${I2P_UID} --home /user ${I2P_USER} \ - && chown -R ${I2P_USER} /user \ - && chown -R ${I2P_USER} ${I2P_PREFIX} \ - && chmod -R u+rwx ${I2P_PREFIX} +# Mount home +VOLUME ["${APP_HOME}/.i2p"] EXPOSE 7654 7656 7657 7658 4444 6668 8998 7659 7660 4445 -USER i2p -ENTRYPOINT [ "/opt/i2p/i2psvc" ] -CMD [ "/opt/i2p/wrapper.config", "wrapper.pidfile=/var/tmp/i2p.pid", "wrapper.name=i2p", "wrapper.displayname=\"I2P Service\"" , "wrapper.statusfile=/var/tmp/i2p.status", "wrapper.java.statusfile=/var/tmp/i2p.java.status", "wrapper.logfile=/var/tmp/wrapper.log" ] - +# Metadata. +LABEL \ + org.label-schema.name="i2p" \ + org.label-schema.description="Docker container for I2P" \ + org.label-schema.version="1.0" \ + org.label-schema.vcs-url="https://github.com/i2p/i2p.i2p" \ + org.label-schema.schema-version="1.0" diff --git a/docker/rootfs/etc/cont-init.d/00-app-user-map.sh b/docker/rootfs/etc/cont-init.d/00-app-user-map.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d8dc519def8471af13a6a59257a41be42d417d9 --- /dev/null +++ b/docker/rootfs/etc/cont-init.d/00-app-user-map.sh @@ -0,0 +1,27 @@ +#!/usr/bin/with-contenv sh + +# +# Add the app user to the password and group databases. This is needed just to +# make sure that mapping between the user/group ID and its name is possible. +# + +set -e # Exit immediately if a command exits with a non-zero status. +set -u # Treat unset variables as an error. + +cp /defaults/passwd /etc/passwd +cp /defaults/group /etc/group +cp /defaults/shadow /etc/shadow +chown root:shadow /etc/shadow +chmod 640 /etc/shadow + +echo "$APP_USER:x:$USER_ID:$GROUP_ID::${APP_HOME:-/dev/null}:/sbin/nologin" >> /etc/passwd +echo "$APP_USER:x:$GROUP_ID:" >> /etc/group + +# Make sure APP_HOME is editable by the user +if [[ -n "$APP_HOME" ]] ; then + chown -R "$APP_USER" "$APP_HOME" + chmod -R u+rw "$APP_HOME" +fi + +# vim:ft=sh:ts=4:sw=4:et:sts=4 + diff --git a/docker/clients.config b/docker/rootfs/i2p/clients.config similarity index 100% rename from docker/clients.config rename to docker/rootfs/i2p/clients.config diff --git a/docker/i2ptunnel.config b/docker/rootfs/i2p/i2ptunnel.config similarity index 100% rename from docker/i2ptunnel.config rename to docker/rootfs/i2p/i2ptunnel.config diff --git a/docker/rootfs/startapp.sh b/docker/rootfs/startapp.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f26d35b16cf5a8bc05932589fe6d6b044f9dec5 --- /dev/null +++ b/docker/rootfs/startapp.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +# Explicitly define HOME otherwise it might not have been set +export HOME=/i2p + +export I2P=${HOME}/i2p + +echo "Starting I2P" + +cd $HOME +export CLASSPATH=. + +for jar in `ls lib/*.jar`; do + CLASSPATH=${CLASSPATH}:${jar} +done + +JAVAOPTS="-Djava.net.preferIPv4Stack=false -Djava.library.path=${I2P}:${I2P}/lib -Di2p.dir.base=${I2P} -Di2p.dir.config=${HOME}/.i2p -DloggerFilenameOverride=logs/log-router-@.txt" + +java -cp "${CLASSPATH}" ${JAVA_OPTS} net.i2p.router.RouterLaunch +