Skip to content

Commit 3c55555

Browse files
committed
docker部署文档
1 parent 0489f3b commit 3c55555

6 files changed

Lines changed: 473 additions & 29 deletions

File tree

docker/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# docker 部署 code-push-server
2+
3+
>该文档用于描述docker部署code-push-server,实例包含两个部分
4+
5+
- code-push-server部分
6+
- 更新包默认采用`local`存储(即存储在本地机器上)。使用docker volume存储方式,容器销毁不会导致数据丢失,除非人为删除volume。
7+
- 默认开启5个实例,使用swarn内部默认负载均衡策略,可以根据自己机器设置docker-compose.yml文件中deploy参数。
8+
- docker-compose.yml只提供了应用部分参数设置,如需要其他特定配置,可以修改文件config.js。
9+
- mysql部分
10+
- 数据使用docker volume存储方式,容器销毁不会导致数据丢失,除非人为删除volume。
11+
- 默认应用使用root用户,为了安全可以创建权限相对较小的权限供code-push-server使用
12+
13+
14+
## 安装docker
15+
16+
参考docker官方安装教程
17+
18+
- [>>mac点这里](https://docs.docker.com/docker-for-mac/install/)
19+
- [>>windows点这里](https://docs.docker.com/docker-for-windows/install/)
20+
- linux基本都自带,但是需要启动,如果版本太老,请更新到最新稳定版
21+
22+
23+
`$ docker info` 能成功输出相关信息,则安装成功,才能继续下面步骤
24+
25+
## 启动swarm
26+
27+
```bash
28+
$ docker swarm init
29+
```
30+
31+
32+
## 获取代码
33+
34+
```bash
35+
$ git clone https://github.com/lisong/code-push-server.git
36+
$ cd code-push-server/docker
37+
```
38+
39+
## 修改配置文件
40+
41+
```bash
42+
$ vim docker-compose.yml
43+
```
44+
45+
*`DOWNLOAD_URL``YOU_MACHINE_IP`替换成本机ip*
46+
*`MYSQL_HOST``YOU_MACHINE_IP`替换成本机ip*
47+
48+
## jwt.tokenSecret修改
49+
50+
> code-push-server 验证登录验证方式使用的json web token加密方式,该对称加密算法是公开的,所以修改config.js中tokenSecret值很重要。
51+
52+
* 非常重要!非常重要! 非常重要!*
53+
54+
> 可以打开连接`https://www.grc.com/passwords.htm`获取 `63 random alpha-numeric characters`类型的随机生成数作为密钥
55+
56+
## 部署
57+
58+
```
59+
$ docker stack deploy -c docker-compose.yml code-push-server
60+
```
61+
62+
> 如果网速不佳,需要漫长而耐心的等待。。。去和妹子聊会天吧^_^
63+
64+
65+
## 查看进展
66+
67+
```
68+
$ docker service ls
69+
$ docker service ps code-push-server_db
70+
$ docker service ps code-push-server_server
71+
```
72+
73+
> 确认`CURRENT STATE``Running about ...`, 则已经部署完成
74+
75+
## 访问接口简单验证
76+
77+
`$ curl -I http://127.0.0.1:3000/`
78+
79+
返回`200 OK`
80+
81+
```http
82+
HTTP/1.1 200 OK
83+
X-DNS-Prefetch-Control: off
84+
X-Frame-Options: SAMEORIGIN
85+
Strict-Transport-Security: max-age=15552000; includeSubDomains
86+
X-Download-Options: noopen
87+
X-Content-Type-Options: nosniff
88+
X-XSS-Protection: 1; mode=block
89+
Content-Type: text/html; charset=utf-8
90+
Content-Length: 592
91+
ETag: W/"250-IiCMcM1ZUFSswSYCU0KeFYFEMO8"
92+
Date: Sat, 25 Aug 2018 15:45:46 GMT
93+
Connection: keep-alive
94+
```
95+
96+
## 查看服务日志
97+
98+
```shell
99+
$ docker service logs code-push-server_server
100+
$ docker service logs code-push-server_db
101+
```
102+
103+
## 查看存储 `docker volume ls`
104+
105+
DRIVER | VOLUME NAME | 描述
106+
------ | ----- | -------
107+
local | code-push-server_data-mysql | 数据库存储数据目录
108+
local | code-push-server_data-storage | 存储打包文件目录
109+
local | code-push-server_data-tmp | 用于计算更新包差异文件临时目录
110+
111+
## 销毁退出应用
112+
113+
```bash
114+
$ docker stack rm code-push-server
115+
```

docker/code-push-server/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:8.11.4-alpine
2+
3+
RUN npm config set registry https://registry.npm.taobao.org/ \
4+
&& npm i -g code-push-server@0.4.3 --no-optional
5+
6+
EXPOSE 3000
7+
8+
CMD ["code-push-server"]

docker/config.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var config = {};
2+
config.development = {
3+
// Config for database, only support mysql.
4+
db: {
5+
username: process.env.MYSQL_USERNAME,
6+
password: process.env.MYSQL_PASSWORD,
7+
database: process.env.MYSQL_DATABASE,
8+
host: process.env.MYSQL_HOST,
9+
port: process.env.MYSQL_PORT || 3306,
10+
dialect: "mysql",
11+
logging: false,
12+
operatorsAliases: false,
13+
},
14+
// Config for local storage when storageType value is "local".
15+
local: {
16+
// Binary files storage dir, Do not use tmpdir and it's public download dir.
17+
storageDir: process.env.STORAGE_DIR,
18+
// Binary files download host address which Code Push Server listen to. the files storage in storageDir.
19+
downloadUrl: process.env.DOWNLOAD_URL,
20+
// public static download spacename.
21+
public: '/download'
22+
},
23+
jwt: {
24+
// Recommended: 63 random alpha-numeric characters
25+
// Generate using: https://www.grc.com/passwords.htm
26+
tokenSecret: 'INSERT_RANDOM_TOKEN_KEY'
27+
},
28+
common: {
29+
/*
30+
* tryLoginTimes is control login error times to avoid force attack.
31+
* if value is 0, no limit for login auth, it may not safe for account. when it's a number, it means you can
32+
* try that times today. but it need config redis server.
33+
*/
34+
tryLoginTimes: 0,
35+
// CodePush Web(https://github.com/lisong/code-push-web) login address.
36+
//codePushWebUrl: "http://127.0.0.1:3001/login",
37+
// create patch updates's number. default value is 3
38+
diffNums: 3,
39+
// data dir for caclulate diff files. it's optimization.
40+
dataDir: process.env.DATA_DIR,
41+
// storageType which is your binary package files store. options value is ("local" | "qiniu" | "s3")
42+
storageType: "local",
43+
// options value is (true | false), when it's true, it will cache updateCheck results in redis.
44+
updateCheckCache: false,
45+
// options value is (true | false), when it's true, it will cache rollout results in redis
46+
rolloutClientUniqueIdCache: false,
47+
},
48+
// Config for smtp email,register module need validate user email project source https://github.com/nodemailer/nodemailer
49+
smtpConfig:{
50+
host: "smtp.aliyun.com",
51+
port: 465,
52+
secure: true,
53+
auth: {
54+
user: "",
55+
pass: ""
56+
}
57+
},
58+
// Config for redis (register module, tryLoginTimes module)
59+
redis: {
60+
default: {
61+
host: "127.0.0.1",
62+
port: 6379,
63+
retry_strategy: function (options) {
64+
if (options.error.code === 'ECONNREFUSED') {
65+
// End reconnecting on a specific error and flush all commands with a individual error
66+
return new Error('The server refused the connection');
67+
}
68+
if (options.total_retry_time > 1000 * 60 * 60) {
69+
// End reconnecting after a specific timeout and flush all commands with a individual error
70+
return new Error('Retry time exhausted');
71+
}
72+
if (options.times_connected > 10) {
73+
// End reconnecting with built in error
74+
return undefined;
75+
}
76+
// reconnect after
77+
return Math.max(options.attempt * 100, 3000);
78+
}
79+
}
80+
}
81+
}
82+
83+
config.development.log4js = {
84+
appenders: {console: { type: 'console'}},
85+
categories : {
86+
"default": { appenders: ['console'], level:'error'},
87+
"startup": { appenders: ['console'], level:'info'},
88+
"http": { appenders: ['console'], level:'info'}
89+
}
90+
}
91+
92+
config.production = Object.assign({}, config.development);
93+
module.exports = config;

docker/docker-compose.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
version: "3.3"
2+
services:
3+
server:
4+
image: tablee/code-push-server:v0.4.3
5+
volumes:
6+
- data-storage:/data/storage
7+
- data-tmp:/data/tmp
8+
- ./config.js:/config.js
9+
environment:
10+
DOWNLOAD_URL: "http://YOU_MACHINE_IP:3000/download"
11+
MYSQL_HOST: "YOU_MACHINE_IP"
12+
MYSQL_PORT: "3308"
13+
MYSQL_USERNAME: "root"
14+
MYSQL_PASSWORD: null
15+
MYSQL_DATABASE: "codepush"
16+
STORAGE_DIR: "/data/storage"
17+
DATA_DIR: "/data/tmp"
18+
NODE_ENV: "production"
19+
CONFIG_FILE: "/config.js"
20+
deploy:
21+
replicas: 5
22+
resources:
23+
limits:
24+
cpus: "1"
25+
memory: 1000M
26+
restart_policy:
27+
condition: on-failure
28+
ports:
29+
- "3000:3000"
30+
networks:
31+
- servernet
32+
depends_on:
33+
- "db"
34+
db:
35+
image: mysql:5.7.23
36+
volumes:
37+
- data-mysql:/var/lib/mysql
38+
- ./sql/codepush-all.sql:/docker-entrypoint-initdb.d/codepush-all.sql
39+
ports:
40+
- "3308:3306"
41+
environment:
42+
MYSQL_ALLOW_EMPTY_PASSWORD: "On"
43+
networks:
44+
- dbnet
45+
networks:
46+
servernet:
47+
dbnet:
48+
volumes:
49+
data-storage:
50+
data-tmp:
51+
data-mysql:

0 commit comments

Comments
 (0)