Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
467c27c
removing expose fro Dockerfile
May 4, 2016
ec54504
change order of commands in Dockerfile
May 4, 2016
bc46ff6
updating less module in package.json
May 9, 2016
2bf04b0
Update README.md
bmeiri Jun 21, 2016
387d856
Update README.md
bmeiri Jun 21, 2016
f4bea46
adding docker-compose
Aug 13, 2016
c6c36e6
adding codefresh.yml
Sep 20, 2016
465d19d
change node version
Sep 20, 2016
bc67b6a
change node version
Sep 20, 2016
7752270
change node version
Sep 20, 2016
8afaf3e
Update defaults.yml
advance512-demo Oct 5, 2016
df77655
Update defaults.yml
advance512-demo Oct 5, 2016
21478af
Create settings.yml
advance512-demo Oct 5, 2016
7d28cee
Added multiple connection tries
advance512-demo Oct 6, 2016
f7f585c
Update app.js
advance512-demo Oct 6, 2016
cabb8c9
Updating app.js
advance512-demo Oct 6, 2016
53cfaa4
Calling tryConnect()..
advance512-demo Oct 6, 2016
fa7b383
Deleting settings.yml
advance512-demo Oct 6, 2016
56bc5a0
Merge pull request #1 from advance512-demo/master
Superfresh Oct 9, 2016
93fce75
modify yaml
verchol Nov 14, 2016
8dadac2
new yaml
verchol Nov 14, 2016
2d4414d
new yaml
verchol Nov 14, 2016
774673c
new yaml
verchol Nov 14, 2016
4b5687c
remove npm from yaml
verchol Nov 14, 2016
6c677b7
remove npm from yaml
verchol Nov 14, 2016
184429a
run with composition
verchol Nov 14, 2016
23bf354
run with composition
verchol Nov 14, 2016
53c9369
add CD
verchol Nov 14, 2016
96063f7
add staging
verchol Nov 14, 2016
e3a5413
fix codefreshCD
verchol Nov 14, 2016
7700972
add push
verchol Nov 14, 2016
06f96b8
add push
verchol Nov 14, 2016
b49118d
add push
verchol Nov 14, 2016
a35bd2d
fix yaml
verchol Nov 14, 2016
e283c88
fix
verchol Nov 14, 2016
6eec5a3
hotfix
verchol Nov 14, 2016
febacce
Merge branch 'devtlv' into staging
verchol Nov 14, 2016
07f46c3
yaml file
verchol Nov 14, 2016
dbfecd0
add staff
verchol Nov 14, 2016
5416a94
add staff
verchol Nov 14, 2016
eafbac1
add hotfix
verchol Nov 14, 2016
c17e68c
add hotfix
verchol Nov 14, 2016
6363c11
add hotfix
verchol Nov 14, 2016
277d97f
add hotfix1
verchol Nov 14, 2016
cd85546
add hotfix2
verchol Nov 14, 2016
08c742b
add hotfix4
verchol Nov 14, 2016
8d0e394
add hotfix5
verchol Nov 14, 2016
ebc04a7
add codefreshdev
verchol Nov 14, 2016
75948cc
change the title
verchol Nov 14, 2016
24e148c
add production filter to ecs
verchol Nov 14, 2016
fa75451
add integration tests
verchol Nov 14, 2016
84f6587
add integration tests
verchol Nov 14, 2016
94a8fa4
Update codefresh.yml
Superfresh Nov 15, 2016
06297cf
update yaml
Superfresh Nov 15, 2016
6e778e8
my new feature
Nov 15, 2016
f55212f
remove integrations
Superfresh Nov 15, 2016
9ccc19b
Merge branch 'master' of github.com:containers101/demochat into devcon
Nov 15, 2016
9f45699
update
Superfresh Nov 15, 2016
521b19e
Merge branch 'master' of github.com:containers101/demochat
Nov 15, 2016
65285e2
back to default
Nov 15, 2016
9c8a45b
my feature
Nov 15, 2016
e6063f3
fix titles
Superfresh Nov 23, 2016
b203274
Change the header
Superfresh Nov 23, 2016
97e0798
title
Superfresh Nov 23, 2016
a23eb61
remove underscore
Superfresh Nov 23, 2016
6b5edce
Change the title
Superfresh Nov 23, 2016
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
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
FROM node:0.10-slim

RUN npm install -g mocha
RUN npm install -g istanbul
RUN npm install -g gulp

COPY ./package.json /src/package.json
RUN cd /src && npm install
COPY ./ /src
RUN npm install -g mocha
RUN npm install -g istanbul
RUN npm install -g gulp

WORKDIR /src
#ENV DEBUG=*

EXPOSE 8080 5222

CMD ["npm", "start"]
12 changes: 12 additions & 0 deletions Dockerfile_prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:0.10-slim

COPY ./package.json /src/package.json
RUN cd /src && npm install
COPY ./ /src

