diff --git a/Dockerfile b/Dockerfile index b7d55e1..6b49b51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,10 @@ ENV BACKUPPC_XS_VERSION 0.57 ENV RSYNC_BPC_VERSION 3.0.9.12 ENV PAR2_VERSION v0.8.0 -RUN apk --no-cache --update add python3 rsync perl perl-archive-zip perl-xml-rss perl-cgi perl-file-listing expat samba-client iputils openssh openssl rrdtool msmtp lighttpd lighttpd-mod_auth gzip apache2-utils tzdata libstdc++ libgomp shadow \ +# Install backuppc runtime dependencies +RUN apk --no-cache --update add python3 rsync bash perl perl-archive-zip perl-xml-rss perl-cgi perl-file-listing expat samba-client iputils openssh openssl rrdtool msmtp lighttpd lighttpd-mod_auth gzip apache2-utils tzdata libstdc++ libgomp shadow \ # Install backuppc build dependencies - && apk --no-cache --update --virtual build-dependencies add gcc g++ libgcc autoconf automake make git patch perl-dev expat-dev curl wget \ + && apk --no-cache --update --virtual build-dependencies add gcc g++ libgcc linux-headers autoconf automake make git patch perl-dev python3-dev expat-dev curl wget \ # Install supervisor && python3 -m ensurepip \ && pip3 install --upgrade pip circus \ @@ -32,8 +33,8 @@ RUN apk --no-cache --update add python3 rsync perl perl-archive-zip perl-xml-rss # Get BackupPC, it will be installed at runtime to allow dynamic upgrade of existing config/pool && curl -o /root/BackupPC-$BACKUPPC_VERSION.tar.gz -L https://github.com/backuppc/backuppc/releases/download/$BACKUPPC_VERSION/BackupPC-$BACKUPPC_VERSION.tar.gz \ # Prepare backuppc home - && mkdir -p /home/backuppc \ -# Mark the docker as not runned yet, to allow entrypoint to do its stuff + && mkdir -p /home/backuppc && cd /home/backuppc \ +# Mark the docker as not run yet, to allow entrypoint to do its stuff && touch /firstrun \ # Clean && rm -rf /root/backuppc-xs /root/rsync-bpc /root/par2cmdline \ @@ -41,12 +42,15 @@ RUN apk --no-cache --update add python3 rsync perl perl-archive-zip perl-xml-rss COPY files/lighttpd.conf /etc/lighttpd/lighttpd.conf COPY files/entrypoint.sh /entrypoint.sh +COPY files/run.sh /run.sh COPY files/circus.ini /etc/circus.ini EXPOSE 8080 +WORKDIR /home/backuppc + VOLUME ["/etc/backuppc", "/home/backuppc", "/data/backuppc"] ENTRYPOINT ["/entrypoint.sh"] -CMD ["/usr/bin/circusd", "/etc/circus.ini"] +CMD ["/run.sh"] diff --git a/files/circus.ini b/files/circus.ini index 6317303..5aea606 100644 --- a/files/circus.ini +++ b/files/circus.ini @@ -3,6 +3,7 @@ endpoint = ipc:///var/circus/endpoint pubsub_endpoint = ipc:///var/circus/pubsub statsd = False httpd = False +working_dir = /home/backuppc [watcher:lighttpd] cmd = /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D @@ -12,4 +13,10 @@ stderr_stream.class = FancyStdoutStream [watcher:backuppc] cmd = /usr/local/BackupPC/bin/BackupPC stdout_stream.class = FancyStdoutStream -stderr_stream.class = FancyStdoutStream \ No newline at end of file +stderr_stream.class = FancyStdoutStream +uid = $(circus.env.backuppc_uuid) +gid = $(circus.env.backuppc_guid) + +[env:lighttpd] +BACKUPPC_USERNAME = $BACKUPPC_USERNAME +BACKUPPC_GROUPNAME = $BACKUPPC_GROUPNAME diff --git a/files/entrypoint.sh b/files/entrypoint.sh index 1b7c9b9..1e2b026 100755 --- a/files/entrypoint.sh +++ b/files/entrypoint.sh @@ -1,8 +1,10 @@ #!/bin/sh set -e -BACKUPPC_USERNAME=`getent passwd "${BACKUPPC_UUID:-1000}" | cut -d: -f1` -BACKUPPC_GROUPNAME=`getent group "${BACKUPPC_GUID:-1000}" | cut -d: -f1` +BACKUPPC_UUID="${BACKUPPC_UUID:-1000}" +BACKUPPC_GUID="${BACKUPPC_GUID:-1000}" +BACKUPPC_USERNAME=`getent passwd "$BACKUPPC_UUID" | cut -d: -f1` +BACKUPPC_GROUPNAME=`getent group "$BACKUPPC_GUID" | cut -d: -f1` if [ -f /firstrun ]; then echo 'First run of the container. BackupPC will be installed.' @@ -15,11 +17,11 @@ if [ -f /firstrun ]; then # Create backuppc user/group if needed if [ -z "$BACKUPPC_GROUPNAME" ]; then - groupadd -r -g "${BACKUPPC_GUID:-1000}" backuppc + groupadd -r -g "$BACKUPPC_GUID" backuppc BACKUPPC_GROUPNAME="backuppc" fi if [ -z "$BACKUPPC_USERNAME" ]; then - useradd -r -d /home/backuppc -g "${BACKUPPC_GUID:-1000}" -u ${BACKUPPC_UUID:-1000} -M -N backuppc + useradd -r -d /home/backuppc -g "$BACKUPPC_GUID" -u "$BACKUPPC_UUID" -M -N backuppc BACKUPPC_USERNAME="backuppc" else usermod -d /home/backuppc "$BACKUPPC_USERNAME" @@ -92,8 +94,14 @@ if [ -f /firstrun ]; then rm -rf /root/BackupPC-$BACKUPPC_VERSION.tar.gz /root/BackupPC-$BACKUPPC_VERSION /firstrun fi +export BACKUPPC_UUID +export BACKUPPC_GUID export BACKUPPC_USERNAME export BACKUPPC_GROUPNAME +# Executable bzip2 seems to have been moved into /usr/bin in latest Alpine version. Fix that. +ln -s /usr/bin/bzip2 /bin/bzip2 + # Exec given CMD in Dockerfile +cd /home/backuppc exec "$@" diff --git a/files/run.sh b/files/run.sh new file mode 100755 index 0000000..8d73c76 --- /dev/null +++ b/files/run.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Ensure directory and necessary sockets exists +mkdir -p /var/circus +touch /var/circus/endpoint /var/circus/pubsub /var/circus/stats + +# Launch circus +/usr/bin/circusd /etc/circus.ini diff --git a/files/supervisord.conf b/files/supervisord.conf deleted file mode 100644 index 5927fb1..0000000 --- a/files/supervisord.conf +++ /dev/null @@ -1,38 +0,0 @@ -[unix_http_server] -file = /tmp/supervisor.sock -username = dummy -password = dummy - -[supervisord] -user=root -logfile = /var/log/supervisord.log -logfile_maxbytes = 50MB -logfile_backups = 10 -loglevel = info -pidfile = /tmp/supervisord.pid -nodaemon = true -minfds = 1024 -minprocs = 200 - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[supervisorctl] -serverurl = unix:///tmp/supervisor.sock -username = dummy -password = dummy - -[program:lighttpd] -command = /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -D -redirect_stderr = true -stdout_logfile = /dev/stdout -stdout_logfile_maxbytes = 0 -stopasgroup = true -killasgroup = true - -[program:backuppc] -command = /usr/local/BackupPC/bin/BackupPC -redirect_stderr = true -stdout_logfile = /dev/stdout -stdout_logfile_maxbytes = 0 -user = %(ENV_BACKUPPC_USERNAME)s