From 4be5e774ffcdc7a094580f36777686ee58a85cf8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 3 Nov 2017 13:39:41 +0000 Subject: [PATCH] Peertube image --- Dockerfile | 58 ++++++++++++++++++++ Dockerfile-alpine | 40 ++++++++++++++ rootfs/PeerTube/config/production.yaml | 49 +++++++++++++++++ rootfs/etc/nginx/sites-enabled/peertube.conf | 47 ++++++++++++++++ rootfs/usr/local/bin/startup | 33 +++++++++++ 5 files changed, 227 insertions(+) create mode 100644 Dockerfile create mode 100644 Dockerfile-alpine create mode 100644 rootfs/PeerTube/config/production.yaml create mode 100644 rootfs/etc/nginx/sites-enabled/peertube.conf create mode 100755 rootfs/usr/local/bin/startup diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb6f34b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +FROM debian:jessie-slim + +ENV UID=991 GID=991 \ + HTTPS=false \ + HOSTNAME=peertube.localhost \ + PORT=80 \ + DATABASE_HOST=localhost \ + DATABASE_PORT=5432 \ + DATABASE_USERNAME=peertube \ + DATABASE_PASSWORD=peertube \ + ADMIN_EMAIL=admin@domain.local \ + SIGNUP_ENABLE=false \ + TRANSCODING_ENABLE=false \ + TRANSCODING_THREADS=2 \ + BODY_SIZE=100M \ + CACHE_SIZE=100 \ + SIGNUP_LIMIT=10 \ + RESOLUTION_280=true \ + RESOLUTION_360=true \ + RESOLUTION_480=true \ + RESOLUTION_720=true \ + RESOLUTION_1080=true \ + DEBIAN_FRONTEND=noninteractive + + +RUN echo "deb http://ftp.debian.org/debian jessie-backports main contrib non-free" >> /etc/apt/sources.list \ + && apt-get update \ + && apt-get -y install curl \ + && apt-get -y --no-install-recommends install ffmpeg openssl git build-essential nginx-light \ + && apt-get clean \ + && curl -sL https://deb.nodesource.com/setup_6.x | bash - \ + && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ + && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ + && apt-get update \ + && apt-get -y install -y nodejs yarn --no-install-recommends \ + && git clone --branch develop https://github.com/Chocobozzz/PeerTube /PeerTube \ + && cd /PeerTube \ + && npm install \ + && yarn install \ + && npm run build \ + && apt-get remove --purge --yes build-essential curl git \ + && apt-get autoremove -y \ + && apt-get clean \ + && rm -rf /PeerTube/.git \ + && rm -rf /tmp/* /var/lib/apt/lists/* /var/cache/debconf/*-old \ + && rm -rf /usr/share/man/?? \ + && rm -rf /usr/share/man/??_* + + +EXPOSE 8080 + +COPY rootfs / + +RUN chmod +x /usr/local/bin/startup + +WORKDIR /PeerTube/ +VOLUME ["/PeerTube/certs", "/PeerTube/videos", "/PeerTube/logs", "/PeerTube/previews", "/PeerTube/thumbnails", "/PeerTube/torrents"] +ENTRYPOINT ["/usr/local/bin/startup"] diff --git a/Dockerfile-alpine b/Dockerfile-alpine new file mode 100644 index 0000000..d4e8796 --- /dev/null +++ b/Dockerfile-alpine @@ -0,0 +1,40 @@ +FROM xataz/nginx + +FROM xataz/node:lts + +ENV UID=991 GID=991 \ + HTTPS=false \ + HOSTNAME=peertube.localhost \ + PORT=80 \ + DATABASE_HOST=localhost \ + DATABASE_PORT=5432 \ + DATABASE_USERNAME=peertube \ + DATABASE_PASSWORD=peertube \ + ADMIN_EMAIL=admin@domain.local \ + SIGNUP_ENABLE=false \ + TRANSCODING_ENABLE=false \ + TRANSCODING_THREADS=2 \ + BODY_SIZE=100M + +RUN apk -U upgrade \ + && apk add -t build-dependencies \ + git \ + build-base \ + g++ \ + python \ + && apk -U add yarn ffmpeg libressl su-exec curl\ + && git clone -b develop https://github.com/Chocobozzz/PeerTube /PeerTube \ + && cd /PeerTube \ + && yarn install \ + && npm install \ + && npm run build \ + && apk del build-dependencies \ + && rm -rf /var/cache/apk/* /tmp/* /root/.gnupg /root/.cache/ /PeerTube/.git + +COPY rootfs / + +RUN chmod +x /usr/local/bin/startup + +WORKDIR /PeerTube/ +VOLUME ["/PeerTube/certs", "/PeerTube/videos", "/PeerTube/logs", "/PeerTube/previews", "/PeerTube/thumbnails", "/PeerTube/torrents"] +ENTRYPOINT ["/usr/local/bin/startup"] diff --git a/rootfs/PeerTube/config/production.yaml b/rootfs/PeerTube/config/production.yaml new file mode 100644 index 0000000..9594ca5 --- /dev/null +++ b/rootfs/PeerTube/config/production.yaml @@ -0,0 +1,49 @@ +listen: + port: 9000 + +# Correspond to your reverse proxy "listen" configuration +webserver: + https: + hostname: '' + port: + +# Your database name will be "peertube"+database.suffix +database: + hostname: '' + port: + suffix: '_prod' + username: '' + password: '' + +# From the project root directory +storage: + certs: 'certs/' + videos: 'videos/' + logs: 'logs/' + previews: 'previews/' + thumbnails: 'thumbnails/' + torrents: 'torrents/' + +cache: + previews: + size: + +admin: + email: '' + +signup: + enabled: + limit: # When the limit is reached, registrations are disabled. -1 == unlimited + +# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag +# Uses a lot of CPU! +transcoding: + enabled: + threads: + resolutions: # Only created if the original video has a higher resolution + 240p: + 360p: + 480p: + 720p: + 1080p: + diff --git a/rootfs/etc/nginx/sites-enabled/peertube.conf b/rootfs/etc/nginx/sites-enabled/peertube.conf new file mode 100644 index 0000000..27028c5 --- /dev/null +++ b/rootfs/etc/nginx/sites-enabled/peertube.conf @@ -0,0 +1,47 @@ +server { + listen 8080; + + location / { + proxy_pass http://localhost:9000; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + # For the video upload + client_max_body_size ; + } + + # Bypass PeerTube webseed route for better performances + location /static/webseed { + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + + alias /PeerTube/videos; + } + + # Websocket tracker + location /tracker/socket { + # Peers send a message to the tracker every 15 minutes + # Don't close the websocket before this time + proxy_read_timeout 1200s; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_pass http://localhost:9000; + } +} diff --git a/rootfs/usr/local/bin/startup b/rootfs/usr/local/bin/startup new file mode 100755 index 0000000..c84a771 --- /dev/null +++ b/rootfs/usr/local/bin/startup @@ -0,0 +1,33 @@ +#!/bin/sh + +#addgroup --gid ${GID} peertube && adduser --disabled-password --shell /bin/sh --gid ${GID} --uid ${UID} --gecos "" peertube +groupadd -g ${GID} peertube && useradd -u ${UID} -M -g ${GID} peertube + +sed -i -e 's||'${HTTPS}'|' \ + -e 's||'${HOSTNAME}'|' \ + -e 's||'${PORT}'|' \ + -e 's||'${DATABASE_HOST}'|' \ + -e 's||'${DATABASE_PORT}'|' \ + -e 's||'${DATABASE_USERNAME}'|' \ + -e 's||'${DATABASE_PASSWORD}'|' \ + -e 's||'${ADMIN_EMAIL}'|' \ + -e 's||'${SIGNUP_ENABLE}'|' \ + -e 's||'${TRANSCODING_ENABLE}'|' \ + -e 's||'${TRANSCODING_THREADS}'|' \ + -e 's||'${CACHE_SIZE}'|' \ + -e 's||'${SIGNUP_LIMIT}'|' \ + -e 's||'${RESOLUTION_280}'|' \ + -e 's||'${RESOLUTION_360}'|' \ + -e 's||'${RESOLUTION_480}'|' \ + -e 's||'${RESOLUTION_720}'|' \ + -e 's||'${RESOLUTION_1080}'|' /PeerTube/config/production.yaml + +sed -i -e 's||'${BODY_SIZE}'|' /etc/nginx/sites-enabled/peertube.conf + +chown -R $UID:$GID ./ +nginx +if [ $# -eq 0 ]; then + su - peertube -c "cd /PeerTube && NODE_ENV=production npm start" +else + su - peertube -c "cd /PeerTube && NODE_ENV=production npm $#" +fi