Skip to content

Commit

Permalink
被docker-compose replicas 坑了一把
Browse files Browse the repository at this point in the history
  • Loading branch information
lisong committed Aug 26, 2018
1 parent 8f135ca commit 201626f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- code-push-server部分
- 更新包默认采用`local`存储(即存储在本地机器上)。使用docker volume存储方式,容器销毁不会导致数据丢失,除非人为删除volume。
- 默认开启5个实例,使用swarm内部默认负载均衡策略,可以根据自己机器配置设置docker-compose.yml文件中deploy参数。
- 内部使用pm2 cluster模式管理进程,默认开启进程数为cpu数,可以根据自己机器配置设置docker-compose.yml文件中deploy参数。
- docker-compose.yml只提供了应用的一部分参数设置,如需要设置其他配置,可以修改文件config.js。
- mysql部分
- 数据使用docker volume存储方式,容器销毁不会导致数据丢失,除非人为删除volume。
Expand Down
8 changes: 5 additions & 3 deletions docker/code-push-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM node:8.11.4-alpine

RUN npm config set registry https://registry.npm.taobao.org/ \
&& npm i -g code-push-server@0.4.3 --no-optional
RUN npm config set registry https://registry.npm.taobao.org/ \
&& npm i -g code-push-server@0.4.3 pm2@latest --no-optional

COPY ./process.json /process.json

EXPOSE 3000

CMD ["code-push-server"]
CMD ["pm2-docker", "start", "/process.json"]
11 changes: 11 additions & 0 deletions docker/code-push-server/process.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"apps" : [
{
"name" : "code-push-server",
"max_memory_restart" : "500M",
"script" : "code-push-server",
"instances" : "max", //开启实例数量,max为cpu核数
"exec_mode" : "cluster", //集群模式,最大提升网站并发
}
]
}
12 changes: 6 additions & 6 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.3"
version: "3.7"
services:
server:
image: tablee/code-push-server:v0.4.3
image: tablee/code-push-server:v0.4.4
volumes:
- data-storage:/data/storage
- data-tmp:/data/tmp
Expand All @@ -10,8 +10,8 @@ services:
DOWNLOAD_URL: "http://YOU_MACHINE_IP:3000/download"
MYSQL_HOST: "YOU_MACHINE_IP"
MYSQL_PORT: "3308"
MYSQL_USERNAME: "root"
MYSQL_PASSWORD: null
MYSQL_USERNAME: "codepush"
MYSQL_PASSWORD: "123456"
MYSQL_DATABASE: "codepush"
STORAGE_DIR: "/data/storage"
DATA_DIR: "/data/tmp"
Expand All @@ -20,7 +20,6 @@ services:
REDIS_HOST: "YOU_MACHINE_IP"
REDIS_PORT: "6388"
deploy:
replicas: 5
resources:
limits:
cpus: "2"
Expand Down Expand Up @@ -52,10 +51,11 @@ services:
ports:
- "6388:6379"
networks:
- dbnet
- redisnet
networks:
servernet:
dbnet:
redisnet:
volumes:
data-storage:
data-tmp:
Expand Down
4 changes: 4 additions & 0 deletions docker/sql/codepush-all.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CREATE DATABASE IF NOT EXISTS `codepush`;

GRANT SELECT,UPDATE,INSERT ON `codepush`.* TO 'codepush'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

flush privileges;

use `codepush`;
CREATE TABLE IF NOT EXISTS `apps` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
Expand Down

0 comments on commit 201626f

Please sign in to comment.