From 1de72fca33aff37605b334c2cb5c57197454753a Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Tue, 31 Oct 2017 21:38:46 +0100 Subject: [PATCH 1/7] import --- Dockerfile | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sabnzbd.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ test.sh | 28 +++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 Dockerfile create mode 100644 sabnzbd.sh create mode 100644 test.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59aab9f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +FROM debian:stretch +MAINTAINER Julien Cabillot + +RUN groupadd -r -g 666 sabnzbd && \ + useradd -l -r -u 666 -g 666 -d /sabnzbd sabnzbd + +# +# Add SABnzbd init script. +# + +COPY sabnzbd.sh /sabnzbd.sh +RUN chmod 755 /sabnzbd.sh + +# +# Fix locales to handle UTF-8 characters. +# + +ENV LANG C.UTF-8 + +# +# Install SABnzbd and all required dependencies. +# + +RUN export SABNZBD_VERSION=2.3.0 PAR2CMDLINE_VERSION=v0.6.14-mt1 && \ + export DEBIAN_FRONTEND=noninteractive && \ + export BUILD_PACKAGES="automake build-essential curl python-dev python-pip" && \ + export RUNTIME_PACKAGES="ca-certificates p7zip-full python-cheetah python-yenc unrar unzip libgomp1 openssl python-cryptography python-openssl" && \ + export PIP_PACKAGES="sabyenc" && \ + sed -i "s/ main$/ main contrib non-free/" /etc/apt/sources.list && \ + apt-get -q update && \ + apt-get install -qqy $BUILD_PACKAGES $RUNTIME_PACKAGES && \ + pip install $PIP_PACKAGES && \ + curl -SL -o /tmp/sabnzbd.tar.gz https://github.com/sabnzbd/sabnzbd/releases/download/${SABNZBD_VERSION}/SABnzbd-${SABNZBD_VERSION}-src.tar.gz && \ + tar xzf /tmp/sabnzbd.tar.gz && \ + mv SABnzbd-* sabnzbd && \ + chown -R sabnzbd: sabnzbd && \ + curl -o /tmp/par2cmdline-mt.tar.gz https://codeload.github.com/jkansanen/par2cmdline-mt/tar.gz/${PAR2CMDLINE_VERSION} && \ + tar xzf /tmp/par2cmdline-mt.tar.gz -C /tmp && \ + cd /tmp/par2cmdline-* && \ + aclocal && \ + automake --add-missing && \ + autoconf && \ + ./configure && \ + make && \ + make install && \ + apt-get -y remove --purge $BUILD_PACKAGES && \ + apt-get -y autoremove --purge && \ + apt-get -y clean all && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf /tmp/* + +# +# Define container settings. +# + +VOLUME ["/datadir", "/media"] + +EXPOSE 8080 + +# +# Start SABnzbd. +# + +WORKDIR /sabnzbd + +CMD ["/sabnzbd.sh"] diff --git a/sabnzbd.sh b/sabnzbd.sh new file mode 100644 index 0000000..78b102e --- /dev/null +++ b/sabnzbd.sh @@ -0,0 +1,60 @@ +#!/bin/bash +set -e + +# +# Display settings on standard out. +# + +USER="sabnzbd" + +echo "SABnzbd settings" +echo "================" +echo +echo " User: ${USER}" +echo " UID: ${SABNZBD_UID:=666}" +echo " GID: ${SABNZBD_GID:=666}" +echo +echo " Config: ${CONFIG:=/datadir/config.ini}" +echo + +# +# Change UID / GID of SABnzbd user. +# + +printf "Updating UID / GID... " +[[ $(id -u ${USER}) == ${SABNZBD_UID} ]] || usermod -o -u ${SABNZBD_UID} ${USER} +[[ $(id -g ${USER}) == ${SABNZBD_GID} ]] || groupmod -o -g ${SABNZBD_GID} ${USER} +echo "[DONE]" + +# +# Set directory permissions. +# + +printf "Set permissions... " +touch ${CONFIG} +chown -R ${USER}: /sabnzbd +function check_dir { + [ "$(stat -c '%u %g' $1)" == "${SABNZBD_UID} ${SABNZBD_GID}" ] || chown ${USER}: $1 +} +check_dir /datadir +check_dir /media +check_dir $(dirname ${CONFIG}) +echo "[DONE]" + +# +# Because SABnzbd runs in a container we've to make sure we've a proper +# listener on 0.0.0.0. We also have to deal with the port which by default is +# 8080 but can be changed by the user. +# + +printf "Get listener port... " +PORT=$(sed -n '/^port *=/{s/port *= *//p;q}' ${CONFIG}) +LISTENER="-s 0.0.0.0:${PORT:=8080}" +echo "[${PORT}]" + +# +# Finally, start SABnzbd. +# + +echo "Starting SABnzbd..." +exec su -pc "./SABnzbd.py -b 0 -f ${CONFIG} ${LISTENER}" ${USER} diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..371fc96 --- /dev/null +++ b/test.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# Simple test script that sees if the SABnzbd server is up within a certain number +# of seconds (TOTAL_ATTEMPTS * SLEEP_TIME). If it isn't up in time or the HTTP +# code returned is not 200, then it exits out with an error code. + +TOTAL_ATTEMPTS=10 +SLEEP_TIME=6 + +function connect_server { + http_code=$(curl -sL -w "%{http_code}\\n" "http://localhost:8080/" -o /dev/null) + curl_exit=$? +} + +attempts=0 +until [ $attempts -ge $TOTAL_ATTEMPTS ] +do + connect_server + [ "$curl_exit" == "0" ] && break + attempts=$[$attempts+1] + sleep $SLEEP_TIME +done + +if [ "$http_code" != "200" ] +then + echo "Received HTTP $http_code from SABnzbd port (last curl exit code: $curl_exit)" + exit 1 +fi From 97e90dd22e7897d9ad3fc88309f1d8a80336149c Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Tue, 31 Oct 2017 21:49:19 +0100 Subject: [PATCH 2/7] ajout du health check --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 59aab9f..2b2abc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,4 +63,7 @@ EXPOSE 8080 WORKDIR /sabnzbd +HEALTHCHECK --interval=10s \ + CMD curl --fail "http://localhost:8080" || exit 1 + CMD ["/sabnzbd.sh"] From 64c6d92e0523b038b3d4891f84993645493d3ab1 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Wed, 1 Nov 2017 12:43:14 +0000 Subject: [PATCH 3/7] Add .gitlab-ci.yml --- .gitlab-ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..2c562ae --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: docker:latest + +services: + - docker:dind + +before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + +build-master: + stage: build + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE" . + - docker push "$CI_REGISTRY_IMAGE" + only: + - master + +build: + stage: build + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" . + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" + except: + - master From 4a98cd4b23888d10b9f5564a833d8ca355636fab Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Wed, 1 Nov 2017 18:45:44 +0100 Subject: [PATCH 4/7] ajout curl pour healthcheck --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b2abc8..a2ae28b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,8 @@ RUN groupadd -r -g 666 sabnzbd && \ # Add SABnzbd init script. # -COPY sabnzbd.sh /sabnzbd.sh -RUN chmod 755 /sabnzbd.sh +COPY "sabnzbd.sh" "/sabnzbd.sh" +RUN chmod 755 "/sabnzbd.sh" # # Fix locales to handle UTF-8 characters. @@ -23,8 +23,8 @@ ENV LANG C.UTF-8 RUN export SABNZBD_VERSION=2.3.0 PAR2CMDLINE_VERSION=v0.6.14-mt1 && \ export DEBIAN_FRONTEND=noninteractive && \ - export BUILD_PACKAGES="automake build-essential curl python-dev python-pip" && \ - export RUNTIME_PACKAGES="ca-certificates p7zip-full python-cheetah python-yenc unrar unzip libgomp1 openssl python-cryptography python-openssl" && \ + export BUILD_PACKAGES="automake build-essential python-dev python-pip" && \ + export RUNTIME_PACKAGES="ca-certificates p7zip-full python-cheetah python-yenc unrar unzip libgomp1 openssl python-cryptography python-openssl curl" && \ export PIP_PACKAGES="sabyenc" && \ sed -i "s/ main$/ main contrib non-free/" /etc/apt/sources.list && \ apt-get -q update && \ @@ -61,9 +61,9 @@ EXPOSE 8080 # Start SABnzbd. # -WORKDIR /sabnzbd +WORKDIR "/sabnzbd" -HEALTHCHECK --interval=10s \ +HEALTHCHECK --interval="10s" \ CMD curl --fail "http://localhost:8080" || exit 1 CMD ["/sabnzbd.sh"] From ea5069c81d0f704c8cc85fb4a31bd95485fc864f Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 3 Nov 2017 08:49:44 +0100 Subject: [PATCH 5/7] =?UTF-8?q?m=C3=A9nage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a2ae28b..619b8b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:stretch +FROM "debian:stretch" MAINTAINER Julien Cabillot RUN groupadd -r -g 666 sabnzbd && \ @@ -46,8 +46,14 @@ RUN export SABNZBD_VERSION=2.3.0 PAR2CMDLINE_VERSION=v0.6.14-mt1 && \ apt-get -y remove --purge $BUILD_PACKAGES && \ apt-get -y autoremove --purge && \ apt-get -y clean all && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /tmp/* + rm -rf "/usr/share/doc/*" \ + "/var/cache/*" \ + "/var/lib/apt/lists/*" \ + "/usr/src/*" \ + "/var/cache/*" \ + "/var/log/"{apt/*,dpkg.log} \ + "/var/www/html" \ + "/tmp/*" # # Define container settings. From 000c242e3897d6bee81ae1c204ec67fc39199233 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Mon, 6 Nov 2017 11:44:18 +0100 Subject: [PATCH 6/7] ajout de tiny pour l'init --- Dockerfile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 619b8b2..5cc7d17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,7 +69,13 @@ EXPOSE 8080 WORKDIR "/sabnzbd" -HEALTHCHECK --interval="10s" \ - CMD curl --fail "http://localhost:8080" || exit 1 +# Add Tini +ENV "TINI_VERSION" "v0.16.1" +ADD "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini" "/tini" +RUN chmod +x "/tini" +ENTRYPOINT ["/tini", "--"] CMD ["/sabnzbd.sh"] + +HEALTHCHECK --interval="10s" \ + CMD curl --fail "http://localhost:8080" || exit 1 From 19264b502cdd5e67e14c77104dfffe12cb78ecda Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Mon, 6 Nov 2017 20:08:42 +0100 Subject: [PATCH 7/7] changement maintainer --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5cc7d17..3505972 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM "debian:stretch" -MAINTAINER Julien Cabillot +MAINTAINER "Julien Cabillot " RUN groupadd -r -g 666 sabnzbd && \ useradd -l -r -u 666 -g 666 -d /sabnzbd sabnzbd