diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..59ef116 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM harbor.ervine.dev/library/x86_64/alpine/alpine-3.11 +MAINTAINER “Jonathan Ervine” + +ENV GETIPLAYER_OUTPUT=/config GETIPLAYER_PROFILE=/config/.get_iplayer PUID=1000 PGID=100 PORT=1935 +EXPOSE 1935 +VOLUME /config + +RUN apk --update --no-cache add ffmpeg perl-cgi perl-mojolicious perl-lwp-protocol-https perl-xml-libxml jq logrotate su-exec tini + +RUN wget -qnd "https://bitbucket.org/shield007/atomicparsley/raw/68337c0c05ec4ba2ad47012303121aaede25e6df/downloads/build_linux_x86_64/AtomicParsley" && \ + install -m 755 -t /usr/local/bin ./AtomicParsley && \ + rm ./AtomicParsley + +RUN wget -qO - "https://api.github.com/repos/get-iplayer/get_iplayer/releases/latest" > /tmp/latest.json && \ + echo get_iplayer release `jq -r .name /tmp/latest.json` && \ + wget -qO - "`jq -r .tarball_url /tmp/latest.json`" | tar -zxf - && \ + cd get-iplayer* && \ + install -m 755 -t /usr/local/bin ./get_iplayer ./get_iplayer.cgi && \ + cd / && \ + rm -rf get-iplayer* && \ + rm /tmp/latest.json + +COPY files/ / + +ENTRYPOINT ["/sbin/tini", "--"] +CMD /start diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..27ea5ac --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,18 @@ +node("docker-node") { + docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') { + + git branch: "3.11.6", url: "ssh://git@git.ervine.org/jonny/x86_64-alpine-get_iplayer", credentialsId: 'jenkins-to-git' + + sh "git rev-parse HEAD > .git/commit-id" + def commit_id = readFile('.git/commit-id').trim() + println commit_id + + stage "build" + def app = docker.build "library/x86_64/alpine/get_iplayer" + + stage "publish" + app.push("${env.BUILD_NUMBER}") + app.push("3.25") + app.push("latest") + } +} diff --git a/files/etc/crontabs/root b/files/etc/crontabs/root new file mode 100644 index 0000000..34fa92a --- /dev/null +++ b/files/etc/crontabs/root @@ -0,0 +1,5 @@ + +# min hour day month weekday command +0 * * * * run-parts /etc/periodic/hourly +0 2 * * * run-parts /etc/periodic/daily + diff --git a/files/etc/logrotate.d/get_iplayer b/files/etc/logrotate.d/get_iplayer new file mode 100644 index 0000000..521784f --- /dev/null +++ b/files/etc/logrotate.d/get_iplayer @@ -0,0 +1,8 @@ +/var/log/get_iplayer*.log { + notifempty + weekly + rotate 4 + compress + delaycompress + missingok +} diff --git a/files/etc/periodic/daily/get_iplayer_update b/files/etc/periodic/daily/get_iplayer_update new file mode 100644 index 0000000..3e11877 --- /dev/null +++ b/files/etc/periodic/daily/get_iplayer_update @@ -0,0 +1,12 @@ +#!/bin/sh +# +# Check for get_iplayer update. +# When updating will kill any active downloads launched from web front-end, but not those launched by hourly background PVR. +# +( + OLD=`get_iplayer -V 2>&1 | sed -nE 's/get_iplayer v(\d+)\.(\d+).*/\1\2/p'` # e.g. 321 + wget -qO - "https://api.github.com/repos/get-iplayer/get_iplayer/releases/latest" > /tmp/latest.json + NEW=`jq -r .name /tmp/latest.json | sed -nE 's/v(\d+)\.(\d+).*/\1\2/p'` # e.g. 322 + [ ! -z "$OLD" ] && [ ! -z "$NEW" ] && [ $OLD -lt $NEW ] && echo "Updating get_iplayer $OLD -> $NEW" 1>&2 && wget -qO - "`jq -r .tarball_url /tmp/latest.json`" | tar -zxf - && cd get-iplayer* && install -m 755 -t /usr/local/bin ./get_iplayer ./get_iplayer.cgi && cd $OLDPWD && rm -rf get-iplayer* && PID=`ps | grep "/usr/local/bin/get_iplayer.cgi" | grep -v grep | cut -c1-6` && [ ! -z "$PID" ] && kill $PID +) 2>> /var/log/get_iplayer_update.log +rm -f /tmp/latest.json diff --git a/files/etc/periodic/hourly/get_iplayer_pvr b/files/etc/periodic/hourly/get_iplayer_pvr new file mode 100644 index 0000000..6a1e4f3 --- /dev/null +++ b/files/etc/periodic/hourly/get_iplayer_pvr @@ -0,0 +1,6 @@ +#!/bin/sh +# +# Run pvr +# +umask 2 +su-exec $PUID:$PGID /usr/local/bin/get_iplayer --pvr --quiet 2>> /var/log/get_iplayer.log diff --git a/files/start b/files/start new file mode 100755 index 0000000..7863cbc --- /dev/null +++ b/files/start @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Docker entrypoint +# + +# Ensure up-to-date +/etc/periodic/daily/get_iplayer_update + +# Start cron with output to syslog +/sbin/syslogd +/usr/sbin/crond + +# Restart if killed, e.g. due to update +umask 2 +while true; do + /usr/local/bin/get_iplayer -V + su-exec $PUID:$PGID /usr/local/bin/get_iplayer.cgi -p $PORT +done