Dockerize cytube and fixes for reverse proxying

This commit is contained in:
David Siaw 2017-06-02 15:01:43 +09:00
parent d0712d007e
commit d66d09f057
7 changed files with 123 additions and 22 deletions

30
Dockerfile Normal file
View file

@ -0,0 +1,30 @@
FROM alpine:3.6
ADD . /app
RUN cd app && sh container-install.sh
WORKDIR /app
ENV MYSQL_HOST localhost
ENV MYSQL_PORT 3306
ENV MYSQL_DATABASE cytube
ENV MYSQL_USER cytube
ENV MYSQL_PASSWORD nico_best_girl
ENV MYSQL_ROOT_PASSWORD ruby_best_girl
ENV SYNC_TITLE Sync
ENV SYNC_DESCRIPTION Sync Video
ENV ROOT_URL http://localhost:8080
ENV ROOT_PORT 8080
ENV IO_ROOT_URL http://localhost
ENV IO_ROOT_PORT 1337
ENV ROOT_DOMAIN localhost:8080
ENV HTTPS_ENABLED false
#ENV YOUTUBE_KEY
#ENV TWITCH_CLIENT_ID
EXPOSE 8080
# EXPOSE 1337
# EXPOSE 8443
CMD ["sh", "run.sh"]

View file

@ -80,6 +80,11 @@ Installing
Installation instructions are available here: https://github.com/calzoneman/sync/wiki/CyTube-3.0-Installation-Guide
Docker
------
`docker pull davidsiaw/sync:3.0`
Feedback
--------

View file

@ -4,11 +4,11 @@
# user: username to authenticate as
# password: password for user
mysql:
server: 'localhost'
port: 3306
database: 'cytube3'
user: 'cytube3'
password: ''
server: '${MYSQL_HOST}'
port: ${MYSQL_PORT}
database: '${MYSQL_DATABASE}'
user: '${MYSQL_USER}'
password: '${MYSQL_PASSWORD}'
pool-size: 10
# Define IPs/ports to listen on
@ -23,7 +23,7 @@ mysql:
listen:
# Default HTTP server - default interface, port 8080
- ip: ''
port: 8080
port: ${ROOT_PORT}
http: true
# Uncomment below to enable HTTPS/SSL websockets
# Note that you must also set https->enabled = true in the https definition
@ -33,7 +33,7 @@ listen:
# io: true
# Default Socket.IO server - default interface, port 1337
- ip: ''
port: 1337
port: ${IO_ROOT_PORT}
io: true
# Example of how to bind an extra port to HTTP and Socket.IO
# - ip: ''
@ -47,11 +47,12 @@ http:
# Even though you may specify multiple ports to listen on for HTTP above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 8080
domain: 'http://localhost'
full-address: "${ROOT_URL}"
default-port: ${ROOT_PORT}
domain: '${ROOT_URL}'
# Specifies the root domain for cookies. If you have multiple domains
# e.g. a.example.com and b.example.com, the root domain is example.com
root-domain: 'localhost'
root-domain: '${ROOT_DOMAIN}'
# Specify alternate domains/hosts that are allowed to set the login cookie
# Leave out the http://
alt-domains:
@ -73,12 +74,12 @@ http:
# HTTPS server details
https:
enabled: false
enabled: ${HTTPS_ENABLED}
# Even though you may specify multiple ports to listen on for HTTPS above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 8443
domain: 'https://localhost'
domain: '${ROOT_URL}'
keyfile: 'localhost.key'
passphrase: ''
certfile: 'localhost.cert'
@ -92,8 +93,8 @@ https:
# Page template values
# title goes in the upper left corner, description goes in a <meta> tag
html-template:
title: 'Sync'
description: 'Free, open source synchtube'
title: '${SYNC_TITLE}'
description: '${SYNC_DESCRIPTION}'
# Socket.IO server details
io:
@ -102,11 +103,11 @@ io:
# you will want to set up a passthrough domain for socket.io.
# If the root of this domain is not the same as the root of your HTTP domain
# (or HTTPS if SSL is enabled), logins won't work.
domain: 'http://localhost'
domain: '${IO_ROOT_URL}'
# Even though you may specify multiple ports to listen on for HTTP above,
# one port must be specified as default for the purposes of generating
# links with the appropriate port
default-port: 1337
default-port: ${IO_ROOT_PORT}
# limit the number of concurrent socket connections per IP address
ip-connection-limit: 10
# Whether or not to use zlib to compress each socket message (this option is
@ -137,7 +138,7 @@ mail:
# 4. Click "Create new Key" under "Public API access"
# 5. Click "Server key"
# 6. Under "APIs & auth" click "YouTube Data API" and then click "Enable API"
youtube-v3-key: ''
youtube-v3-key: '${YOUTUBE_KEY}'
# Minutes between saving channel state to disk
channel-save-interval: 5
# Limit for the number of channels a user can register
@ -216,7 +217,7 @@ channel-blacklist: []
# server-synched raw file playback. This requires the following:
# * ffmpeg must be installed on the server
ffmpeg:
enabled: false
enabled: true
# Executable name for ffprobe if it is not "ffprobe". On Debian and Ubuntu (on which
# libav is used rather than ffmpeg proper), this is "avprobe"
ffprobe-exec: 'ffprobe'
@ -249,7 +250,7 @@ service-socket:
# Twitch Client ID for the data API (used for VOD lookups)
# https://github.com/justintv/Twitch-API/blob/master/authentication.md#developer-setup
twitch-client-id: null
twitch-client-id: '${TWITCH_CLIENT_ID}'
poll:
max-options: 50

