Skip to content

Commit 5416e54

Browse files
committed
add yapi
1 parent 8928439 commit 5416e54

File tree

6 files changed

+210
-0
lines changed

6 files changed

+210
-0
lines changed

Program/工具篇/Yapi/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:11 as builder
2+
3+
RUN apt-get install -y git python make openssl tar gcc
4+
ADD yapi.tgz /home/
5+
RUN mkdir /api && mv /home/package /api/vendors
6+
RUN cd /api/vendors && \
7+
npm install --production --registry https://registry.npm.taobao.org
8+
9+
FROM node:11
10+
11+
MAINTAINER hua.xu
12+
ENV TZ="Asia/Shanghai" HOME="/"
13+
WORKDIR ${HOME}
14+
15+
COPY --from=builder /api/vendors /api/vendors
16+
COPY config.json /api/
17+
EXPOSE 3001
18+
19+
COPY docker-entrypoint.sh /api/
20+
RUN chmod 755 /api/docker-entrypoint.sh
21+
22+
ENTRYPOINT ["/api/docker-entrypoint.sh"]

Program/工具篇/Yapi/config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"port": "MY_PORT",
3+
"adminAccount": "MY_ACOUNT",
4+
"db": {
5+
"servername": "MY_DB_SERVER",
6+
"DATABASE": "MY_DB_NAME",
7+
"port": "MY_DB_PORT",
8+
"user": "MY_USER",
9+
"pass": "MY_PASS",
10+
"authSource": "MY_AUTH"
11+
}
12+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '3.7'
2+
networks:
3+
netdci:
4+
5+
services:
6+
yapi:
7+
build:
8+
context: ./
9+
dockerfile: ./Dockerfile
10+
image: skycitygalaxy/yapi
11+
container_name: yapi
12+
environment:
13+
- VERSION=1.8.1
14+
- LOG_PATH=/tmp/yapi.log
15+
- HOME=/home
16+
- MY_PORT=3001
17+
18+
- MY_DB_SERVER=127.0.0.1
19+
- MY_DB_NAME=yapi
20+
- MY_DB_PORT=27027
21+
- MY_USER=xu
22+
- MY_PASS=xu
23+
- MY_AUTH=test
24+
ports:
25+
- 127.0.0.1:3000:3000
26+
volumes:
27+
- ~/data/yapi/log/yapi.log:/home/vendors/log # log dir
28+
depends_on:
29+
- mongo
30+
networks:
31+
- netdci
32+
33+
mongo:
34+
image: mongo
35+
container_name: mongo
36+
ports:
37+
- 127.0.0.1:27027:27017
38+
volumes:
39+
- ~/data/yapi/mongodb:/data/db #db dir
40+
networks:
41+
- netdci
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
shopt -s nullglob
4+
5+
MY_PORT="${MY_PORT:=3000}"
6+
MY_ACOUNT="${MY_ACOUNT:=heroxu123@gmail.com}"
7+
MY_DB_SERVER="${MY_DB_SERVER:=127.0.0.1}"
8+
MY_DB_NAME="${MY_DB_NAME:=yapi}"
9+
MY_DB_PORT="${MY_DB_PORT:=27027}"
10+
MY_USER="${MY_USER:=xu}"
11+
MY_PASS="${MY_PASS:=xu}"
12+
MY_AUTH="${MY_AUTH:=test}"
13+
14+
config() {
15+
if [[ -z "${MY_PORT}" || -z "${MY_ACOUNT}" || -z "${MY_DB_SERVER}" || -z "${MY_DB_NAME}" || -z "${MY_DB_PORT}" || -z "${MY_USER}" || -z "${MY_PASS}" || -z "${MY_AUTH}" ]]; then
16+
echo -e "\n\"MY_PORT\" or \"MY_ACOUNT\" or \"MY_DB_SERVER\" or \"MY_DB_NAME\" or \"MY_DB_PORT\" or \"MY_USER\" or \"MY_PASS\" or \"MY_AUTH\" can not be empty!\n" && exit 1
17+
else
18+
sed -i "s#MY_PORT#${MY_PORT}#g" /api/config.json
19+
sed -i "s#MY_ACOUNT#${MY_ACOUNT}#g" /api/config.json
20+
sed -i "s#MY_DB_SERVER#${MY_DB_SERVER}#g" /api/config.json
21+
sed -i "s#MY_DB_NAME#${MY_DB_NAME}#g" /api/config.json
22+
sed -i "s#MY_DB_PORT#${MY_DB_PORT}#g" /api/config.json
23+
sed -i "s#MY_USER#${MY_USER}#g" /api/config.json
24+
sed -i "s#MY_PASS#${MY_PASS}#g" /api/config.json
25+
sed -i "s#MY_AUTH#${MY_AUTH}#g" /api/config.json
26+
27+
fi
28+
}
29+
30+
config
31+
32+
node /api/vendors/server/app.js
33+
34+
exec "$@"

