YApi 部署记录

时间:2023-11-22 22:02:08

YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台。

Step1:准备Mongo数据库

services:

  mongo:
image: mongo
restart: always
ports:
- 27017:27017
volumes:
- $PWD/mongodata:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: MONGODB的用户名
MONGO_INITDB_ROOT_PASSWORD: MONGODB的密码 mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: MONGODB的用户名
ME_CONFIG_MONGODB_ADMINPASSWORD: MONGODB的密码
ME_CONFIG_BASICAUTH_USERNAME: MONGO-EXPRESS的密码
ME_CONFIG_BASICAUTH_PASSWORD: MONGO-EXPRESS的用户名

Step2:准备YApi

准备YApi配置文件

{
"port": "3000",
"closeRegister":false,
"versionNotify": true,
"adminAccount": "admin@admin.com",
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "db-user",
"pass": "db-password",
"authSource": "admin"
},
"mail": {
"enable": true,
"host": "smtp.exmail.qq.com",
"port": 465,
"from": "tacey_wong@xxx.com",
"auth": {
"user": "tacey_wong@xxx.com",
"pass": ""
}
}
}

注意

  • 部分邮箱服务商要求from和auth的邮箱必须一样
  • 部分邮箱的密码是单独申请的客户端授权码
  • DB::servername请填写数据库地址,制作镜像安装YApi的时候需要在数据库初始化一些东西

Dockerfile

FROM node
MAINTAINER Tacey Wong
ENV REFRESHED_AT 2019.03.08 RUN mkdir yapi WORKDIR /yapi RUN git clone --depth=1 https://github.com/YMFE/yapi.git vendors
COPY yapi_config.json config.json
WORKDIR /yapi/vendors
RUN pwd
RUN cat ../config.json
RUN npm install --production --registry https://registry.npm.taobao.org && npm run install-server EXPOSE 3000 CMD ["node", "server/app.js"]

Step3:备份API数据

最简单的是直接备份mongodb的data文件夹。即:

volumes:
- $PWD/mongodata:/data/db