Skip to content

Commit 111749d

Browse files
committed
Fixed: #27
1 parent 190fc7a commit 111749d

File tree

11 files changed

+218
-141
lines changed

11 files changed

+218
-141
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git
2+
.gitignore
3+
README.md
4+
docker-compose.yml
5+
node_modules/
6+
dist/
7+
test/

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM node:carbon-alpine
2+
WORKDIR /www
3+
COPY . /www
4+
RUN npm install

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ PORT=8888
6060

6161
### Run
6262

63+
> Node.js & Docker support. **You need to create a `.env` file as above**.
64+
6365
### Node.js
6466

6567
Beacuse of using Koa2, `Node.js >= v7.6.0` is needed.
@@ -74,7 +76,7 @@ open browser: `localhost:8080`
7476
7577
#### Production:
7678

77-
`npm run build` and then `npm run server`
79+
`npm run start`
7880

7981
open browser: `localhost:8889`
8082

@@ -84,6 +86,16 @@ open browser: `localhost:8889`
8486

8587
`npm run test` and find the coverage report in the `coverage/lcov/index.html`
8688

89+
### Docker
90+
91+
`docker-compose build` && `docker-compose up`
92+
93+
> mysql in docker use 3306 port inside & outside.
94+
95+
open browser: `localhost:8889`
96+
97+
> tips: login password is 123
98+
8799
## License
88100

89101
[MIT](http://opensource.org/licenses/MIT)

docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: "3"
2+
3+
volumes:
4+
mysqlstorage:
5+
6+
services:
7+
node:
8+
build:
9+
context: .
10+
dockerfile: Dockerfile
11+
env_file:
12+
- ./.env
13+
volumes:
14+
- ./:/www
15+
ports:
16+
- ${PORT}:${PORT}
17+
command: "npm run start"
18+
environment:
19+
DB_URL: mysql
20+
links:
21+
- mysql
22+
depends_on:
23+
- mysql
24+
25+
mysql:
26+
image: 'mysql:5.7'
27+
env_file:
28+
- ./.env
29+
environment:
30+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
31+
MYSQL_USER: ${DB_USER}
32+
build:
33+
context: .
34+
dockerfile: mysql.dockerfile
35+
args:
36+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
37+
restart: always
38+
volumes:
39+
- mysqlstorage:/data/db
40+
ports:
41+
- "3306:3306"

init_db.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
mysql -u$MYSQL_USER -p$MYSQL_ROOT_PASSWORD <<EOF
3+
source $WORK_PATH/$FILE_0;
4+
source $WORK_PATH/$FILE_1;

mysql.dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mysql:5.7
2+
LABEL maintainer="Molunerfinn <[email protected]>"
3+
ARG MYSQL_ROOT_PASSWORD
4+
ARG MYSQL_USER
5+
6+
ENV MYSQL_ROOT_PASSWORD $MYSQL_ROOT_PASSWORD
7+
ENV MYSQL_USER $MYSQL_USER
8+
ENV WORK_PATH /usr/local/db
9+
ENV FILE_0 list.sql
10+
ENV FILE_1 user.sql
11+
USER root
12+
13+
WORKDIR $WORK_PATH/
14+
15+
COPY ./sql/*.sql $WORK_PATH/
16+
COPY ./init_db.sh /docker-entrypoint-initdb.d/init_db.sh
17+
18+
RUN chmod a+x /docker-entrypoint-initdb.d/init_db.sh

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"server": "nodemon -w app.js -w server server-entry.js",
1111
"test": "cross-env NODE_ENV=test jest --forceExit --runInBand",
1212
"coverage": "cat ./coverage/lcov.info | coveralls",
13-
"start": "cross-env NODE_ENV=production pm2 start pm2.json"
13+
"prod": "cross-env NODE_ENV=production node server-entry.js",
14+
"start": "npm run build && npm run prod",
15+
"start:pm2": "cross-env NODE_ENV=production pm2 start pm2.json"
1416
},
1517
"dependencies": {
1618
"axios": "^0.15.3",
@@ -31,10 +33,10 @@
3133
"stylus-loader": "^2.4.0",
3234
"supertest": "^3.0.0",
3335
"vue": "2.5.2",
34-
"vue-jest": "^1.0.3",
3536
"vue-router": "^2.3.1"
3637
},
3738
"devDependencies": {
39+
"@vue/test-utils": "^1.0.0-beta.12",
3840
"autoprefixer": "^7.1.2",
3941
"babel-core": "^6.22.1",
4042
"babel-eslint": "^7.1.1",
@@ -79,10 +81,11 @@
7981
"semver": "^5.3.0",
8082
"shelljs": "^0.7.6",
8183
"url-loader": "^0.5.8",
84+
"vue-jest": "^2.3.0",
8285
"vue-loader": "^13.3.0",
86+
"vue-server-renderer": "^2.5.16",
8387
"vue-style-loader": "^3.0.1",
8488
"vue-template-compiler": "2.5.2",
85-
"vue-test-utils": "^1.0.0-beta.4",
8689
"webpack": "^3.6.0",
8790
"webpack-bundle-analyzer": "^2.9.0",
8891
"webpack-dev-middleware": "^1.12.0",

server/config/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '../../env'
22
import Sequelize from 'sequelize'
33

4-
const Todolist = new Sequelize(`mysql://${process.env.DB_USER}:${process.env.DB_PASSWORD}@localhost/todolist`, {
4+
const Todolist = new Sequelize(`mysql://${process.env.DB_USER}:${process.env.DB_PASSWORD}@${process.env.DB_URL || 'localhost'}/todolist`, {
55
define: {
66
timestamps: false // 取消Sequelzie自动给数据表加入时间戳(createdAt以及updatedAt)
77
}

test/client/login.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import elementUI from 'element-ui'
3-
import { mount } from 'vue-test-utils'
3+
import { mount } from '@vue/test-utils'
44
import Login from '../../src/components/Login.vue'
55
import axios from 'axios'
66

test/client/todolist.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import elementUI from 'element-ui'
3-
import { mount } from 'vue-test-utils'
3+
import { mount } from '@vue/test-utils'
44
import Todolist from '../../src/components/Todolist.vue'
55
import axios from 'axios'
66

0 commit comments

Comments
 (0)