Skip to content

Commit 19a1053

Browse files
committed
chore(database): universal database config
1 parent 44ffe8b commit 19a1053

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:10.10-alpine
2+
3+
RUN mkdir -p /usr/src/trudesk
4+
WORKDIR /usr/src/trudesk
5+
6+
COPY . /usr/src/trudesk
7+
8+
RUN apk add --no-cache --update bash make gcc g++ python mongodb-tools
9+
10+
RUN npm install -g yarn && \
11+
yarn install --production=false --prefer-offline && \
12+
npm rebuild bcrypt node-sass --build-from-source && \
13+
yarn run build && \
14+
yarn install --production --prefer-offline && \
15+
apk del make gcc g++ python
16+
17+
EXPOSE 8118
18+
19+
CMD [ "/bin/bash", "/usr/src/trudesk/startup.sh" ]

public/img/defaultProfile.jpg

7.63 KB
Loading

src/database/index.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,37 @@
1313
*/
1414

1515
var _ = require('lodash')
16-
var mongoose = require('mongoose')
1716
var nconf = require('nconf')
17+
var mongoose = require('mongoose')
1818
var winston = require('winston')
1919

2020
var db = {}
21+
var mongoConnectionUri = {
22+
server: process.env.MONGODB_SERVER || nconf.get('mongo:host'),
23+
port: process.env.MONGODB_PORT || nconf.get('mongo:port') || '27017',
24+
username: process.env.MONGODB_USERNAME || nconf.get('mongo:username'),
25+
password: process.env.MONGODB_PASSWORD || nconf.get('mongo:password'),
26+
database: process.env.MONGODB_DATABASE ? 'trudesk_' + process.env.MONGODB_DATABASE : nconf.get('mongo:database')
27+
}
2128

22-
var dbPassword = encodeURIComponent(nconf.get('mongo:password'))
23-
24-
var CONNECTION_URI =
25-
'mongodb://' +
26-
nconf.get('mongo:username') +
27-
':' +
28-
dbPassword +
29-
'@' +
30-
nconf.get('mongo:host') +
31-
':' +
32-
nconf.get('mongo:port') +
33-
'/' +
34-
nconf.get('mongo:database')
29+
var CONNECTION_URI = ''
30+
if (!mongoConnectionUri.username)
31+
CONNECTION_URI =
32+
'mongodb://' + mongoConnectionUri.server + ':' + mongoConnectionUri.port + '/' + mongoConnectionUri.database
33+
else {
34+
mongoConnectionUri.password = encodeURIComponent(mongoConnectionUri.password)
35+
CONNECTION_URI =
36+
'mongodb://' +
37+
mongoConnectionUri.username +
38+
':' +
39+
mongoConnectionUri.password +
40+
'@' +
41+
mongoConnectionUri.server +
42+
':' +
43+
mongoConnectionUri.port +
44+
'/' +
45+
mongoConnectionUri.database
46+
}
3547

3648
var options = {
3749
keepAlive: 1,
@@ -43,7 +55,6 @@ var options = {
4355
module.exports.init = function (callback, connectionString, opts) {
4456
if (connectionString) CONNECTION_URI = connectionString
4557
if (opts) options = opts
46-
if (!_.isUndefined(process.env.MONGOHQ_URL)) CONNECTION_URI = process.env.MONGOHQ_URL.trim()
4758

4859
if (db.connection) {
4960
return callback(null, db)

startup.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
if [ ! -d /usr/src/trudesk/public/uploads/users ]; then
4+
echo "Creating Directory..."
5+
mkdir /usr/src/trudesk/public/uploads/users
6+
fi
7+
8+
if [ ! -f /usr/src/trudesk/public/uploads/users/defaultProfile.jpg ]; then
9+
echo "Coping defaultProfile.jpg"
10+
cp /usr/src/trudesk/public/img/defaultProfile.jpg /usr/src/trudesk/public/uploads/users/defaultProfile.jpg
11+
fi
12+
13+
node /usr/src/trudesk/runner.js

0 commit comments

Comments
 (0)