Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
EXPOSE 80 443
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 14 additions & 7 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
}));
Expand Down Expand Up @@ -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(){
Expand Down
62 changes: 27 additions & 35 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();
Expand Down
21 changes: 0 additions & 21 deletions lib/credentials.default.json

This file was deleted.