From 1b0a49e60654753bfd5faf6f81812b1e0af95d5c Mon Sep 17 00:00:00 2001 From: PlusMinus0 Date: Sat, 17 Nov 2018 22:53:34 +0100 Subject: [PATCH] Restructured some things and made 1000:100 the default user. Added debian base image, tests and update README.md --- Dockerfile | 23 ------------- README.md | 6 ++-- alpine.Dockerfile | 19 +++++++++++ build-n-test.sh | 21 ++++++++++++ common/entrypoint.sh | 32 ++++++++++++++++++ .../sevenzipjbinding1509.jar | Bin .../sevenzipjbinding1509Linux.jar | Bin debian.Dockerfile | 23 +++++++++++++ goss.yaml | 28 +++++++++++++++ startJD2.sh | 28 --------------- 10 files changed, 126 insertions(+), 54 deletions(-) delete mode 100644 Dockerfile create mode 100644 alpine.Dockerfile create mode 100755 build-n-test.sh create mode 100755 common/entrypoint.sh rename sevenzipjbinding1509.jar => common/sevenzipjbinding1509.jar (100%) rename sevenzipjbinding1509Linux.jar => common/sevenzipjbinding1509Linux.jar (100%) create mode 100644 debian.Dockerfile create mode 100644 goss.yaml delete mode 100755 startJD2.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index dd575ef..0000000 --- a/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM openjdk:8-jre-alpine - -MAINTAINER PlusMinus - - -# Create directory, and start JD2 for the initial update and creation of config files. -RUN \ - apk add --no-cache --quiet tini su-exec bash && \ - mkdir -p /opt/JDownloader/libs && \ - wget -O /opt/JDownloader/JDownloader.jar --user-agent="https://hub.docker.com/r/plusminus/jdownloader2-headless/" http://installer.jdownloader.org/JDownloader.jar && \ - java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar && \ - apk add --update ffmpeg - -# Beta sevenzipbindings -COPY sevenzip* /opt/JDownloader/ - -COPY startJD2.sh /opt/JDownloader/ -RUN chmod +x /opt/JDownloader/startJD2.sh - - -ENTRYPOINT ["/sbin/tini", "-g", "--", "/opt/JDownloader/startJD2.sh"] -# Run this when the container is started -CMD ["java", "-Djava.awt.headless=true", "-jar", "/opt/JDownloader/JDownloader.jar"] diff --git a/README.md b/README.md index 36b1f92..74d2822 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Headless JDownloader 2 Docker Container ## Optional environment variables |Environment Variable|Description| |--------------------|-----------| -|UID|Specifies the UID the daemon should run as. All created files will be owned by this UID. Defaults to 0 for root.| -|GID|Specifies the GID for all created files. This only works in combination with the UID. Defaults to 0 for root.| +|UID|Specifies the UID the daemon should run as. All created files will be owned by this UID. Defaults to 1000.| +|GID|Specifies the GID for all created files. This only works in combination with the UID. Defaults to 100 for users.| -Not setting these will default to root:root. If you are required to set all environment varibles, setting these to 0 will fall back to the default. +Not setting these will default to 1000:100. diff --git a/alpine.Dockerfile b/alpine.Dockerfile new file mode 100644 index 0000000..19f6ba0 --- /dev/null +++ b/alpine.Dockerfile @@ -0,0 +1,19 @@ +FROM openjdk:8-jre-alpine + +MAINTAINER PlusMinus + +# Create directory, and start JD2 for the initial update and creation of config files. +RUN apk update && apk upgrade && \ + apk add --no-cache --quiet tini su-exec shadow ffmpeg && \ + mkdir -p /opt/JDownloader/libs && \ + wget -O /opt/JDownloader/JDownloader.jar --user-agent="https://hub.docker.com/r/plusminus/jdownloader2-headless/" http://installer.jdownloader.org/JDownloader.jar && \ + java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar + +# Beta sevenzipbindings and entrypoint +COPY common/* /opt/JDownloader/ +RUN chmod +x /opt/JDownloader/entrypoint.sh + + +ENTRYPOINT ["tini", "-g", "--", "/opt/JDownloader/entrypoint.sh"] +# Run this when the container is started +CMD ["java", "-Djava.awt.headless=true", "-jar", "/opt/JDownloader/JDownloader.jar"] diff --git a/build-n-test.sh b/build-n-test.sh new file mode 100755 index 0000000..96b40a2 --- /dev/null +++ b/build-n-test.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +images=('alpine' 'debian') + +if [ "$(docker version --format '{{.Server.Experimental}}')" = 'true' ]; then + export DOCKER_BUILDKIT=1 +fi + + +for image in "${images[@]}"; do + tag="jd2dev:${image}" + + echo "Building $tag" + docker build -t $tag -f $image.Dockerfile . + + echo "Testing image" + dgoss run $tag +done + + diff --git a/common/entrypoint.sh b/common/entrypoint.sh new file mode 100755 index 0000000..f6d4282 --- /dev/null +++ b/common/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# Set defaults for uid and gid to not be root +if [ -n $GID ]; then GID=100; fi +if [ -n $UID ]; then UID=1000; fi + +if [ "$GID" -ne "0" ]; then + GROUP=jdownloader + groupadd -g $GID $GROUP +else + GROUP=root +fi + +if [ "$UID" -ne "0" ]; then + USER=jdownloader + + # Create user without home (-M) and remove login shell + useradd -M -s /bin/false -g $GID -u $UID $USER +else + USER=root + usermod -ag $GID +fi + +chown -R $UID:$GID /opt/JDownloader + +# Sometimes this gets deleted. Just copy it every time. +cp /opt/JDownloader/sevenzip* /opt/JDownloader/libs/ + +su-exec ${UID}:${GID} "$@" + +# Keep container alive when jd2 restarts +while sleep 3600; do :; done diff --git a/sevenzipjbinding1509.jar b/common/sevenzipjbinding1509.jar similarity index 100% rename from sevenzipjbinding1509.jar rename to common/sevenzipjbinding1509.jar diff --git a/sevenzipjbinding1509Linux.jar b/common/sevenzipjbinding1509Linux.jar similarity index 100% rename from sevenzipjbinding1509Linux.jar rename to common/sevenzipjbinding1509Linux.jar diff --git a/debian.Dockerfile b/debian.Dockerfile new file mode 100644 index 0000000..4e63f49 --- /dev/null +++ b/debian.Dockerfile @@ -0,0 +1,23 @@ +FROM openjdk:11-jre-slim-sid + +MAINTAINER PlusMinus + +# Create directory, and start JD2 for the initial update and creation of config files. +RUN apt-get update && apt-get dist-upgrade -yqq && \ + apt-get install -yqq tini ffmpeg wget make gcc && \ + mkdir -p /opt/JDownloader/libs && \ + wget -O /opt/JDownloader/JDownloader.jar --user-agent="https://hub.docker.com/r/plusminus/jdownloader2-headless/" http://installer.jdownloader.org/JDownloader.jar && \ + java -Djava.awt.headless=true -jar /opt/JDownloader/JDownloader.jar && \ + mkdir -p /tmp/ && \ + wget -O /tmp/su-exec.tar.gz https://github.com/ncopa/su-exec/archive/v0.2.tar.gz && \ + cd /tmp/ && tar -xf su-exec.tar.gz && cd su-exec-0.2 && make && cp su-exec /usr/bin &&\ + apt-get purge -yqq wget make gcc && apt-get autoremove -yqq && cd / && rm -rf tmp + +# Beta sevenzipbindings and entrypoint +COPY common/* /opt/JDownloader/ +RUN chmod +x /opt/JDownloader/entrypoint.sh + + +ENTRYPOINT ["tini", "-g", "--", "/opt/JDownloader/entrypoint.sh"] +# Run this when the container is started +CMD ["java", "-Djava.awt.headless=true", "-jar", "/opt/JDownloader/JDownloader.jar"] diff --git a/goss.yaml b/goss.yaml new file mode 100644 index 0000000..dd9ecdb --- /dev/null +++ b/goss.yaml @@ -0,0 +1,28 @@ +file: + /opt/JDownloader/JDownloader.jar: + exists: true + mode: "0644" + filetype: file + contains: [] + /opt/JDownloader/sevenzipjbinding1509.jar: + exists: true + mode: "0644" + filetype: file + contains: [] + /opt/JDownloader/sevenzipjbinding1509Linux.jar: + exists: true + mode: "0644" + filetype: file + contains: [] +package: + ffmpeg: + installed: true +user: + jdownloader: + exists: true + uid: 1000 + gid: 100 + groups: + - users + home: [] + shell: /bin/false diff --git a/startJD2.sh b/startJD2.sh deleted file mode 100755 index 54334b8..0000000 --- a/startJD2.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -if [ "$GID" ] && [ "$GID" -ne "0" ] -then - GROUP=jdownloader - addgroup -g $GID $GROUP -else - GROUP=root -fi - -if [ "$UID" ] && [ "$UID" -ne "0" ] -then - USER=jdownloader - adduser -S -D -s /bin/false -u $UID $USER -else - USER=root -fi - -adduser -G $GROUP $USER -chown -R $USER:$GROUP /opt/JDownloader - -# Sometimes this gets deleted. Just copy it every time. -cp /opt/JDownloader/sevenzip* /opt/JDownloader/libs/ - -su-exec ${USER}:${GROUP} "$@" - -# Keep container alive when jd2 restarts -while sleep 3600; do :; done