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 28c91b7d05
commit 93e4052101
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 .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 client ./client
COPY server ./server COPY server ./server
COPY scripts ./scripts
CMD ["npm", "start"] CMD ["npm", "start"]
FROM development as build FROM development as build
ENV NODE_ENV production ENV NODE_ENV production
COPY .env ./ # COPY .env ./
RUN npm run build RUN npm run build
FROM base as production FROM base as production
@ -26,6 +27,8 @@ 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 ecosystem.json .env ./ COPY index.js ecosystem.json .babelrc ./
COPY scripts ./scripts
# COPY .env ./
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

@ -10,17 +10,7 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
target: development target: development
environment: environment:
- API_URL=/api
- MONGO_URL=mongodb://mongo:27017/p5js-web-editor - 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: volumes:
- .:/usr/src/app - .:/usr/src/app
- /usr/src/app/node_modules - /usr/src/app/node_modules

View file

@ -13,18 +13,10 @@ services:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
target: production target: production
env_file:
- .env
environment: environment:
- API_URL=/api
- MONGO_URL=mongodb://mongo:27017/p5js-web-editor - 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: volumes:
- .:/opt/node/app - .:/opt/node/app
- /opt/node/app/node_modules - /opt/node/app/node_modules

View file

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

View file

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

View file

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

View file

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

View file

@ -6,10 +6,8 @@ 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');
try { if (process.env.NODE_ENV !== "production") {
require('dotenv').config(); require('dotenv').config();
} catch (error) {
console.log('.env file does not exist. Assuming environment variables are pre-loaded.');
} }
module.exports = { module.exports = {