├── .eslintignore ├── .dockerignore ├── .eslintrc ├── config ├── plugin.js └── config.default.js ├── .gitignore ├── .travis.yml ├── app ├── router.js └── controller │ └── home.js ├── appveyor.yml ├── Dockerfile ├── .autod.conf.js ├── test └── app │ └── controller │ └── home.test.js ├── README.md ├── README.zh-CN.md └── package.json /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .git/ -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-egg" 3 | } 4 | -------------------------------------------------------------------------------- /config/plugin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // had enabled by egg 4 | // exports.static = true; 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | npm-debug.log 3 | yarn-error.log 4 | node_modules/ 5 | package-lock.json 6 | yarn.lock 7 | coverage/ 8 | .idea/ 9 | run/ 10 | .DS_Store 11 | *.sw* 12 | *.un~ 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | sudo: false 3 | language: node_js 4 | node_js: 5 | - '8' 6 | install: 7 | - npm i npminstall && npminstall 8 | script: 9 | - npm run ci 10 | after_script: 11 | - npminstall codecov && codecov -------------------------------------------------------------------------------- /app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @param {Egg.Application} app - egg application 5 | */ 6 | module.exports = app => { 7 | const { router, controller } = app; 8 | router.get('/', controller.home.index); 9 | }; 10 | -------------------------------------------------------------------------------- /app/controller/home.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Controller = require('egg').Controller; 4 | 5 | class HomeController extends Controller { 6 | async index() { 7 | this.ctx.body = 'hi, egg'; 8 | } 9 | } 10 | 11 | module.exports = HomeController; 12 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: '8' 4 | 5 | install: 6 | - ps: Install-Product node $env:nodejs_version 7 | - npm i npminstall && node_modules\.bin\npminstall 8 | 9 | test_script: 10 | - node --version 11 | - npm --version 12 | - npm run test 13 | 14 | build: off 15 | -------------------------------------------------------------------------------- /config/config.default.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = appInfo => { 4 | const config = exports = {}; 5 | 6 | // use for cookie sign key, should change to your own and keep security 7 | config.keys = appInfo.name + '_1532398873411_4893'; 8 | 9 | // add your config here 10 | config.middleware = []; 11 | 12 | return config; 13 | }; 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8.11.3-alpine 2 | 3 | ENV TIME_ZONE=Asia/Shanghai 4 | 5 | RUN \ 6 | mkdir -p /usr/src/app \ 7 | && apk add --no-cache tzdata \ 8 | && echo "${TIME_ZONE}" > /etc/timezone \ 9 | && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime 10 | 11 | WORKDIR /usr/src/app 12 | 13 | COPY package.json /usr/src/app/ 14 | 15 | RUN npm i 16 | 17 | # RUN npm i --registry=https://registry.npm.taobao.org 18 | 19 | COPY . /usr/src/app 20 | 21 | EXPOSE 7001 22 | 23 | CMD npm run start -------------------------------------------------------------------------------- /.autod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | write: true, 5 | prefix: '^', 6 | plugin: 'autod-egg', 7 | test: [ 8 | 'test', 9 | 'benchmark', 10 | ], 11 | dep: [ 12 | 'egg', 13 | 'egg-scripts', 14 | ], 15 | devdep: [ 16 | 'egg-ci', 17 | 'egg-bin', 18 | 'egg-mock', 19 | 'autod', 20 | 'autod-egg', 21 | 'eslint', 22 | 'eslint-config-egg', 23 | 'webstorm-disable-index', 24 | ], 25 | exclude: [ 26 | './test/fixtures', 27 | './dist', 28 | ], 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /test/app/controller/home.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { app, assert } = require('egg-mock/bootstrap'); 4 | 5 | describe('test/app/controller/home.test.js', () => { 6 | 7 | it('should assert', function* () { 8 | const pkg = require('../../../package.json'); 9 | assert(app.config.keys.startsWith(pkg.name)); 10 | 11 | // const ctx = app.mockContext({}); 12 | // yield ctx.service.xx(); 13 | }); 14 | 15 | it('should GET /', () => { 16 | return app.httpRequest() 17 | .get('/') 18 | .expect('hi, egg') 19 | .expect(200); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-boilerplate 2 | 3 | Egg.js docker boilerplate. 4 | 5 | ## QuickStart 6 | 7 | 8 | 9 | see [egg docs][egg] for more detail. 10 | 11 | ### Development 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### Deploy 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | **Docker** 27 | 28 | ```bash 29 | $ docker build -t egg-boilerplate . 30 | $ docker run -p 7001:7001 egg-boilerplate 31 | ``` 32 | 33 | ### npm scripts 34 | 35 | - Use `npm run lint` to check code style. 36 | - Use `npm test` to run unit test. 37 | - Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. 38 | 39 | 40 | [egg]: https://eggjs.org -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 | # docker-boilerplate 2 | 3 | Egg.js docker boilerplate. 4 | 5 | ## 快速入门 6 | 7 | 8 | 9 | 如需进一步了解,参见 [egg 文档][egg]。 10 | 11 | ### 本地开发 12 | 13 | ```bash 14 | $ npm i 15 | $ npm run dev 16 | $ open http://localhost:7001/ 17 | ``` 18 | 19 | ### 部署 20 | 21 | ```bash 22 | $ npm start 23 | $ npm stop 24 | ``` 25 | 26 | **Docker** 27 | 28 | ```bash 29 | $ docker build -t egg-boilerplate . 30 | $ docker run -p 7001:7001 egg-boilerplate 31 | ``` 32 | 33 | ### 单元测试 34 | 35 | - [egg-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。 36 | - 断言库非常推荐使用 [power-assert]。 37 | - 具体参见 [egg 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)。 38 | 39 | ### 内置指令 40 | 41 | - 使用 `npm run lint` 来做代码风格检查。 42 | - 使用 `npm test` 来执行单元测试。 43 | - 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod) 。 44 | 45 | 46 | [egg]: https://eggjs.org 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-boilerplate", 3 | "version": "1.0.0", 4 | "description": "", 5 | "private": true, 6 | "dependencies": { 7 | "egg": "^2.9.1", 8 | "egg-scripts": "^2.6.0" 9 | }, 10 | "devDependencies": { 11 | "autod": "^3.0.1", 12 | "autod-egg": "^1.1.0", 13 | "egg-bin": "^4.7.1", 14 | "egg-ci": "^1.8.0", 15 | "egg-mock": "^3.17.3", 16 | "eslint": "^5.2.0", 17 | "eslint-config-egg": "^7.0.0", 18 | "webstorm-disable-index": "^1.2.0" 19 | }, 20 | "engines": { 21 | "node": ">=8.9.0" 22 | }, 23 | "scripts": { 24 | "start": "egg-scripts start --title=egg-server-docker-boilerplate", 25 | "startd": "egg-scripts start --daemon --title=egg-server-docker-boilerplate", 26 | "stop": "egg-scripts stop --title=egg-server-docker-boilerplate", 27 | "dev": "egg-bin dev", 28 | "debug": "egg-bin debug", 29 | "test": "npm run lint -- --fix && npm run test-local", 30 | "test-local": "egg-bin test", 31 | "cov": "egg-bin cov", 32 | "lint": "eslint .", 33 | "ci": "npm run lint && npm run cov", 34 | "autod": "autod" 35 | }, 36 | "ci": { 37 | "version": "8" 38 | }, 39 | "repository": { 40 | "type": "git", 41 | "url": "" 42 | }, 43 | "author": "Suyi Thonatos.Yang", 44 | "license": "MIT" 45 | } 46 | --------------------------------------------------------------------------------