diff --git a/Dockerfile b/Dockerfile index 6a28af5e..f1951b46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,16 @@ FROM node:4-onbuild +ARG DOMAIN=runfullstack.co + +COPY ./config /usr/src/app +ENV NODE_ENV production + +RUN sed -i -e "s/config\/sslcerts\/key.pem/\/etc\/letsencrypt\/live\/$DOMAIN\/privkey.pem/g" /usr/src/app/config/production.json && \ + sed -i -e "s/config\/sslcerts\/cert.pem/\/etc\/letsencrypt\/live\/$DOMAIN\/cert.pem/g" /usr/src/app/config/production.json + +RUN apt-get update -yq && \ + apt-get install -yq supervisor && \ + mkdir -p /var/log/supervisor + +COPY ./supervisord.conf /etc/supervisor/conf.d/signalmaster.conf + +CMD ["/usr/bin/supervisord"] diff --git a/README.md b/README.md index a24031dc..fb279209 100644 --- a/README.md +++ b/README.md @@ -58,3 +58,13 @@ To run the image execute this: docker run --name signalmaster -d -p 8888:8888 signalmaster This will start a signal master server on port 8888 exposed on port 8888. + +## Differences + +This version allows you to set the host for listening. + + docker build -t signalmaster . + +Run the image: + + docker run -d -p 8080:8080 -e PORT=8080 -e HOST=0.0.0.0 -e NODE_ENV=production auser/signalmaster diff --git a/config/development.json b/config/development.json index 0c79b8e3..bb510330 100644 --- a/config/development.json +++ b/config/development.json @@ -2,6 +2,7 @@ "isDev": true, "server": { "port": 8888, + "host": "0.0.0.0", "/* secure */": "/* whether this connects via https */", "secure": false, "key": null, diff --git a/config/production.json b/config/production.json index 69c9e4be..aafcb74a 100644 --- a/config/production.json +++ b/config/production.json @@ -2,6 +2,7 @@ "isDev": false, "server": { "port": 8888, + "host": "0.0.0.0", "/* secure */": "/* whether this connects via https */", "secure": true, "key": "config/sslcerts/key.pem", diff --git a/server.js b/server.js index 0b6eae53..c31284fd 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,8 @@ var yetify = require('yetify'), fs = require('fs'), sockets = require('./sockets'), port = parseInt(process.env.PORT || config.server.port, 10), + host = process.env.HOST || config.server.host, + le_domain = process.env.DOMAIN || false, server_handler = function (req, res) { res.writeHead(404); res.end(); @@ -12,6 +14,18 @@ var yetify = require('yetify'), // Create an http(s) server instance to that socket.io can listen to if (config.server.secure) { + var fileExists = function (fp) { + try { fs.accessSync(fp); return true } catch (err) { return false; } + } + if (le_domain) { + var le_path = "/etc/letsencrypt/live/" + le_domain + "/"; + if (fileExists(le_path + "privkey.pem")) { + config.server.key = le_path + "privkey.pem" + } + if (fileExists((le_path + "cert.pem"))) { + config.server.cert = le_path + "cert.pem" + } + } server = require('https').Server({ key: fs.readFileSync(config.server.key), cert: fs.readFileSync(config.server.cert), @@ -28,8 +42,8 @@ if (config.uid) process.setuid(config.uid); var httpUrl; if (config.server.secure) { - httpUrl = "https://localhost:" + port; + httpUrl = "https://" + host + ":" + port; } else { - httpUrl = "http://localhost:" + port; + httpUrl = "http://" + host + ":" + port; } console.log(yetify.logo() + ' -- signal master is running at: ' + httpUrl); diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 00000000..c99d4bd8 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,11 @@ +[supervisord] +nodaemon=true + +[program:signalmaster] +command = /usr/local/bin/node /usr/src/app/server.js +directory = /usr/src/app +autostart = true +autorestart = true +stdout_logfile = /var/log/supervisor/signalmaster.log +stderr_logfile = /var/log/supervisor/signalmaster_err.log +environment = NODE_ENV="production"