Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.2 proposal #52

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dec9f3d
pm2,doc: prefer starting the app with pm2 yml config
makemek Apr 23, 2017
488ffc3
pm2,bin,test: load all app's envs from process.yml
makemek Apr 23, 2017
45d4edf
doc: remarks when running in development mode
makemek Apr 24, 2017
73a1d0e
chore(package): update mocha to version 3.3.0
greenkeeper[bot] Apr 24, 2017
2968e9f
npm,doc: 'npm start' will launch app using pm2
makemek Apr 24, 2017
6238624
dep: dev package should be in devDependencies
makemek Apr 25, 2017
128cc22
src: replace sprintf-js with es6 string template
makemek Apr 25, 2017
0f6b58d
build: 'gulp build' and 'gulp import' as default task
makemek Apr 26, 2017
9295abe
src: remove injecting 'cklg' cookie
makemek Apr 26, 2017
bdaa2b7
src: js class implementation in cookie injector
makemek Apr 26, 2017
ec406c1
build: fix pm2-docker not found config file
makemek Apr 26, 2017
578194d
build: start process.yml using production environment
makemek Apr 26, 2017
fb865a1
chore(package): update coveralls to version 2.13.1
greenkeeper[bot] Apr 27, 2017
218987d
build: reduce docker image size
makemek Apr 26, 2017
821aae7
src: refactor code to be es6 complient
makemek Apr 28, 2017
109070c
chore(package): update nyc to version 10.3.0
greenkeeper[bot] Apr 29, 2017
afb3324
src: replace winston logger with pino logger
makemek Apr 29, 2017
9124d40
src: no need to log http request
makemek Apr 29, 2017
e52ca98
config: fix can't config LOGGER_ENABLE and LOGGER_PRETTY
makemek Apr 29, 2017
6fe859e
config: remove LOGGER_ENABLE option
makemek Apr 29, 2017
3c86274
config: use default pm2 log dir
makemek Apr 29, 2017
a14d24d
chore(package): update async to version 2.4.0
greenkeeper[bot] Apr 29, 2017
ebef457
fix(package): update pino to version 4.5.0
greenkeeper[bot] Apr 30, 2017
a24f793
doc: start the application in production mode
makemek Apr 30, 2017
a3df887
doc: update outdated configuration section
makemek Apr 30, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules/*
.git
.nyc_output
coverage
*.log
30 changes: 0 additions & 30 deletions .env.template.json

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Project gitignore
src/config/settings.json
.env.json

# Public assets gitignore
*.min.*
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
node_js:
- "6"
- "5"

before_install:
- travis_retry npm install
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ RUN adduser -S $USER && \
USER ${USER}
WORKDIR ${DEPLOY_DIR}
RUN npm install --only=production -g pm2 && \
npm install && \
npm run build
npm install --only=development && \
npm run build && \
rm -rf node_modules && \
npm install --only=production

EXPOSE ${PORT}

CMD pm2-docker start process.json --auto-exit
CMD pm2-docker start process.yml --env production --auto-exit
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,41 @@ Please follows steps below to run Modcolle
3. Copy `/deployment/nginx/nginx.conf` to `\path\to\nginx\conf`. Make sure to backup nginx.conf first before overwrite.
4. Inside nginx.conf replace `app1` and `DOMAIN_NAME` with `localhost`
5. Start nginx
6. Type `npm install pm2 -g` and run `pm2 start process.json`
6. Type `npm install pm2 -g` and run `npm start`
7. Open a browser and type `localhost` in the url

## Starting the Application

As a single instance
### Cluster Mode
This command runs [pm2](https://npmjs.org/packages/pm2) using configuration defined in `env` of [process.yml](https://github.com/makemek/Modcolle/blob/master/process.yml).
```
npm start
```

In cluster mode using [PM2](https://npmjs.org/packages/pm2)
You can also start the application in production mode by passing `--env production` to pm2.
```
pm2 start process.json
npm start -- --env production
```

In development mode with [nodemon](https://npmjs.org/packages/nodemon) and [browser-sync](https://npmjs.org/packages/browser-sync)
### Development Mode
With [nodemon](https://npmjs.org/packages/nodemon) and [browser-sync](https://npmjs.org/packages/browser-sync)
> **In this mode, no environment variables are loaded**.
You can still set them inside a command line if needed.
```
npm run dev

-----------
(optional) configure browser-sync using environment variables before running.
PORT=<port number> # browser-sync app's proxy port; default is 5000
PORT_DEV=<port number> # browser-sync listeing port; default is 3000
```

## Configuration
`.env.json` is the common configuration for Modcolle which will be created on first-time start or test by copying `.env.json.template` (no overwrite if file already exists).
At `env` section in `process.json` are environment variables that will override `.env.json` for running in production environment.
`process.yml` is PM2's [process file](http://pm2.keymetrics.io/docs/usage/application-declaration/) for Modcolle.
Inside `process.yml`, `env` contains common environment variables required by the application.
`env_production` used in production contains envrionment variables that overrides variables in `env`.

### Environment Variables
- LOGGER_SILENT: if `false` enables log, `true` disables log
- LOGGER_LEVEL: select a [logging level](https://github.com/winstonjs/winston#logging-levels)
- LOGGER_LEVEL: select a [logging level](https://github.com/pinojs/pino/blob/master/docs/API.md#level)
- LOGGER_PRETTY: pretty print log (should be set to `false` in production)
- PORT: application port
- PORT_DEV: **FOR DEVELOPMENT ONLY** will take effect when run `npm run dev`
- KANCOLLE_SERVER_MASTER: A host name for main Kancolle server that have interface`/kcsapi/api_world/get_id` for requesting players world id
Expand Down
9 changes: 4 additions & 5 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

'use strict'

require('dot-env')
const winston = require('winston')
const pino = require('pino')()
const app = require('../src/')
const http = require('http')

Expand Down Expand Up @@ -64,11 +63,11 @@ function onError(error) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
winston.error(bind + ' requires elevated privileges')
pino.error(bind + ' requires elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
winston.error(bind + ' is already in use')
pino.error(bind + ' is already in use')
process.exit(1)
break
default:
Expand All @@ -85,5 +84,5 @@ function onListening() {
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port
winston.info('modcolle is listening on ' + bind)
pino.info('modcolle is listening on ' + bind)
}
12 changes: 3 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

require('dot-env')

const appPort = process.env.PORT || '5000'
const devPort = process.env.PORT_DEV || '3000'
const css = 'src/views/*.css'
Expand Down Expand Up @@ -29,6 +27,8 @@ const source = require('vinyl-source-stream')
const browserify = require('browserify')
const buffer = require('vinyl-buffer')

gulp.task('default', ['build', 'import'])

gulp.task('build', ['build:css', 'build:js'])

gulp.task('build:css', () => {
Expand All @@ -52,13 +52,7 @@ gulp.task('build:js', () => {
.pipe(bs.stream())
})

gulp.task('import', ['environment-variables', 'font-awesome'])

gulp.task('environment-variables', () => {
gulp.src('.env.template.json')
.pipe(rename('.env.json'))
.pipe(gulp.dest('.', {overwrite: false}))
})
gulp.task('import', ['font-awesome'])

gulp.task('font-awesome', () => {
gulp.src('node_modules/font-awesome/css/font-awesome.min.css')
Expand Down
26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
]
},
"scripts": {
"build": "gulp build && gulp import",
"build": "gulp",
"prestart": "npm run build",
"start": "node bin/www",
"start": "pm2 start process.yml",
"dev": "npm run build && gulp browser-sync",
"coverage": "nyc npm test",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
Expand All @@ -32,38 +32,33 @@
"test": "npm run eslint && npm run utest"
},
"dependencies": {
"async": "2.3.0",
"body-parser": "1.17.1",
"dot-env": "0.0.1",
"eslint-config-modcolle": "0.1.1",
"express": "4.15.2",
"express-handlebars": "3.0.0",
"fallbackjs": "1.1.8",
"font-awesome": "4.7.0",
"inherit": "2.2.6",
"morgan": "1.8.1",
"passport": "0.3.2",
"passport-local": "1.0.0",
"pino": "4.5.0",
"request": "2.81.0",
"request-promise": "4.2.0",
"sprintf-js": "1.0.3",
"tough-cookie": "2.3.2",
"url-join": "2.0.1",
"url-parse": "1.1.8",
"validator": "7.0.0",
"winston": "2.3.1"
"validator": "7.0.0"
},
"devDependencies": {
"app-root-path": "2.0.1",
"async": "2.4.0",
"autoprefixer": "6.7.7",
"babel": "6.23.0",
"babel-preset-env": "1.4.0",
"browser-sync": "2.18.8",
"browserify": "14.3.0",
"cheerio": "0.22.0",
"coveralls": "2.13.0",
"coveralls": "2.13.1",
"eslint": "3.19.0",
"eslint-config-modcolle": "0.1.1",
"fallbackjs": "1.1.8",
"font-awesome": "4.7.0",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-clean-css": "3.0.4",
Expand All @@ -72,10 +67,11 @@
"gulp-rename": "1.2.2",
"gulp-uglify": "2.1.2",
"gulp-util": "3.0.8",
"mocha": "3.2.0",
"js-yaml": "3.8.3",
"mocha": "3.3.0",
"nock": "9.0.13",
"nodemon": "1.11.0",
"nyc": "10.2.0",
"nyc": "10.3.0",
"should": "11.2.1",
"sinon": "2.1.0",
"slash": "1.0.0",
Expand Down
17 changes: 0 additions & 17 deletions process.json

This file was deleted.

39 changes: 39 additions & 0 deletions process.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apps:
- name: Modcolle
script: bin/www
watch: false
instances: 0
merge_logs: true
exec_mode: cluster_mode

env:
LOGGER_PRETTY: true
LOGGER_LEVEL: info
PORT: 5000

KANCOLLE_SERVER_MASTER: http://203.104.209.7
KANCOLLE_SERVER_1: http://203.104.209.71
KANCOLLE_SERVER_2: http://203.104.209.87
KANCOLLE_SERVER_3: http://125.6.184.16
KANCOLLE_SERVER_4: http://125.6.187.205
KANCOLLE_SERVER_5: http://125.6.187.229
KANCOLLE_SERVER_6: http://125.6.187.253
KANCOLLE_SERVER_7: http://125.6.188.25
KANCOLLE_SERVER_8: http://203.104.248.135
KANCOLLE_SERVER_9: http://125.6.189.7
KANCOLLE_SERVER_10: http://125.6.189.39
KANCOLLE_SERVER_11: http://125.6.189.71
KANCOLLE_SERVER_12: http://125.6.189.103
KANCOLLE_SERVER_13: http://125.6.189.135
KANCOLLE_SERVER_14: http://125.6.189.167
KANCOLLE_SERVER_15: http://125.6.189.215
KANCOLLE_SERVER_16: http://125.6.189.247
KANCOLLE_SERVER_17: http://203.104.209.23
KANCOLLE_SERVER_18: http://203.104.209.39
KANCOLLE_SERVER_19: http://203.104.209.55
KANCOLLE_SERVER_20: http://203.104.209.102

env_production:
NODE_ENV: production
PORT: 5000
LOGGER_PRETTY: false
Loading