Initial commit
This commit is contained in:
commit
5cb79e2866
49
Dockerfile
Normal file
49
Dockerfile
Normal file
@ -0,0 +1,49 @@
|
||||
FROM node:12-alpine as builder
|
||||
|
||||
ENV YAPI_VERSION="1.9.2"
|
||||
ENV YAPI_HOME="/yapi"
|
||||
ENV GIT_URL="https://github.com/YMFE/yapi.git"
|
||||
ENV GIT_MIRROR_URL="https://gitee.com/mirrors/YApi.git"
|
||||
|
||||
WORKDIR ${YAPI_HOME}
|
||||
|
||||
COPY config.json .
|
||||
COPY start.sh .
|
||||
|
||||
RUN apk add --no-cache wget python make git curl
|
||||
RUN chmod +x start.sh
|
||||
RUN ret=`curl -s https://api.ip.sb/geoip | grep China | wc -l` && \
|
||||
if [ $ret -ne 0 ]; then \
|
||||
GIT_URL=${GIT_MIRROR_URL} && npm config set registry https://registry.npm.taobao.org; \
|
||||
fi;
|
||||
RUN git clone --depth 1 --branch v${YAPI_VERSION} --single-branch ${GIT_URL} vendors
|
||||
|
||||
WORKDIR ${YAPI_HOME}/vendors
|
||||
#RUN npm install -g node-gyp yapi-cli
|
||||
RUN npm install --production
|
||||
|
||||
|
||||
FROM node:12-alpine
|
||||
|
||||
ENV TZ="Asia/Shanghai"
|
||||
ENV YAPI_VERSION="1.9.2"
|
||||
ENV YAPI_HOME="/yapi"
|
||||
ENV YAPI_PORT="3000"
|
||||
ENV ADMIN_EMAIL="master@simaek.com"
|
||||
ENV DB_HOST="mongo"
|
||||
ENV DB_NAME="yapi"
|
||||
ENV DB_PORT="27017"
|
||||
ENV MAIL_ENABLE="false"
|
||||
ENV MAIL_HOST="127.0.0.1"
|
||||
ENV MAIL_PORT="465"
|
||||
ENV MAIL_FROM="master@simaek.com"
|
||||
ENV MAIL_USER="user"
|
||||
ENV MAIL_PWD="password"
|
||||
|
||||
WORKDIR ${YAPI_HOME}
|
||||
|
||||
COPY --from=builder /yapi .
|
||||
|
||||
EXPOSE ${YAPI_PORT}
|
||||
#ENTRYPOINT ["node", "server/app.js"]
|
||||
ENTRYPOINT ["sh", "start.sh"]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 SIMAEK
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
97
README.md
Normal file
97
README.md
Normal file
@ -0,0 +1,97 @@
|
||||
[![MIT Licence](https://img.shields.io/github/license/jinfeijie/yapi.svg?style=flat-square)](https://opensource.org/licenses/mit-license.php)
|
||||
|
||||
|
||||
|
||||
|
||||
## ⚠️注意
|
||||
|
||||
本仓库目前只支持安装,暂不支持升级,请知晓。如需升级请自行备份mongoDB内的数据。
|
||||
|
||||
|
||||
|
||||
## 构建镜像
|
||||
|
||||
克隆本仓库到本地。
|
||||
|
||||
```
|
||||
git clone --depth 1 https://code.simaek.com/xueye/yapi-docker.git
|
||||
```
|
||||
|
||||
执行构建脚本。
|
||||
|
||||
```
|
||||
chmod +x build.sh && ./build.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
## docker-compose 部署
|
||||
|
||||
修改`docker-compose.yml`文件中的相关参数,以下是变量的一些说明。
|
||||
|
||||
| 环境变量 | 默认值 | 建议 |
|
||||
| ------------- |:-------------:|:-----------:|
|
||||
| YAPI_PORT | 3000 | 可修改 |
|
||||
| ADMIN_EMAIL | master@simaek.com | 建议修改 |
|
||||
| DB_HOST | mongo | 不建议修改 |
|
||||
| DB_NAME | yapi | 不建议修改 |
|
||||
| DB_PORT | 27017 | 不建议修改|
|
||||
| MAIL_ENABLE | false | 是否启用邮件功能 |
|
||||
| MAIL_HOST | 127.0.0.1 | 邮件服务器地址 |
|
||||
| MAIL_PORT | 465 | 邮件服务器端口 |
|
||||
| MAIL_FROM | master@simaek.com | 发件人 |
|
||||
| MAIL_USER | user | 邮件服务器用户名 |
|
||||
| MAIL_PWD | password | 邮件服务器密码 |
|
||||
|
||||
使用`docker-compose`启动服务。
|
||||
|
||||
````
|
||||
docker-compose up -d
|
||||
````
|
||||
|
||||
访问地址为:`YOU_SERVER_IP:YAPI_PORT`,用户名为`#{ADMIN_EMAIL}`,默认密码为:`ymfe.org`。
|
||||
|
||||
也可通过Docker的日志查看。
|
||||
|
||||
```
|
||||
docker logs yapi
|
||||
```
|
||||
|
||||
信息如下:
|
||||
|
||||
```
|
||||
> yapi-vendor@1.9.2 install-server /yapi/vendors
|
||||
> node server/install.js
|
||||
|
||||
log: mongodb load success...
|
||||
初始化管理员账号成功,账号名:"master@simaek.com",密码:"ymfe.org"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Nginx 配置
|
||||
|
||||
在配置域名访问的时候将很有用。
|
||||
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name domain.com;
|
||||
keepalive_timeout 70;
|
||||
|
||||
location / {
|
||||
proxy_pass http://YOU_SERVER_IP:YAPI_PORT;
|
||||
}
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 支持
|
||||
|
||||
📧联系[@xueye](xueye404@qq.com)
|
||||
|
||||
✨欢迎 Star && Fork
|
12
build.sh
Executable file
12
build.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#==========================================================
|
||||
# System Required: Debian (32bit/64bit)
|
||||
# Version: v1.0.0
|
||||
# Author: xueye
|
||||
# Blog: https://www.simaek.com
|
||||
# Description: 构建yapi的Docker镜像
|
||||
# Usage: chmod +x build.sh && ./build.sh
|
||||
#==========================================================
|
||||
|
||||
docker build -f Dockerfile -t simaek/yapi:latest .
|
4
clean.sh
Executable file
4
clean.sh
Executable file
@ -0,0 +1,4 @@
|
||||
docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker stop
|
||||
docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker rm
|
||||
docker image ls | grep '<none>' | awk '{print $3}' | xargs docker rmi
|
||||
|
19
config.json
Normal file
19
config.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"port": "YAPI_PORT",
|
||||
"adminAccount": "ADMIN_EMAIL",
|
||||
"db": {
|
||||
"servername": "DB_HOST",
|
||||
"DATABASE": "DB_NAME",
|
||||
"port": "DB_PORT"
|
||||
},
|
||||
"mail": {
|
||||
"enable": "MAIL_ENABLE",
|
||||
"host": "MAIL_HOST",
|
||||
"port": "MAIL_PORT",
|
||||
"from": "MAIL_FROM",
|
||||
"auth": {
|
||||
"user": "MAIL_USER",
|
||||
"pass": "MAIL_PWD"
|
||||
}
|
||||
}
|
||||
}
|
42
docker-compose.yml
Normal file
42
docker-compose.yml
Normal file
@ -0,0 +1,42 @@
|
||||
version: '2.1'
|
||||
services:
|
||||
# mongo database for yapi
|
||||
mongo:
|
||||
image: mongo:2.8.0
|
||||
container_name: mongo
|
||||
# restart: always
|
||||
# volumes:
|
||||
# - ~/data/yapi/mongodb:/data/db #db dir
|
||||
networks:
|
||||
- backend
|
||||
# yapi server
|
||||
yapi:
|
||||
image: simaek/yapi:latest
|
||||
# build: ./
|
||||
container_name: yapi
|
||||
environment:
|
||||
- YAPI_PORT=3000
|
||||
- ADMIN_EMAIL=master@simaek.com
|
||||
- DB_HOST=mongo
|
||||
- DB_NAME=yapi
|
||||
- DB_PORT=27017
|
||||
- MAIL_ENABLE=false
|
||||
- MAIL_HOST=127.0.0.1
|
||||
- MAIL_PORT=465
|
||||
- MAIL_FROM=master@simaek.com
|
||||
- MAIL_USER=master
|
||||
- MAIL_PWD=master
|
||||
# restart: always
|
||||
ports:
|
||||
- 3000:3000
|
||||
# volumes:
|
||||
# - ~/data/yapi/log/yapi.log:/home/vendors/log # log dir
|
||||
depends_on:
|
||||
- mongo
|
||||
#entrypoint: "sh /yapi/start.sh"
|
||||
networks:
|
||||
- backend
|
||||
networks:
|
||||
backend:
|
||||
name: yapi
|
||||
driver: bridge
|
30
start.sh
Normal file
30
start.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
cd ${YAPI_HOME}/vendors
|
||||
|
||||
if [ ! -e "init.lock" ]
|
||||
then
|
||||
sed -i "s/YAPI_PORT/${YAPI_PORT}/g" config.json
|
||||
sed -i "s/ADMIN_EMAIL/${ADMIN_EMAIL}/g" config.json
|
||||
sed -i "s/DB_HOST/${DB_HOST}/g" config.json
|
||||
sed -i "s/DB_NAME/${DB_NAME}/g" config.json
|
||||
sed -i "s/DB_PORT/${DB_PORT}/g" config.json
|
||||
sed -i "s/\"MAIL_ENABLE\"/${MAIL_ENABLE}/g" config.json
|
||||
sed -i "s/MAIL_HOST/${MAIL_HOST}/g" config.json
|
||||
sed -i "s/MAIL_PORT/${MAIL_PORT}/g" config.json
|
||||
sed -i "s/MAIL_FROM/${MAIL_FROM}/g" config.json
|
||||
sed -i "s/MAIL_USER/${MAIL_USER}/g" config.json
|
||||
sed -i "s/MAIL_PWD/${MAIL_PWD}/g" config.json
|
||||
# yapi install -v ${YAPI_VERSION}
|
||||
npm run install-server
|
||||
touch init.lock
|
||||
fi
|
||||
|
||||
cd ${YAPI_HOME}/vendors
|
||||
|
||||
if [ $1 ]
|
||||
then
|
||||
node $i
|
||||
else
|
||||
node server/app.js
|
||||
fi
|
Loading…
Reference in New Issue
Block a user