diff --git a/Dockerfile b/Dockerfile index c587345..d97e437 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,21 @@ FROM node:11 + ENV NODE_ENV production WORKDIR /usr/src/app + COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"] RUN npm install --production --silent && mv node_modules ../ + COPY . . + EXPOSE 3000 -CMD npm start \ No newline at end of file + +RUN mkdir -p /data/db +ENV DB_URL /data/db + +RUN mkdir -p /data/sessions +ENV SESSION_STORE /data/sessions + +ENV SECRET_DIRNAME /data + +CMD npm start diff --git a/config/index.js b/config/index.js index 95be6a3..25c0cce 100644 --- a/config/index.js +++ b/config/index.js @@ -8,6 +8,7 @@ module.exports = { port: Number(process.env.PORT) || 3000, proxyServer: process.env.PROXY_SERVER || undefined, secret: process.env.SECRET || require('./secret'), + sessionStore: process.env.SESSION_STORE || './sessions', sessionMaxAge: Number(process.env.SESSION_MAX_AGE) || 1000 * 60 * 60 * 24 * 7, siteTitle: process.env.SITE_TITLE || 'Christmas Community', useCDN: yesNo.parse(process.env.USE_CDN || true), diff --git a/config/secret/index.js b/config/secret/index.js index dabdf94..ba422a2 100644 --- a/config/secret/index.js +++ b/config/secret/index.js @@ -2,7 +2,7 @@ const uuid = require('uuid/v4'); const path = require('path'); const fs = require('fs'); -const secretFilePath = path.join(__dirname, 'secret.txt'); +const secretFilePath = path.join((process.env.SECRET_DIRNAME ? process.env.SECRET_DIRNAME : __dirname), 'secret.txt'); try { module.exports = fs.readFileSync(secretFilePath).toString(); diff --git a/index.js b/index.js index 228e8aa..a280287 100644 --- a/index.js +++ b/index.js @@ -44,7 +44,7 @@ passport.deserializeUser((user, callback) => { const LevelStore = expressSessionLevel(session); -const sessionDb = level('./sessions') +const sessionDb = level(config.sessionStore) app.use(require('body-parser').urlencoded({ extended: true })); app.use(session({