change Dockerfile to fix environment variables and fetching examples

This commit is contained in:
Cassie Tarakajian 2018-06-08 10:41:33 -07:00
parent 6dd92a1573
commit 131e853503
11 changed files with 16 additions and 35 deletions

View File

@ -13,11 +13,12 @@ RUN npm rebuild node-sass
COPY .babelrc index.js nodemon.json webpack.config.babel.js webpack.config.dev.js webpack.config.prod.js webpack.config.server.js ./
COPY client ./client
COPY server ./server
COPY scripts ./scripts
CMD ["npm", "start"]
FROM development as build
ENV NODE_ENV production
COPY .env ./
# COPY .env ./
RUN npm run build
FROM base as production
@ -26,6 +27,8 @@ COPY package.json package-lock.json ./
RUN npm install --production
RUN npm rebuild node-sass
RUN npm install pm2 -g
COPY index.js ecosystem.json .env ./
COPY index.js ecosystem.json .babelrc ./
COPY scripts ./scripts
# COPY .env ./
COPY --from=build /usr/src/app/dist ./dist
CMD ["pm2-runtime", "ecosystem.json"]

View File

@ -10,17 +10,7 @@ services:
dockerfile: Dockerfile
target: development
environment:
- API_URL=/api
- MONGO_URL=mongodb://mongo:27017/p5js-web-editor
- PORT=8000
- SESSION_SECRET=override_in_dotenv
- AWS_ACCESS_KEY=override_in_dotenv
- AWS_SECRET_KEY=override_in_dotenv
- AWS_REGION=override_in_dotenv
- S3_BUCKET=override_in_dotenv
- GITHUB_ID=override_in_dotenv
- GITHUB_SECRET=override_in_dotenv
- MAILGUN_KEY=override_in_dotenv
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules

View File

@ -13,18 +13,10 @@ services:
context: .
dockerfile: Dockerfile
target: production
env_file:
- .env
environment:
- API_URL=/api
- MONGO_URL=mongodb://mongo:27017/p5js-web-editor
- PORT=8000
- SESSION_SECRET=override_in_dotenv
- AWS_ACCESS_KEY=override_in_dotenv
- AWS_SECRET_KEY=override_in_dotenv
- AWS_REGION=override_in_dotenv
- S3_BUCKET=override_in_dotenv
- GITHUB_ID=override_in_dotenv
- GITHUB_SECRET=override_in_dotenv
- MAILGUN_KEY=override_in_dotenv
volumes:
- .:/opt/node/app
- /opt/node/app/node_modules

View File

@ -1,10 +1,4 @@
// 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');

View File

@ -12,8 +12,8 @@
"build:client": "cross-env NODE_ENV=production webpack --config webpack.config.prod.js --progress",
"build:server": "cross-env NODE_ENV=production webpack --config webpack.config.server.js --progress",
"test": "npm run lint",
"fetch-examples": "node server/scripts/fetch-examples.js",
"fetch-examples-gg": "node server/scripts/fetch-examples-gg.js"
"fetch-examples": "node scripts/fetch-examples.js",
"fetch-examples-gg": "node scripts/fetch-examples-gg.js"
},
"main": "index.js",
"author": "Cassie Tarakajian",

View File

@ -1,4 +1,6 @@
require('babel-register');
require('babel-polyfill');
require('dotenv').config();
if (process.env.NODE_ENV !== "production") {
require('dotenv').config();
}
require('./examples-gg-latest.js');

View File

@ -1,4 +1,6 @@
require('babel-register');
require('babel-polyfill');
require('dotenv').config();
if (process.env.NODE_ENV !== "production") {
require('dotenv').config();
}
require('./examples.js');

View File

@ -6,10 +6,8 @@ const cssnext = require('postcss-cssnext');
const postcssFocus = require('postcss-focus');
const postcssReporter = require('postcss-reporter');
const cssnano = require('cssnano');
try {
if (process.env.NODE_ENV !== "production") {
require('dotenv').config();
} catch (error) {
console.log('.env file does not exist. Assuming environment variables are pre-loaded.');
}
module.exports = {