From 2fe11eb707ccffce484ed91f5931a0e32152b6ee Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 17 May 2018 17:45:48 -0700 Subject: [PATCH 1/9] move github files to .github folder, delete useless server config, get development Docker build working --- CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md | 0 contributing.md => .github/CONTRIBUTING.md | 0 ISSUE_TEMPLATE.md => .github/ISSUE_TEMPLATE.md | 0 .../PULL_REQUEST_TEMPLATE.md | 0 Dockerfile | 2 +- index.js | 11 ++++++----- server/config.js | 6 ------ server/server.js | 8 +++----- 8 files changed, 10 insertions(+), 17 deletions(-) rename CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md (100%) rename contributing.md => .github/CONTRIBUTING.md (100%) rename ISSUE_TEMPLATE.md => .github/ISSUE_TEMPLATE.md (100%) rename PULL_REQUEST_TEMPLATE.md => .github/PULL_REQUEST_TEMPLATE.md (100%) delete mode 100644 server/config.js diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT.md rename to .github/CODE_OF_CONDUCT.md diff --git a/contributing.md b/.github/CONTRIBUTING.md similarity index 100% rename from contributing.md rename to .github/CONTRIBUTING.md diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/Dockerfile b/Dockerfile index 6d75fe0c..a1330f5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:8.9.0 +FROM node:8.11.1 ENV APP_HOME=/opt/node/app \ TERM=xterm diff --git a/index.js b/index.js index e8b25418..f99dabf7 100644 --- a/index.js +++ b/index.js @@ -17,10 +17,11 @@ if (process.env.NODE_ENV === 'production') { }); require('babel-polyfill'); //// in development, let .env values override those in the environment already (i.e. in docker-compose.yml) - if (process.env.NODE_ENV === 'development') { - for (let key in parsed) { - process.env[key] = parsed[key]; - } - } + // so commenting this out makes the docker container work. + // if (process.env.NODE_ENV === 'development') { + // for (let key in parsed) { + // process.env[key] = parsed[key]; + // } + // } require('./server/server'); } diff --git a/server/config.js b/server/config.js deleted file mode 100644 index cf7fb8e8..00000000 --- a/server/config.js +++ /dev/null @@ -1,6 +0,0 @@ -const config = { - mongoURL: process.env.MONGO_URL || 'mongodb://localhost:27017/p5js-web-editor', - port: process.env.PORT || 8000, -}; - -export default config; diff --git a/server/server.js b/server/server.js index d186ff4e..efb915b7 100644 --- a/server/server.js +++ b/server/server.js @@ -15,7 +15,6 @@ import webpackHotMiddleware from 'webpack-hot-middleware'; import config from '../webpack.config.dev'; // Import all required modules -import serverConfig from './config'; import users from './routes/user.routes'; import sessions from './routes/session.routes'; import projects from './routes/project.routes'; @@ -106,8 +105,7 @@ require('./config/passport'); // const passportConfig = require('./config/passport'); // Connect to MongoDB -// mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI); -mongoose.connect(serverConfig.mongoURL); +mongoose.connect(process.env.MONGO_URL); mongoose.connection.on('error', () => { console.error('MongoDB Connection Error. Please make sure that MongoDB is running.'); process.exit(1); @@ -132,9 +130,9 @@ app.get('*', (req, res) => { }); // start app -app.listen(serverConfig.port, (error) => { +app.listen(process.env.PORT, (error) => { if (!error) { - console.log(`p5js web editor is running on port: ${serverConfig.port}!`); // eslint-disable-line + console.log(`p5js web editor is running on port: ${process.env.PORT}!`); // eslint-disable-line } }); From 752b804c55bcba44f1ba6407e180775d74b4705c Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 17 May 2018 18:01:03 -0700 Subject: [PATCH 2/9] remove unused index.html, move example fetch to own folder --- index.html | 17 ----------------- package.json | 4 ++-- server/{ => scripts}/examples-gg-latest.js | 4 ++-- server/{ => scripts}/examples.js | 4 ++-- .../scripts/fetch-examples-gg.js | 2 +- .../scripts/fetch-examples.js | 2 +- 6 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 index.html rename server/{ => scripts}/examples-gg-latest.js (99%) rename server/{ => scripts}/examples.js (99%) rename fetch-examples-gg.js => server/scripts/fetch-examples-gg.js (65%) rename fetch-examples.js => server/scripts/fetch-examples.js (71%) diff --git a/index.html b/index.html deleted file mode 100644 index 10a68414..00000000 --- a/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - p5.js Web Editor - - - - -
-
- - - - diff --git a/package.json b/package.json index bc53a3a2..a0b8bc59 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 fetch-examples.js", - "fetch-examples-gg": "node fetch-examples-gg.js" + "fetch-examples": "node server/scripts/fetch-examples.js", + "fetch-examples-gg": "node server/scripts/fetch-examples-gg.js" }, "main": "index.js", "author": "Cassie Tarakajian", diff --git a/server/examples-gg-latest.js b/server/scripts/examples-gg-latest.js similarity index 99% rename from server/examples-gg-latest.js rename to server/scripts/examples-gg-latest.js index f2fa5ff2..513e87ff 100644 --- a/server/examples-gg-latest.js +++ b/server/scripts/examples-gg-latest.js @@ -5,8 +5,8 @@ import objectID from 'bson-objectid'; import shortid from 'shortid'; import eachSeries from 'async/eachSeries'; -import User from './models/user'; -import Project from './models/project'; +import User from '../models/user'; +import Project from '../models/project'; // TODO: change to true when testing! const testMake = false; diff --git a/server/examples.js b/server/scripts/examples.js similarity index 99% rename from server/examples.js rename to server/scripts/examples.js index 305b623e..3d0cefb4 100644 --- a/server/examples.js +++ b/server/scripts/examples.js @@ -4,8 +4,8 @@ import mongoose from 'mongoose'; import objectID from 'bson-objectid'; import shortid from 'shortid'; import eachSeries from 'async/eachSeries'; -import User from './models/user'; -import Project from './models/project'; +import User from '../models/user'; +import Project from '../models/project'; const defaultHTML = ` diff --git a/fetch-examples-gg.js b/server/scripts/fetch-examples-gg.js similarity index 65% rename from fetch-examples-gg.js rename to server/scripts/fetch-examples-gg.js index fc354c2c..73fcc26b 100644 --- a/fetch-examples-gg.js +++ b/server/scripts/fetch-examples-gg.js @@ -1,4 +1,4 @@ require('babel-register'); require('babel-polyfill'); require('dotenv').config(); -require('./server/examples-gg-latest.js'); +require('./examples-gg-latest.js'); diff --git a/fetch-examples.js b/server/scripts/fetch-examples.js similarity index 71% rename from fetch-examples.js rename to server/scripts/fetch-examples.js index aecc226a..c46eeb54 100644 --- a/fetch-examples.js +++ b/server/scripts/fetch-examples.js @@ -1,4 +1,4 @@ require('babel-register'); require('babel-polyfill'); require('dotenv').config(); -require('./server/examples.js'); +require('./examples.js'); From 073e307f3397f8a207ab8a0e5c4d560e1bb39418 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 17 May 2018 18:43:06 -0700 Subject: [PATCH 3/9] start production docker configuration --- Dockerfile => Dockerfile-development | 0 README.md | 10 +++++----- docker-compose-development.yml | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 6 +++++- nginx/Dockerfile | 3 +++ nginx.conf => nginx/nginx.conf | 0 6 files changed, 41 insertions(+), 6 deletions(-) rename Dockerfile => Dockerfile-development (100%) create mode 100644 docker-compose-development.yml create mode 100644 nginx/Dockerfile rename nginx.conf => nginx/nginx.conf (100%) diff --git a/Dockerfile b/Dockerfile-development similarity index 100% rename from Dockerfile rename to Dockerfile-development diff --git a/README.md b/README.md index 2b97b9ca..7e7cf286 100644 --- a/README.md +++ b/README.md @@ -54,21 +54,21 @@ Note that this takes up a significant amount of space on your machine. Make sure * Mac: https://www.docker.com/docker-mac * Windows: https://www.docker.com/docker-windows 2. Clone this repository and cd into it -3. `$ docker-compose build` -4. `$ docker-compose run --rm server npm run fetch-examples` +3. `$ docker-compose -f docker-compose-development.yml build` +4. `$ docker-compose -f docker-compose-development.yml run --rm server npm run fetch-examples` Now, anytime you wish to start the server with its dependencies, you can run: -5. `$ docker-compose up` +5. `$ docker-compose -f docker-compose-development.yml up` 6. Navigate to [http://localhost:8000](http://localhost:8000) in your browser To open a terminal/shell in the running Docker server (i.e. after `docker-compose up` has been run): -7. `$ docker-compose exec server bash -l` +7. `$ docker-compose -f docker-compose-development.yml exec server bash -l` If you don't have the full server environment running, you can launch a one-off container instance (and have it automatically deleted after you're done using it): -8. `$ docker-compose run server --rm bash -l` +8. `$ docker-compose -f docker-compose-development.yml run server --rm bash -l` ## Production Installation 1. Clone this repository and `cd` into it diff --git a/docker-compose-development.yml b/docker-compose-development.yml new file mode 100644 index 00000000..9b97dd33 --- /dev/null +++ b/docker-compose-development.yml @@ -0,0 +1,28 @@ +version: '2' +services: + mongo: + image: mongo:3.4.7 + server: + build: + context: . + dockerfile: Dockerfile-development + command: npm start + 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 + ports: + - '8000:8000' + depends_on: + - mongo diff --git a/docker-compose.yml b/docker-compose.yml index 7f6c97bf..c324527d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,12 @@ version: '2' services: mongo: image: mongo:3.4.7 + nginx: + build: ./nginx server: - build: . + build: + context: . + dockerfile: Dockerfile-development command: npm start environment: - API_URL=/api diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 00000000..4c45e83b --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.13.12 + +COPY nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/nginx.conf b/nginx/nginx.conf similarity index 100% rename from nginx.conf rename to nginx/nginx.conf From edadfd5c68450e6b8337b63d996fc29683509111 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 4 Jun 2018 15:34:40 -0700 Subject: [PATCH 4/9] more changes to get dockerization working --- docker-compose-development.yml | 2 +- docker-compose.yml | 4 +- ecosystem.json | 2 +- nginx/Dockerfile | 4 +- nginx/alpha.editor.p5js.org.conf | 61 ++++++++++++++++ nginx/nginx-aws.conf | 122 +++++++++++++++++++++++++++++++ nginx/nginx.conf | 61 ---------------- 7 files changed, 191 insertions(+), 65 deletions(-) create mode 100644 nginx/alpha.editor.p5js.org.conf create mode 100644 nginx/nginx-aws.conf diff --git a/docker-compose-development.yml b/docker-compose-development.yml index 9b97dd33..33d98f76 100644 --- a/docker-compose-development.yml +++ b/docker-compose-development.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' services: mongo: image: mongo:3.4.7 diff --git a/docker-compose.yml b/docker-compose.yml index c324527d..a5d58f68 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ -version: '2' +version: '3' services: mongo: image: mongo:3.4.7 + expose: + - "27017" nginx: build: ./nginx server: diff --git a/ecosystem.json b/ecosystem.json index 5f56d91f..edcd6311 100644 --- a/ecosystem.json +++ b/ecosystem.json @@ -4,6 +4,6 @@ "env": { "NODE_ENV": "production" }, - "instances" : 2, + "instances" : "max", "exec_mode" : "cluster" } \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 4c45e83b..9372b789 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,3 +1,5 @@ FROM nginx:1.13.12 -COPY nginx.conf /etc/nginx/nginx.conf \ No newline at end of file +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/nginx/alpha.editor.p5js.org.conf b/nginx/alpha.editor.p5js.org.conf new file mode 100644 index 00000000..ec704743 --- /dev/null +++ b/nginx/alpha.editor.p5js.org.conf @@ -0,0 +1,61 @@ + # HTTP - redirect all requests to HTTPS: + server { + listen 80; + server_name alpha.editor.p5js.org; + location / { + proxy_pass http://127.0.0.1:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + location ~* \/login(\/)* { + return 301 https://$host$request_uri; + } + location ~* \/signup(\/)* { + return 301 https://$host$request_uri; + } + location ~* \/reset-password(\/)* { + return 301 https://$host$request_uri; + } + location ~* "\/[a-zA-Z0-9._-]{1,20}\/account(\/)*" { + return 301 https://$host$request_uri; + } + +} + +server { + listen 443; + ssl on; + ssl_certificate /etc/letsencrypt/live/alpha.editor.p5js.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/alpha.editor.p5js.org/privkey.pem; + server_name alpha.editor.p5js.org; + location / { + proxy_pass http://127.0.0.1:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} + +server { + listen 80; + server_name editor.p5js.org; + location ~ ^/(.*) { + return 302 http://alpha.editor.p5js.org/$1; + } +} + +server { + listen 443; + ssl on; + ssl_certificate /etc/letsencrypt/live/editor.p5js.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/editor.p5js.org/privkey.pem; + server_name editor.p5js.org; + location ~ ^/(.*) { + return 302 https://alpha.editor.p5js.org/$1; + } +} \ No newline at end of file diff --git a/nginx/nginx-aws.conf b/nginx/nginx-aws.conf new file mode 100644 index 00000000..b0ab9feb --- /dev/null +++ b/nginx/nginx-aws.conf @@ -0,0 +1,122 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + include /etc/nginx/sites-enabled/*.conf; + + index index.html index.htm; + + server { + listen 80 default_server; + listen [::]:80 default_server; + server_name localhost; + root /usr/share/nginx/html; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + location / { + } + + # redirect server error pages to the static page /40x.html + # + error_page 404 /404.html; + location = /40x.html { + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl; +# listen [::]:443 ssl; +# server_name localhost; +# root /usr/share/nginx/html; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# # It is *strongly* recommended to generate unique DH parameters +# # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 +# #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /etc/nginx/default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + +} \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index ec704743..e69de29b 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,61 +0,0 @@ - # HTTP - redirect all requests to HTTPS: - server { - listen 80; - server_name alpha.editor.p5js.org; - location / { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - location ~* \/login(\/)* { - return 301 https://$host$request_uri; - } - location ~* \/signup(\/)* { - return 301 https://$host$request_uri; - } - location ~* \/reset-password(\/)* { - return 301 https://$host$request_uri; - } - location ~* "\/[a-zA-Z0-9._-]{1,20}\/account(\/)*" { - return 301 https://$host$request_uri; - } - -} - -server { - listen 443; - ssl on; - ssl_certificate /etc/letsencrypt/live/alpha.editor.p5js.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/alpha.editor.p5js.org/privkey.pem; - server_name alpha.editor.p5js.org; - location / { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } -} - -server { - listen 80; - server_name editor.p5js.org; - location ~ ^/(.*) { - return 302 http://alpha.editor.p5js.org/$1; - } -} - -server { - listen 443; - ssl on; - ssl_certificate /etc/letsencrypt/live/editor.p5js.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/editor.p5js.org/privkey.pem; - server_name editor.p5js.org; - location ~ ^/(.*) { - return 302 https://alpha.editor.p5js.org/$1; - } -} \ No newline at end of file From ece6c8e450274f6e120fce3f549c26ff5c68f52d Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 7 Jun 2018 13:09:51 -0700 Subject: [PATCH 5/9] update .env.example and README, start to build out Docker development and prodiction setup --- .env.example | 13 +++- Dockerfile | 31 ++++++++ README.md | 75 +++++-------------- docker-compose-development.yml | 16 ++-- docker-compose.yml | 10 ++- nginx/alpha.editor.p5js.org.conf | 50 ++++++------- nginx/nginx.conf | 122 +++++++++++++++++++++++++++++++ 7 files changed, 222 insertions(+), 95 deletions(-) create mode 100644 Dockerfile diff --git a/.env.example b/.env.example index 794704dc..f5db441f 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,14 @@ GITHUB_ID= GITHUB_SECRET= GOOGLE_ID= (use google+ api) GOOGLE_SECRET= (use google+ api) +MAILGUN_DOMAIN= MAILGUN_KEY= -EXAMPLE_USERNAME= -EXAMPLE_USER_EMAIL= -EXAMPLE_USER_PASSWORD= \ No newline at end of file +EMAIL_SENDER= +EMAIL_VERIFY_SECRET_TOKEN=whatever_you_want_this_to_be_it_only_matters_for_production +S3_BUCKET_URL_BASE= +EXAMPLE_USERNAME=p5 +EXAMPLE_USER_EMAIL=examples@p5js.org +EXAMPLE_USER_PASSWORD=hellop5js +GG_EXAMPLES_USERNAME=generative-design +GG_EXAMPLES_PASS=generativedesign +GG_EXAMPLES_EMAIL=benedikt.gross@generative-gestaltung.de \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..788b9be1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:8.11.1 as base +ENV APP_HOME=/usr/src/app \ + TERM=xterm +RUN mkdir -p $APP_HOME +WORKDIR $APP_HOME +EXPOSE 8000 + +FROM base as development +ENV NODE_ENV development +COPY package.json package-lock.json ./ +RUN npm install +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 +CMD ["npm", "start"] + +FROM development as build +ENV NODE_ENV production +RUN npm run build + +FROM base as production +ENV NODE_ENV=production +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 --from=build /usr/src/app/dist ./dist +CMD ["pm2-runtime", "ecosystem.json"] diff --git a/README.md b/README.md index 7e7cf286..8cab8c79 100644 --- a/README.md +++ b/README.md @@ -10,33 +10,12 @@ This project is currently in development! It will be announced when there is a ( 4. Install MongoDB and make sure it is running * For Mac OSX with [homebrew](http://brew.sh/): `brew install mongodb` then `brew services start mongodb` * For Windows and Linux: [MongoDB Installation](https://docs.mongodb.com/manual/installation/) -5. Create a file called `.env` in the root of this directory that looks like - - ``` - API_URL=/api - MONGO_URL=mongodb://localhost:27017/p5js-web-editor - PORT=8000 - SESSION_SECRET=whatever_you_want_this_to_be_it_only_matters_for_production - AWS_ACCESS_KEY= - AWS_SECRET_KEY= - AWS_REGION= - S3_BUCKET= - GITHUB_ID= - GITHUB_SECRET= - GOOGLE_ID= (use google+ api) - GOOGLE_SECRET= (use google+ api) - MAILGUN_KEY= - EXAMPLE_USERNAME= - EXAMPLE_USER_EMAIL= - EXAMPLE_USER_PASSWORD= - ``` - - If you don't care about being able to upload media files to S3 or Login with Github or Google, you can drop in the file exactly how it is. Or, if you don't want to do that, just ask me to send you mine. Refer to [this gist](https://gist.github.com/catarak/70c9301f0fd1ac2d6b58de03f61997e3) for creating an S3 bucket for testing, or if you don't want to do that, I can add you to one of my S3 buckets. - -6. `$ npm run fetch-examples` - this downloads the example sketches into a user called 'p5' -7. `$ npm start` -8. Navigate to [http://localhost:8000](http://localhost:8000) in your browser -9. Install the [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en). +5. `$ cp .env.example .env` +6. (Optional) Update `.env` with necessary keys to enable certain app behavoirs, i.e. add Github ID and Github Secret if you want to be able to log in with Github. +7. `$ npm run fetch-examples` - this downloads the example sketches into a user called 'p5' +8. `$ npm start` +9. Navigate to [http://localhost:8000](http://localhost:8000) in your browser +10. Install the [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en). 10. Open and close the Redux DevTools using `ctrl+h`, and move them with `ctrl+w` ### Testing SSL on your local machine @@ -74,52 +53,32 @@ If you don't have the full server environment running, you can launch a one-off 1. Clone this repository and `cd` into it 2. `$ npm install` 3. Install MongoDB and make sure it is running -4. Create a file called `.env` in the root of this directory that looks like - - ``` - API_URL=/api - MONGO_URL=mongodb://localhost:27017/p5js-web-editor - PORT=8000 - SESSION_SECRET=make_this_a_long-random_string_like_maybe_126_characters_long - AWS_ACCESS_KEY= - AWS_SECRET_KEY= - AWS_REGION= - S3_BUCKET= - GITHUB_ID= - GITHUB_SECRET= - GOOGLE_ID= (use google+ api) - GOOGLE_SECRET= (use google+ api) - EMAIL_SENDER= - MAILGUN_KEY= - MAILGUN_DOMAIN= - EMAIL_VERIFY_SECRET_TOKEN=whatever_you_want_this_to_be_it_only_matters_for_production - EXAMPLE_USERNAME= - EXAMPLE_USER_EMAIL= - EXAMPLE_USER_PASSWORD= - ``` - For production, you will need to have real Github and Amazon credentials. Refer to [this gist](https://gist.github.com/catarak/70c9301f0fd1ac2d6b58de03f61997e3) for creating an S3 bucket for testing. - -5. `$ npm run fetch-examples` - this downloads the example sketches into a user called 'p5' -6. `$ npm run build` -7. `$ npm run start:prod` +4. `$ cp .env.example .env` +5. (NOT Optional) edit `.env` and fill in all necessart values. +6. `$ npm run fetch-examples` - this downloads the example sketches into a user called 'p5' +7. `$ npm run build` +8. `$ npm run start:prod` ### For Production Setup with PM2 1. `$ npm install -g pm2` 2. `$ pm2 start ecosystem.json` -## Optional S3 bucket URL base configuration +## S3 Bucket Configuration + +Please refer to the folllowing [gist](https://gist.github.com/catarak/70c9301f0fd1ac2d6b58de03f61997e3) to set up an S3 bucket to be used with this project. + If your S3 bucket is in the US East (N Virginia) region (us-east-1), you'll need to set a custom URL base for it, because it does not follow the standard naming pattern as the rest of the regions. Instead, add the following to your environment/.env file: -```S3_BUCKET_URL_BASE=https://s3.amazonaws.com``` +`S3_BUCKET_URL_BASE=https://s3.amazonaws.com` If you've configured your S3 bucket and DNS records to use a custom domain name, you can also set it using this variable. I.e.: -```S3_BUCKET_URL_BASE=https://files.mydomain.com``` +`S3_BUCKET_URL_BASE=https://files.mydomain.com` For more information on using a custom domain, see this documentation link: diff --git a/docker-compose-development.yml b/docker-compose-development.yml index 33d98f76..c0fbfdb6 100644 --- a/docker-compose-development.yml +++ b/docker-compose-development.yml @@ -1,12 +1,14 @@ -version: '3' +version: '3.4' services: mongo: image: mongo:3.4.7 + volumes: + - dbdata:/data/db server: build: - context: . - dockerfile: Dockerfile-development - command: npm start + context: ./ + dockerfile: Dockerfile + target: development environment: - API_URL=/api - MONGO_URL=mongodb://mongo:27017/p5js-web-editor @@ -20,9 +22,11 @@ services: - GITHUB_SECRET=override_in_dotenv - MAILGUN_KEY=override_in_dotenv volumes: - - .:/opt/node/app - - /opt/node/app/node_modules + - .:/usr/src/app + - /usr/src/app/node_modules ports: - '8000:8000' depends_on: - mongo +volumes: + dbdata: diff --git a/docker-compose.yml b/docker-compose.yml index a5d58f68..306c0694 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ -version: '3' +version: '3.4' services: mongo: image: mongo:3.4.7 + volumes: + - dbdata:/data/db expose: - "27017" nginx: @@ -9,8 +11,8 @@ services: server: build: context: . - dockerfile: Dockerfile-development - command: npm start + dockerfile: Dockerfile + target: production environment: - API_URL=/api - MONGO_URL=mongodb://mongo:27017/p5js-web-editor @@ -30,3 +32,5 @@ services: - '8000:8000' depends_on: - mongo +volumes: + dbdata: diff --git a/nginx/alpha.editor.p5js.org.conf b/nginx/alpha.editor.p5js.org.conf index ec704743..f89e51bd 100644 --- a/nginx/alpha.editor.p5js.org.conf +++ b/nginx/alpha.editor.p5js.org.conf @@ -25,21 +25,21 @@ } -server { - listen 443; - ssl on; - ssl_certificate /etc/letsencrypt/live/alpha.editor.p5js.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/alpha.editor.p5js.org/privkey.pem; - server_name alpha.editor.p5js.org; - location / { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } -} +# server { +# listen 443; +# ssl on; +# ssl_certificate /etc/letsencrypt/live/alpha.editor.p5js.org/fullchain.pem; +# ssl_certificate_key /etc/letsencrypt/live/alpha.editor.p5js.org/privkey.pem; +# server_name alpha.editor.p5js.org; +# location / { +# proxy_pass http://127.0.0.1:8000; +# proxy_http_version 1.1; +# proxy_set_header Upgrade $http_upgrade; +# proxy_set_header Connection 'upgrade'; +# proxy_set_header Host $host; +# proxy_cache_bypass $http_upgrade; +# } +# } server { listen 80; @@ -49,13 +49,13 @@ server { } } -server { - listen 443; - ssl on; - ssl_certificate /etc/letsencrypt/live/editor.p5js.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/editor.p5js.org/privkey.pem; - server_name editor.p5js.org; - location ~ ^/(.*) { - return 302 https://alpha.editor.p5js.org/$1; - } -} \ No newline at end of file +# server { +# listen 443; +# ssl on; +# ssl_certificate /etc/letsencrypt/live/editor.p5js.org/fullchain.pem; +# ssl_certificate_key /etc/letsencrypt/live/editor.p5js.org/privkey.pem; +# server_name editor.p5js.org; +# location ~ ^/(.*) { +# return 302 https://alpha.editor.p5js.org/$1; +# } +# } \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index e69de29b..b0ab9feb 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -0,0 +1,122 @@ +# For more information on configuration, see: +# * Official English Documentation: http://nginx.org/en/docs/ +# * Official Russian Documentation: http://nginx.org/ru/docs/ + +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + include /etc/nginx/sites-enabled/*.conf; + + index index.html index.htm; + + server { + listen 80 default_server; + listen [::]:80 default_server; + server_name localhost; + root /usr/share/nginx/html; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + location / { + } + + # redirect server error pages to the static page /40x.html + # + error_page 404 /404.html; + location = /40x.html { + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + +# Settings for a TLS enabled server. +# +# server { +# listen 443 ssl; +# listen [::]:443 ssl; +# server_name localhost; +# root /usr/share/nginx/html; +# +# ssl_certificate "/etc/pki/nginx/server.crt"; +# ssl_certificate_key "/etc/pki/nginx/private/server.key"; +# # It is *strongly* recommended to generate unique DH parameters +# # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048 +# #ssl_dhparam "/etc/pki/nginx/dhparams.pem"; +# ssl_session_cache shared:SSL:1m; +# ssl_session_timeout 10m; +# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP; +# ssl_prefer_server_ciphers on; +# +# # Load configuration files for the default server block. +# include /etc/nginx/default.d/*.conf; +# +# location / { +# } +# +# error_page 404 /404.html; +# location = /40x.html { +# } +# +# error_page 500 502 503 504 /50x.html; +# location = /50x.html { +# } +# } + +} \ No newline at end of file From 28c91b7d05615e9f32c675698a7600b6874ca65d Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 7 Jun 2018 14:49:17 -0700 Subject: [PATCH 6/9] start to handle environment variables --- Dockerfile | 4 ++-- index.js | 8 +++++++- nginx/Dockerfile | 2 +- webpack.config.prod.js | 6 +++++- 4 files changed, 15 insertions(+), 5 deletions(-) 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', From 93e4052101c150eb320d038279aee4eca2d19463 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 8 Jun 2018 10:41:33 -0700 Subject: [PATCH 7/9] 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 = { From 6ecfe6448573e8153f8f443d40fb17dc05c555b3 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 13 Jun 2018 17:40:46 -0700 Subject: [PATCH 8/9] fix fetch example scripts, add webpack config to build fetch script bundles --- scripts/backup.sh => backup.sh | 0 package.json | 4 +- .../scripts}/examples-gg-latest.js | 0 {scripts => server/scripts}/examples.js | 0 .../scripts}/fetch-examples-gg.js | 0 {scripts => server/scripts}/fetch-examples.js | 0 webpack.config.examples.js | 93 +++++++++++++++++++ 7 files changed, 95 insertions(+), 2 deletions(-) rename scripts/backup.sh => backup.sh (100%) rename {scripts => server/scripts}/examples-gg-latest.js (100%) rename {scripts => server/scripts}/examples.js (100%) rename {scripts => server/scripts}/fetch-examples-gg.js (100%) rename {scripts => server/scripts}/fetch-examples.js (100%) create mode 100644 webpack.config.examples.js diff --git a/scripts/backup.sh b/backup.sh similarity index 100% rename from scripts/backup.sh rename to backup.sh diff --git a/package.json b/package.json index e76f9646..6edafcd9 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 scripts/fetch-examples.js", - "fetch-examples-gg": "node scripts/fetch-examples-gg.js" + "fetch-examples": "node ./server/scripts/fetch-examples.js", + "fetch-examples-gg": "node ./server/scripts/fetch-examples-gg.js" }, "main": "index.js", "author": "Cassie Tarakajian", diff --git a/scripts/examples-gg-latest.js b/server/scripts/examples-gg-latest.js similarity index 100% rename from scripts/examples-gg-latest.js rename to server/scripts/examples-gg-latest.js diff --git a/scripts/examples.js b/server/scripts/examples.js similarity index 100% rename from scripts/examples.js rename to server/scripts/examples.js diff --git a/scripts/fetch-examples-gg.js b/server/scripts/fetch-examples-gg.js similarity index 100% rename from scripts/fetch-examples-gg.js rename to server/scripts/fetch-examples-gg.js diff --git a/scripts/fetch-examples.js b/server/scripts/fetch-examples.js similarity index 100% rename from scripts/fetch-examples.js rename to server/scripts/fetch-examples.js diff --git a/webpack.config.examples.js b/webpack.config.examples.js new file mode 100644 index 00000000..a2e08e7e --- /dev/null +++ b/webpack.config.examples.js @@ -0,0 +1,93 @@ +const path = require('path'); +const nodeExternals = require('webpack-node-externals'); + +module.exports = [{ + entry: path.resolve(__dirname, 'server/scripts/fetch-examples.js'), + + output: { + path: __dirname + '/dist/', + filename: 'fetch-examples.bundle.js' + }, + + target: 'node', + + externals: [nodeExternals()], + + resolve: { + extensions: ['*', '.js', '.jsx'], + modules: [ + 'client', + 'node_modules', + ], + }, + + module: { + loaders: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { + presets: [ + 'react', + 'env', + 'stage-0', + ], + plugins: [ + [ + 'babel-plugin-webpack-loaders', { + 'config': './webpack.config.babel.js', + "verbose": false + } + ] + ] + }, + } + ], + }, +}, +{ + entry: path.resolve(__dirname, 'server/scripts/fetch-examples-gg.js'), + + output: { + path: __dirname + '/dist/', + filename: 'fetch-examples-gg.bundle.js' + }, + + target: 'node', + + externals: [nodeExternals()], + + resolve: { + extensions: ['*', '.js', '.jsx'], + modules: [ + 'client', + 'node_modules', + ], + }, + + module: { + loaders: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { + presets: [ + 'react', + 'env', + 'stage-0', + ], + plugins: [ + [ + 'babel-plugin-webpack-loaders', { + 'config': './webpack.config.babel.js', + "verbose": false + } + ] + ] + }, + } + ], + }, +}]; \ No newline at end of file From d8e129780341f7e52deecca062cf7e9f3d870933 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 15 Jun 2018 13:51:42 -0700 Subject: [PATCH 9/9] get local-ssl-proxy working for testing prod locally --- Dockerfile | 13 +++++++------ docker-compose.yml | 8 ++++++-- package.json | 8 ++++++-- server/scripts/fetch-examples-gg.js | 2 +- server/scripts/fetch-examples.js | 2 +- webpack.config.dev.js | 4 +++- webpack.config.prod.js | 2 +- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index b47c384f..05076099 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,21 +4,21 @@ ENV APP_HOME=/usr/src/app \ RUN mkdir -p $APP_HOME WORKDIR $APP_HOME EXPOSE 8000 +EXPOSE 80 +EXPOSE 443 FROM base as development ENV NODE_ENV development COPY package.json package-lock.json ./ RUN npm install 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 webpack.config.examples.js ./ COPY client ./client COPY server ./server -COPY scripts ./scripts CMD ["npm", "start"] FROM development as build ENV NODE_ENV production -# COPY .env ./ RUN npm run build FROM base as production @@ -27,8 +27,9 @@ 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 .babelrc ./ -COPY scripts ./scripts -# COPY .env ./ +RUN npm install local-ssl-proxy +COPY index.js ecosystem.json ./ COPY --from=build /usr/src/app/dist ./dist +RUN npm run ssl-proxy +#RUN npm run fetch-examples:prod CMD ["pm2-runtime", "ecosystem.json"] diff --git a/docker-compose.yml b/docker-compose.yml index f7c2a490..87d5fd93 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,8 @@ services: - dbdata:/data/db expose: - "27017" - nginx: - build: ./nginx + # nginx: + # build: ./nginx server: build: context: . @@ -17,11 +17,15 @@ services: - .env environment: - MONGO_URL=mongodb://mongo:27017/p5js-web-editor + - API_URL=https://localhost/api + - PORT=80 volumes: - .:/opt/node/app - /opt/node/app/node_modules ports: - '8000:8000' + - '80:80' + - '443:443' depends_on: - mongo volumes: diff --git a/package.json b/package.json index 6edafcd9..09d90d7c 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,16 @@ "start:prod": "cross-env NODE_ENV=production node index.js", "lint": "eslint client server --ext .jsx --ext .js", "lint-fix": "eslint client server --ext .jsx --ext .js --fix", - "build": "npm run build:client && npm run build:server", + "build": "npm run build:client && npm run build:server && npm run build:examples", "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:examples": "cross-env NODE_ENV=production webpack --config webpack.config.examples.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-gg": "node ./server/scripts/fetch-examples-gg.js", + "fetch-examples:prod": "node ./dist/fetch-examples.bundle.js", + "fetch-examples-gg:prod": "node ./dist/fetch-examples.bundle.js", + "ssl-proxy": "local-ssl-proxy --source 443 --target 80 &" }, "main": "index.js", "author": "Cassie Tarakajian", diff --git a/server/scripts/fetch-examples-gg.js b/server/scripts/fetch-examples-gg.js index 647618d9..51867785 100644 --- a/server/scripts/fetch-examples-gg.js +++ b/server/scripts/fetch-examples-gg.js @@ -1,6 +1,6 @@ require('babel-register'); require('babel-polyfill'); -if (process.env.NODE_ENV !== "production") { +if (process.env.NODE_ENV === "development") { require('dotenv').config(); } require('./examples-gg-latest.js'); diff --git a/server/scripts/fetch-examples.js b/server/scripts/fetch-examples.js index d4037179..e287b076 100644 --- a/server/scripts/fetch-examples.js +++ b/server/scripts/fetch-examples.js @@ -1,6 +1,6 @@ require('babel-register'); require('babel-polyfill'); -if (process.env.NODE_ENV !== "production") { +if (process.env.NODE_ENV === "development") { require('dotenv').config(); } require('./examples.js'); diff --git a/webpack.config.dev.js b/webpack.config.dev.js index 9b453932..81d542ba 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -1,5 +1,7 @@ const webpack = require('webpack'); -require('dotenv').config(); +if (process.env.NODE_ENV === 'development') { + require('dotenv').config(); +} module.exports = { devtool: 'cheap-module-eval-source-map', diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 7170b9c0..2f02835e 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -6,7 +6,7 @@ const cssnext = require('postcss-cssnext'); const postcssFocus = require('postcss-focus'); const postcssReporter = require('postcss-reporter'); const cssnano = require('cssnano'); -if (process.env.NODE_ENV !== "production") { +if (process.env.NODE_ENV === "development") { require('dotenv').config(); }