Program/工具篇/Yapi/download.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function usage(){
2+
echo "usage: sh build.sh <version>"
3+
echo "默认版本: 1.7.1"
4+
echo "yapi的版本: https://github.com/YMFE/yapi/releases"
5+
echo "我们将从这里下载: http://registry.npm.taobao.org/yapi-vendor/download/yapi-vendor-\$1.tgz"
6+
}
7+
8+
9+
10+
version=1.7.1
11+
12+
if [ -n "$1" ]; then
13+
version=$1
14+
fi
15+
16+
usage
17+
18+
19+
echo -e "\033[32m download new package (version $version) \033[0m"
20+
21+
wget -O yapi.tgz http://registry.npm.taobao.org/yapi-vendor/download/yapi-vendor-$version.tgz
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# 使用DockerCompose构建部署Yapi
2+
3+
## OverView
4+
5+
YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台 https://hellosean1025.github.io/yapi
6+
7+
## 准备一个自己的 Mongo
8+
9+
因为这些数据都是要落地的,建议单独准备一个DB。
10+
11+
## 自己构建镜像
12+
13+
自己构建的镜像可以保证镜像的安全,或者可以魔改一下代码再构建镜像。
14+
15+
- 下载 Yapi
16+
17+
```
18+
./download.sh 1.8.1
19+
```
20+
21+
- 构建镜像
22+
23+
```
24+
docker-compose build
25+
```
26+
27+
- Push 镜像
28+
29+
```
30+
docker tag skycitygalaxy/yapi:latest skycitygalaxy/yapi:v7
31+
docker push skycitygalaxy/yapi:v7
32+
```
33+
34+
## 直接使用镜像,本地部署
35+
36+
如果不想自己构建镜像的话,可以使用我打包好的镜像:skycitygalaxy/yapi:v7
37+
38+
- 拉取镜像
39+
40+
```
41+
docker pull skycitygalaxy/yapi:v7
42+
```
43+
44+
- 启动服务
45+
46+
```
47+
docker run -d -p 3001:3000 --name yapi skycitygalaxy/yapi:v7
48+
```
49+
50+
- 修改配置
51+
52+
进入容器,修改配置为自己的配置。
53+
54+
```
55+
docker exec -ti yapi bash
56+
cd /api/
57+
vim config.json
58+
```
59+
60+
- 重启服务
61+
62+
```
63+
docker restart yapi
64+
```
65+
66+
- 访问 http://127.0.0.1:3001/
67+
68+
![](http://cdn.heroxu.com/2019080815652468118063.png)
69+
70+
## 使用 Rancher 部署
71+
72+
- 配置环境变量
73+
74+
![](http://cdn.heroxu.com/20190808156524572847385.png)
75+
76+
- 部署完成
77+
78+
![](http://cdn.heroxu.com/20190808156524588021590.png)
79+
80+
![](http://cdn.heroxu.com/20190808156524581769215.png)

0 commit comments

Comments
 (0)