YApi 部署記錄

YApi 是一個可本地部署的、打通先後端及QA的、可視化的接口管理平臺。node

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配置文件git

{
  "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": ""
    }
  }
}

注意github

  • 部分郵箱服務商要求from和auth的郵箱必須同樣
  • 部分郵箱的密碼是單獨申請的客戶端受權碼
  • DB::servername請填寫數據庫地址,製做鏡像安裝YApi的時候須要在數據庫初始化一些東西

Dockerfilemongodb

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文件夾。即:docker

volumes:
      - $PWD/mongodata:/data/db
相關文章
相關標籤/搜索