WORKDIR /src
#ENV DEBUG=*


CMD ["npm", "start"]

3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
![Let's Chat Greylock](http://i.imgur.com/0a3l5VF.png)
#test1
#test2
![Screenshot](http://i.imgur.com/C4uMD67.png)
Test Test
A self-hosted chat app for small teams or big Gal by [Security Compass][seccom].

[![Build Status](https://travis-ci.org/sdelements/lets-chat.svg?branch=master)](https://travis-ci.org/sdelements/lets-chat)
Expand Down
167 changes: 94 additions & 73 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ process.title = 'letschat';

require('colors');

var _ = require('lodash'),
path = require('path'),
fs = require('fs'),
express = require('express.oi'),
i18n = require('i18n'),
bodyParser = require('body-parser'),
var _ = require('lodash'),
path = require('path'),
fs = require('fs'),
express = require('express.oi'),
i18n = require('i18n'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
compression = require('compression'),
helmet = require('helmet'),
http = require('http'),
nunjucks = require('nunjucks'),
mongoose = require('mongoose'),
migroose = require('./migroose'),
compression = require('compression'),
helmet = require('helmet'),
http = require('http'),
nunjucks = require('nunjucks'),
mongoose = require('mongoose'),
migroose = require('./migroose'),
connectMongo = require('connect-mongo'),
all = require('require-tree'),
psjon = require('./package.json'),
settings = require('./app/config'),
auth = require('./app/auth/index'),
core = require('./app/core/index');

var MongoStore = connectMongo(express.session),
httpEnabled = settings.http && settings.http.enable,
all = require('require-tree'),
psjon = require('./package.json'),
settings = require('./app/config'),
auth = require('./app/auth/index'),
core = require('./app/core/index');

var MongoStore = connectMongo(express.session),
httpEnabled = settings.http && settings.http.enable,
httpsEnabled = settings.https && settings.https.enable,
models = all(path.resolve('./app/models')),
middlewares = all(path.resolve('./app/middlewares')),
controllers = all(path.resolve('./app/controllers')),
models = all(path.resolve('./app/models')),
middlewares = all(path.resolve('./app/middlewares')),
controllers = all(path.resolve('./app/controllers')),
app;

//
// express.oi Setup
//
if (httpsEnabled) {
app = express().https({
key: fs.readFileSync(settings.https.key),
app = express().https({
key: fs.readFileSync(settings.https.key),
cert: fs.readFileSync(settings.https.cert)
}).io();
} else {
Expand All @@ -56,17 +56,17 @@ if (settings.env === 'production') {

// Session
var sessionStore = new MongoStore({
url: settings.database.uri,
url: settings.database.uri,
autoReconnect: true
});

// Session
var session = {
key: 'connect.sid',
secret: settings.secrets.cookie,
store: sessionStore,
cookie: { secure: httpsEnabled },
resave: false,
key: 'connect.sid',
secret: settings.secrets.cookie,
store: sessionStore,
cookie: { secure: httpsEnabled },
resave: false,
saveUninitialized: true
};

Expand All @@ -85,32 +85,32 @@ app.use(helmet.ieNoOpen());
app.use(helmet.noSniff());
app.use(helmet.xssFilter());
app.use(helmet.hsts({
maxAge: 31536000,
maxAge: 31536000,
includeSubdomains: true,
force: httpsEnabled,
preload: true
force: httpsEnabled,
preload: true
}));
app.use(helmet.contentSecurityPolicy({
defaultSrc: ['\'none\''],
connectSrc: ['*'],
scriptSrc: ['\'self\'', '\'unsafe-eval\''],
styleSrc: ['\'self\'', 'fonts.googleapis.com', '\'unsafe-inline\''],
fontSrc: ['\'self\'', 'fonts.gstatic.com'],
mediaSrc: ['\'self\''],
objectSrc: ['\'self\''],
imgSrc: ['*']
scriptSrc: ['\'self\'', '\'unsafe-eval\''],
styleSrc: ['\'self\'', 'fonts.googleapis.com', '\'unsafe-inline\''],
fontSrc: ['\'self\'', 'fonts.gstatic.com'],
mediaSrc: ['\'self\''],
objectSrc: ['\'self\''],
imgSrc: ['*']
}));

var bundles = {};
app.use(require('connect-assets')({
paths: [
paths: [
'media/js',
'media/less'
],
helperContext: bundles,
build: settings.env === 'production',
helperContext: bundles,
build: settings.env === 'production',
fingerprinting: settings.env === 'production',
servePath: 'media/dist'
servePath: 'media/dist'
}));

// Public
Expand All @@ -121,24 +121,24 @@ app.use('/media', express.static(__dirname + '/media', {
// Templates
var nun = nunjucks.configure('templates', {
autoescape: true,
express: app,
tags: {
blockStart: '<%',
blockEnd: '%>',
express: app,
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
}
});

function wrapBundler(func) {
// This method ensures all assets paths start with "./"
// Making them relative, and not absolute
return function() {
return function () {
return func.apply(func, arguments)
.replace(/href="\//g, 'href="./')
.replace(/src="\//g, 'src="./');
.replace(/href="\//g, 'href="./')
.replace(/src="\//g, 'src="./');
};
}

Expand All @@ -148,7 +148,7 @@ nun.addGlobal('text_search', false);

// i18n
i18n.configure({
directory: __dirname + '/locales',
directory: __dirname + '/locales',
defaultLocale: settings.i18n && settings.i18n.locale || 'en'
});
app.use(i18n.init);
Expand All @@ -160,21 +160,21 @@ app.use(bodyParser.urlencoded({
}));

// IE header
app.use(function(req, res, next) {
app.use(function (req, res, next) {
res.setHeader('X-UA-Compatible', 'IE=Edge,chrome=1');
next();
});

//
// Controllers
//
_.each(controllers, function(controller) {
_.each(controllers, function (controller) {
controller.apply({
app: app,
core: core,
settings: settings,
app: app,
core: core,
settings: settings,
middlewares: middlewares,
models: models,
models: models,
controllers: controllers
});
});
Expand All @@ -187,7 +187,7 @@ mongoose.connection.on('error', function (err) {
throw new Error(err);
});

mongoose.connection.on('disconnected', function() {
mongoose.connection.on('disconnected', function () {
throw new Error('Could not connect to database');
});

Expand All @@ -197,17 +197,16 @@ mongoose.connection.on('disconnected', function() {

function startApp() {
var port = httpsEnabled && settings.https.port ||
httpEnabled && settings.http.port;
httpEnabled && settings.http.port;

var host = httpsEnabled && settings.https.host ||
httpEnabled && settings.http.host || '0.0.0.0';

httpEnabled && settings.http.host || '0.0.0.0';


if (httpsEnabled && httpEnabled) {
// Create an HTTP -> HTTPS redirect server
var redirectServer = express();
redirectServer.get('*', function(req, res) {
redirectServer.get('*', function (req, res) {
var urlPort = port === 80 ? '' : ':' + port;
res.redirect('https://' + req.hostname + urlPort + req.path);
});
Expand Down Expand Up @@ -247,31 +246,44 @@ function checkForMongoTextSearch() {
return;
}

if(version[0] < 2) {
if (version[0] < 2) {
return;
}

if(version[0] === '2' && version[1] < 6) {
if (version[0] === '2' && version[1] < 6) {
return;
}

nun.addGlobal('text_search', true);
});
}

mongoose.connect(settings.database.uri, function(err) {
var connectionTries = 0;

function handleMongoConnectionState(err) {

if (err) {
throw err;
connectionTries++;
if (connectionTries < 3) {
console.log('Error connecting to database (will retry in 2 seconds): ' + err.toString());
setTimeout(tryConnect, 2000);
return;
}
else {
throw err;
}
}

checkForMongoTextSearch();

migroose.needsMigration(function(err, migrationRequired) {
migroose.needsMigration(function (err, migrationRequired) {

if (err) {
console.error(err);
}

else if (migrationRequired) {

console.log('Database migration required'.red);
console.log('Ensure you backup your database first.');
console.log('');
Expand All @@ -281,7 +293,16 @@ mongoose.connect(settings.database.uri, function(err) {

return process.exit();
}


console.log('Starting app.');
startApp();
});
});

}

function tryConnect() {
console.log('Connecting to database...');
mongoose.connect(settings.database.uri, handleMongoConnectionState);
}

tryConnect();
48 changes: 48 additions & 0 deletions codefresh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '1.0'
steps:

build_step:
title: Build
type: build
dockerfile: Dockerfile
image_name: containers101/demochat
tag: ${{CF_BRANCH}}

unit_tests:
title: Unit Tests
image: ${{build_step}}
fail_fast: false
#working-directory : ${{initial-clone}}
commands:
#- npm install
#- npm install -g gulp
- npm test

push_to_registry:
title: Push To Registry
type: push
candidate: ${{build_step}}
tag: ${{CF_BRANCH}}

#demo-chat-integration:
# type: composition
# composition: letschat
# composition-candidates:
# main:
# image: nhoag/curl
# command: bash -c "sleep 20 && curl http://demochat:5000/" | echo 'works'

deploy_to_ecs:
title: Deploy Container to ECS
image: codefresh/cf-deploy-ecs
commands:
- cfecs-update --image-name containers101/demochat --image-tag ${{CF_BRANCH}} eu-west-1 demochat-production demochat-service
environment:
- AWS_ACCESS_KEY_ID=AKIAISRGV2FLUTSZJPVQ
#${{AWS_ACCESS_KEY_ID}}
- AWS_SECRET_ACCESS_KEY=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
#${{AWS_SECRET_ACCESS_KEY}}
when:
branch:
only:
- master
Loading