diff --git a/Dockerfile b/Dockerfile index 788b9be1..82c31e64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ CMD ["npm", "start"] FROM development as build ENV NODE_ENV production +COPY .env ./ RUN npm run build FROM base as production @@ -25,7 +26,6 @@ COPY package.json package-lock.json ./ RUN npm install --production RUN npm rebuild node-sass RUN npm install pm2 -g -COPY index.js ./ -COPY ecosystem.json ./ +COPY index.js ecosystem.json .env ./ COPY --from=build /usr/src/app/dist ./dist CMD ["pm2-runtime", "ecosystem.json"] diff --git a/index.js b/index.js index f99dabf7..289a8997 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,15 @@ -let parsed = require('dotenv').config(); +// let parsed = require('dotenv').config(); if (process.env.NODE_ENV === 'production') { + try { + require('dotenv').config(); + } catch(error) { + console.log('.env file does not exist. Assuming environment variables are pre-loaded.'); + } process.env.webpackAssets = JSON.stringify(require('./dist/static/manifest.json')); process.env.webpackChunkAssets = JSON.stringify(require('./dist/static/chunk-manifest.json')); require('./dist/server.bundle.js'); } else { + let parsed = require('dotenv').config(); require('babel-register')({ "plugins": [ [ diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 9372b789..49d6b29a 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,5 +1,5 @@ FROM nginx:1.13.12 +RUN mkdir -p /etc/nginx/sites-enabled COPY nginx.conf /etc/nginx/nginx.conf -RUN mkdir /etc/nginx/sites-enabled COPY alpha.editor.p5js.org.conf /etc/nginx/sites-enabled \ No newline at end of file diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 1a59fd96..64bae5ff 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -6,7 +6,11 @@ const cssnext = require('postcss-cssnext'); const postcssFocus = require('postcss-focus'); const postcssReporter = require('postcss-reporter'); const cssnano = require('cssnano'); -require('dotenv').config(); +try { + require('dotenv').config(); +} catch (error) { + console.log('.env file does not exist. Assuming environment variables are pre-loaded.'); +} module.exports = { devtool: 'source-map',