diff --git a/Dockerfile b/Dockerfile index 86856438b..8a17e531b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,39 @@ FROM iojs:onbuild -ENV NODE_ENV production +# node settings +ENV NODE_ENV=production +# starts on port 443 if truthy, else 80 +ENV USE_SSL= +# admin user +ENV ADMIN_EMAIL=admin@semaphore.local +ENV ADMIN_USERNAME=semaphore +ENV ADMIN_REALNAME=Administrator +ENV ADMIN_PASSWORD=CastawayLabs + +# mongodb +ENV MONGODB_URL mongodb://127.0.0.1/semaphore + +# redis config +ENV REDIS_HOST=127.0.0.1 +ENV REDIS_PORT=6379 +ENV REDIS_KEY= + +# smtp config +ENV SMTP_USER= +ENV SMTP_PASS= + +# external services +ENV BUGSNAG_KEY= +ENV USE_ANALYTICS= + +# add and install ADD . /srv/semaphore WORKDIR /srv/semaphore -RUN rm -f node_modules/ - +RUN npm install -g bower RUN npm install +RUN bower install --allow-root CMD ["node", "/srv/semaphore/bin/semaphore"] -EXPOSE 80 \ No newline at end of file +EXPOSE 80 443 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..e56cd3798 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +--- + +redis: + image: redis + ports: + - 6379:6379 + +mongo: + image: mongo + ports: + - 27017:27017 + +semaphore: + image: semaphore + links: + - mongo + - redis + environment: + - MONGODB_URL=mongodb://mongo/semaphore + - REDIS_HOST=redis + ports: + - 80:80 diff --git a/lib/app.js b/lib/app.js index 1a0307779..398710943 100644 --- a/lib/app.js +++ b/lib/app.js @@ -27,10 +27,13 @@ console.log = logtrail.log.bind(logtrail); var releaseStage = config.production ? "production" : "development"; -bugsnag.register(config.credentials.bugsnag_key, { - notifyReleaseStages: ["production"], - releaseStage: releaseStage -}); +if(config.credentials.bugsnag_key) { + bugsnag.register(config.credentials.bugsnag_key, { + notifyReleaseStages: ["production"], + releaseStage: releaseStage + }); +} + mongoose.connect(config.credentials.db, config.credentials.db_options); @@ -70,7 +73,10 @@ app.use(require('less-middleware')(publicFolder)); app.use(require('serve-static')(publicFolder)); app.use(require('morgan')(config.production ? 'combined' : 'dev')); -app.use(bugsnag.requestHandler); +if(config.credentials.bugsnag_key) { + app.use(bugsnag.requestHandler); +} + app.use(bodyParser.urlencoded({ extended: true })); @@ -102,8 +108,9 @@ app.use(function(req, res, next) { // routes routes.router(app); - -app.use(bugsnag.errorHandler); +if(config.credentials.bugsnag_key) { + app.use(bugsnag.errorHandler); +} var server = http.createServer(app) server.listen(app.get('port'), function(){ diff --git a/lib/config.js b/lib/config.js index 8374da2fd..82e2a9209 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,39 +1,30 @@ var fs = require('fs'), env = process.env; -try { - var credentials = require('./credentials.json'); -} catch (e) { - if (!(process.env.MONGODB_URL && process.env.REDIS_HOST)) { - console.log("\nNo credentials.json File or env variables!\n"); - process.exit(1); - } else { - credentials = require('./credentials.default.json'); - } -} - -exports.credentials = credentials; - -['redis_port', 'redis_host', 'redis_key', 'bugsnag_key', 'port'].forEach(function (key) { - if (env[key.toUpperCase()]) { - exports.credentials[key] = env[key.toUpperCase()]; +exports.credentials = { + "redis_port": env.REDIS_PORT, + "redis_host": env.REDIS_HOST, + "redis_key": env.REDIS_KEY, + "use_analytics": env.USE_ANALYTICS, + "bugsnag_key": env.BUGSNAG_KEY, + "smtp": { + "user": env.SMTP_USER, + "pass": env.SMTP_PASS + }, + "db": env.MONGODB_URL, + "db_options": { + "auto_reconnect": true, + "native_parser": true, + "server": { + "auto_reconnect": true + } } -}); - -if (env.SMTP_USER) { - exports.credentials.smtp.user = env.SMTP_USER; -} -if (env.SMTP_PASS) { - exports.credentials.smtp.pass = env.SMTP_PASS; -} -if (env.MONGODB_URL) { - exports.credentials.db = env.MONGODB_URL; -} +}; exports.version = require('../package.json').version; exports.hash = 'dirty'; exports.production = process.env.NODE_ENV == "production"; -exports.port = process.env.PORT || credentials.port; +exports.port = env.USE_SSL ? 443 : 80; exports.path = __dirname; if (process.platform.match(/^win/) == null) { @@ -54,24 +45,25 @@ exports.configure = function (app) { app.locals.version = exports.version; app.locals.versionHash = exports.hash; app.locals.production = exports.production; - app.locals.use_analytics = credentials.use_analytics; + app.locals.use_analytics = exports.credentials.use_analytics; } exports.init = function () { var models = require('./models'); models.User.findOne({ - email: 'admin@semaphore.local' + email: env.ADMIN_EMAIL }).exec(function (err, admin) { if (!admin) { - console.log("Creating Admin user admin@semaphore.local!"); + console.log("Creating Admin user " + env.ADMIN_EMAIL + "!"); admin = new models.User({ - email: 'admin@semaphore.local', - username: 'semaphore', - name: 'Administrator' + email: env.ADMIN_EMAIL, + username: env.ADMIN_USERNAME, + name: env.ADMIN_REALNAME }); - models.User.hashPassword('CastawayLabs', function (hash) { + + models.User.hashPassword(env.ADMIN_PASSWORD, function (hash) { admin.password = hash; admin.save(); diff --git a/lib/credentials.default.json b/lib/credentials.default.json deleted file mode 100644 index aa2848275..000000000 --- a/lib/credentials.default.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "redis_port": 6379, - "redis_host": "127.0.0.1", - "redis_key": "", - "use_analytics": false, - "is_ssl": false, - "bugsnag_key": "", - "smtp": { - "user": "", - "pass": "" - }, - "db": "mongodb://127.0.0.1/semaphore", - "db_options": { - "auto_reconnect": true, - "native_parser": true, - "server": { - "auto_reconnect": true - } - }, - "port": 80 -} \ No newline at end of file