start to handle environment variables

This commit is contained in:
Cassie Tarakajian 2018-06-07 14:49:17 -07:00
parent 0857a52326
commit 6dd92a1573
4 changed files with 15 additions and 5 deletions

View file

@ -17,6 +17,7 @@ CMD ["npm", "start"]
FROM development as build FROM development as build
ENV NODE_ENV production ENV NODE_ENV production
COPY .env ./
RUN npm run build RUN npm run build
FROM base as production FROM base as production
@ -25,7 +26,6 @@ COPY package.json package-lock.json ./
RUN npm install --production RUN npm install --production
RUN npm rebuild node-sass RUN npm rebuild node-sass
RUN npm install pm2 -g RUN npm install pm2 -g
COPY index.js ./ COPY index.js ecosystem.json .env ./
COPY ecosystem.json ./
COPY --from=build /usr/src/app/dist ./dist COPY --from=build /usr/src/app/dist ./dist
CMD ["pm2-runtime", "ecosystem.json"] CMD ["pm2-runtime", "ecosystem.json"]

View file

@ -1,9 +1,15 @@
let parsed = require('dotenv').config(); // let parsed = require('dotenv').config();
if (process.env.NODE_ENV === 'production') { 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.webpackAssets = JSON.stringify(require('./dist/static/manifest.json'));
process.env.webpackChunkAssets = JSON.stringify(require('./dist/static/chunk-manifest.json')); process.env.webpackChunkAssets = JSON.stringify(require('./dist/static/chunk-manifest.json'));
require('./dist/server.bundle.js'); require('./dist/server.bundle.js');
} else { } else {
let parsed = require('dotenv').config();
require('babel-register')({ require('babel-register')({
"plugins": [ "plugins": [
[ [

View file

@ -1,5 +1,5 @@
FROM nginx:1.13.12 FROM nginx:1.13.12
RUN mkdir -p /etc/nginx/sites-enabled
COPY nginx.conf /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir /etc/nginx/sites-enabled
COPY alpha.editor.p5js.org.conf /etc/nginx/sites-enabled COPY alpha.editor.p5js.org.conf /etc/nginx/sites-enabled

View file

@ -6,7 +6,11 @@ const cssnext = require('postcss-cssnext');
const postcssFocus = require('postcss-focus'); const postcssFocus = require('postcss-focus');
const postcssReporter = require('postcss-reporter'); const postcssReporter = require('postcss-reporter');
const cssnano = require('cssnano'); 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 = { module.exports = {
devtool: 'source-map', devtool: 'source-map',