9
container-install.sh Normal file
View file

@ -0,0 +1,9 @@
#!/bin/sh
apk update
apk add build-base python git nodejs nodejs-npm mysql mysql-client curl gettext ffmpeg
npm install npm@latest -g
npm install
npm run build-server

View file

@ -25,7 +25,7 @@
"csrf": "^3.0.0",
"cytube-common": "git://github.com/CyTube/cytube-common",
"cytube-mediaquery": "git://github.com/CyTube/mediaquery",
"cytubefilters": "git://github.com/calzoneman/cytubefilters#67c7c69a",
"cytubefilters": "git://github.com/davidsiaw/cytubefilters",
"express": "^4.13.3",
"express-minify": "^0.1.6",
"graceful-fs": "^4.1.2",

58
run.sh
View file

@ -1,8 +1,64 @@
#!/bin/sh
#plagiarized from wangxian/alpine-mysql
if [ -d /app/mysql ]; then
echo "[i] MySQL directory already present, skipping creation"
else
echo "[i] MySQL data directory not found, creating initial DBs"
mysql_install_db --user=root > /dev/null
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
MYSQL_ROOT_PASSWORD=111111
echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD"
fi
MYSQL_DATABASE=${MYSQL_DATABASE}
MYSQL_USER=${MYSQL_USER}
MYSQL_PASSWORD=${MYSQL_PASSWORD}
if [ ! -d "/run/mysqld" ]; then
mkdir -p /run/mysqld
fi
tfile=`mktemp`
if [ ! -f "$tfile" ]; then
return 1
fi
cat << EOF > $tfile
USE mysql;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "$MYSQL_ROOT_PASSWORD" WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
DROP USER ''@'${HOSTNAME}';
DROP USER 'root'@'${HOSTNAME}';
DROP USER 'root'@'localhost';
DROP USER 'root'@'127.0.0.1';
DROP USER 'root'@'::1';
DROP USER ''@'localhost';
UPDATE user SET password=PASSWORD("${MYSQL_ROOT_PASSWORD}") WHERE user='root' AND host='%';
EOF
if [ "$MYSQL_DATABASE" != "" ]; then
echo "[i] Creating database: $MYSQL_DATABASE"
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile
if [ "$MYSQL_USER" != "" ]; then
echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD"
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
fi
fi
/usr/bin/mysqld --user=root --bootstrap --verbose=0 < $tfile
rm -f $tfile
fi
envsubst < config.template.yaml > config.yaml
mysqld --user=root &
while :
do
node index.js
sleep 2
done

View file

@ -28,7 +28,7 @@ function checkAdmin(cb) {
*/
function handleAcp(req, res, user) {
var sio;
if (req.secure || req.header("x-forwarded-proto") === "https") {
if ( Config.get("https.enabled") && (req.secure || req.header("x-forwarded-proto") === "https") ) {
sio = Config.get("https.domain") + ":" + Config.get("https.default-port");
} else {
sio = Config.get("io.domain") + ":" + Config.get("io.default-port");