From 131e853503678cd3aa18546ac79d3522df8ded31 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jun 2018 10:41:33 -0700 Subject: [PATCH] change Dockerfile to fix environment variables and fetching examples --- Dockerfile | 7 +++++-- docker-compose-development.yml | 10 ---------- docker-compose.yml | 12 ++---------- index.js | 6 ------ package.json | 4 ++-- backup.sh => scripts/backup.sh | 0 {server/scripts => scripts}/examples-gg-latest.js | 0 {server/scripts => scripts}/examples.js | 0 {server/scripts => scripts}/fetch-examples-gg.js | 4 +++- {server/scripts => scripts}/fetch-examples.js | 4 +++- webpack.config.prod.js | 4 +--- 11 files changed, 16 insertions(+), 35 deletions(-) rename backup.sh => scripts/backup.sh (100%) rename {server/scripts => scripts}/examples-gg-latest.js (100%) rename {server/scripts => scripts}/examples.js (100%) rename {server/scripts => scripts}/fetch-examples-gg.js (53%) rename {server/scripts => scripts}/fetch-examples.js (50%) diff --git a/Dockerfile b/Dockerfile index 82c31e64..b47c384f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose-development.yml b/docker-compose-development.yml index c0fbfdb6..e07f2ebf 100644 --- a/docker-compose-development.yml +++ b/docker-compose-development.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 306c0694..f7c2a490 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/index.js b/index.js index 289a8997..b65d1733 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/package.json b/package.json index a0b8bc59..e76f9646 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/backup.sh b/scripts/backup.sh similarity index 100% rename from backup.sh rename to scripts/backup.sh diff --git a/server/scripts/examples-gg-latest.js b/scripts/examples-gg-latest.js similarity index 100% rename from server/scripts/examples-gg-latest.js rename to scripts/examples-gg-latest.js diff --git a/server/scripts/examples.js b/scripts/examples.js similarity index 100% rename from server/scripts/examples.js rename to scripts/examples.js diff --git a/server/scripts/fetch-examples-gg.js b/scripts/fetch-examples-gg.js similarity index 53% rename from server/scripts/fetch-examples-gg.js rename to scripts/fetch-examples-gg.js index 73fcc26b..647618d9 100644 --- a/server/scripts/fetch-examples-gg.js +++ b/scripts/fetch-examples-gg.js @@ -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'); diff --git a/server/scripts/fetch-examples.js b/scripts/fetch-examples.js similarity index 50% rename from server/scripts/fetch-examples.js rename to scripts/fetch-examples.js index c46eeb54..d4037179 100644 --- a/server/scripts/fetch-examples.js +++ b/scripts/fetch-examples.js @@ -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'); diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 64bae5ff..7170b9c0 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -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 = {