├── .dockerignore ├── .gitignore ├── .vimrc ├── Dockerfile ├── README.md ├── config.json └── entrypoint.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 | 3 | " 显示相关 4 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 5 | "set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 6 | "winpos 5 5 " 设定窗口位置 7 | "set lines=40 columns=155 " 设定窗口大小 8 | "set nu " 显示行号 9 | set go= " 不要图形按钮 10 | 11 | "color asmanian2 " 设置背景主题 12 | 13 | set guifont=Courier_New:h10:cANSI " 设置字体 14 | "syntax on " 语法高亮 15 | autocmd InsertLeave * se nocul " 用浅色高亮当前行 16 | 17 | autocmd InsertEnter * se cul " 用浅色高亮当前行 18 | "set ruler " 显示标尺 19 | set showcmd " 输入的命令显示出来,看的清楚些 20 | 21 | "set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 22 | 23 | "set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) 24 | 25 | "set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 26 | 27 | set novisualbell " 不要闪烁(不明白) 28 | set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 29 | 30 | set laststatus=1 " 启动显示状态行(1),总是显示状态行(2) 31 | set foldenable " 允许折叠 32 | 33 | set foldmethod=manual " 手动折叠 34 | "set background=dark "背景使用黑色 35 | set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 36 | 37 | " 显示中文帮助 38 | if version >= 603 39 | set helplang=cn 40 | set encoding=utf-8 41 | endif 42 | " 设置配色方案 43 | 44 | "colorscheme murphy 45 | "字体 46 | 47 | "if (has("gui_running")) 48 | " set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 49 | 50 | "endif 51 | 52 | set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 53 | set termencoding=utf-8 54 | set encoding=utf-8 55 | set fileencodings=ucs-bom,utf-8,cp936 56 | set fileencoding=utf-8 57 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 58 | 59 | """""新文件标题"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 60 | "新建.c,.h,.sh,.java文件,自动插入文件头 61 | 62 | autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" 63 | 64 | ""定义函数SetTitle,自动插入文件头 65 | 66 | func SetTitle() 67 | 68 | "如果文件类型为.sh文件 69 | if &filetype == 'sh' 70 | call setline(1,"\#########################################################################") 71 | 72 | call append(line("."), "\# File Name: ".expand("%")) 73 | 74 | call append(line(".")+1, "\# Author: ma6174") 75 | 76 | call append(line(".")+2, "\# mail: ma6174@163.com") 77 | 78 | call append(line(".")+3, "\# Created Time: ".strftime("%c")) 79 | 80 | call append(line(".")+4, "\#########################################################################") 81 | 82 | call append(line(".")+5, "\#!/bin/bash") 83 | 84 | call append(line(".")+6, "") 85 | 86 | else 87 | 88 | call setline(1, "/*************************************************************************") 89 | 90 | call append(line("."), " > File Name: ".expand("%")) 91 | 92 | call append(line(".")+1, " > Author: ma6174") 93 | 94 | call append(line(".")+2, " > Mail: ma6174@163.com ") 95 | 96 | call append(line(".")+3, " > Created Time: ".strftime("%c")) 97 | 98 | call append(line(".")+4, " ************************************************************************/") 99 | 100 | call append(line(".")+5, "") 101 | 102 | endif 103 | 104 | if &filetype == 'cpp' 105 | 106 | call append(line(".")+6, "#include") 107 | 108 | call append(line(".")+7, "using namespace std;") 109 | 110 | call append(line(".")+8, "") 111 | 112 | endif 113 | 114 | if &filetype == 'c' 115 | 116 | call append(line(".")+6, "#include") 117 | 118 | call append(line(".")+7, "") 119 | 120 | endif 121 | 122 | "新建文件后,自动定位到文件末尾 123 | autocmd BufNewFile * normal G 124 | endfunc 125 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 126 | "键盘命令 127 | 128 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 129 | 130 | 131 | 132 | nmap w :w! 133 | 134 | nmap f :find 135 | 136 | 137 | 138 | " 映射全选+复制 ctrl+a 139 | map ggVGY 140 | map! ggVGY 141 | map gg=G 142 | " 选中状态下 Ctrl+c 复制 143 | 144 | vmap "+y 145 | "去空行 146 | 147 | nnoremap :g/^\s*$/d 148 | 149 | "比较文件 150 | nnoremap :vert diffsplit 151 | "新建标签 152 | 153 | map :tabnew 154 | 155 | "列出当前目录文件 156 | map :tabnew . 157 | "打开树状文件目录 158 | 159 | map \be 160 | 161 | "C,C++ 按F5编译运行 162 | map :call CompileRunGcc() 163 | func! CompileRunGcc() 164 | exec "w" 165 | if &filetype == 'c' 166 | exec "!g++ % -o %<" 167 | exec "! ./%<" 168 | elseif &filetype == 'cpp' 169 | exec "!g++ % -o %<" 170 | exec "! ./%<" 171 | elseif &filetype == 'java' 172 | exec "!javac %" 173 | exec "!java %<" 174 | elseif &filetype == 'sh' 175 | :!./% 176 | endif 177 | endfunc 178 | "C,C++的调试 179 | 180 | map :call Rungdb() 181 | 182 | func! Rungdb() 183 | 184 | exec "w" 185 | 186 | exec "!g++ % -g -o %<" 187 | 188 | exec "!gdb ./%<" 189 | 190 | endfunc 191 | 192 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 193 | 194 | ""实用设置 195 | 196 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 197 | " 设置当文件被改动时自动载入 198 | 199 | set autoread 200 | 201 | " quickfix模式 202 | autocmd FileType c,cpp map :w:make 203 | "代码补全 204 | 205 | set completeopt=preview,menu 206 | 207 | "允许插件 208 | filetype plugin on 209 | "共享剪贴板 210 | 211 | set clipboard+=unnamed 212 | 213 | "从不备份 214 | set nobackup 215 | "make 运行 216 | 217 | :set makeprg=g++\ -Wall\ \ % 218 | 219 | "自动保存 220 | set autowrite 221 | set ruler " 打开状态栏标尺 222 | 223 | set cursorline " 突出显示当前行 224 | set magic " 设置魔术 225 | 226 | set guioptions-=T " 隐藏工具栏 227 | set guioptions-=m " 隐藏菜单栏 228 | 229 | "set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ 230 | " 设置在状态行显示的信息 231 | 232 | set foldcolumn=0 233 | 234 | set foldmethod=indent 235 | 236 | set foldlevel=3 237 | 238 | set foldenable " 开始折叠 239 | " 不要使用vi的键盘模式,而是vim自己的 240 | 241 | set nocompatible 242 | 243 | " 语法高亮 244 | set syntax=on 245 | " 去掉输入错误的提示声音 246 | 247 | set noeb 248 | 249 | " 在处理未保存或只读文件的时候,弹出确认 250 | set confirm 251 | " 自动缩进 252 | 253 | set autoindent 254 | 255 | set cindent 256 | 257 | " Tab键的宽度 258 | set tabstop=4 259 | " 统一缩进为4 260 | 261 | set softtabstop=4 262 | 263 | set shiftwidth=4 264 | 265 | " 不要用空格代替制表符 266 | set noexpandtab 267 | " 在行和段开始处使用制表符 268 | 269 | set smarttab 270 | 271 | " 显示行号 272 | set number 273 | " 历史记录数 274 | 275 | set history=1000 276 | 277 | "禁止生成临时文件 278 | set nobackup 279 | set noswapfile 280 | "搜索忽略大小写 281 | 282 | set ignorecase 283 | 284 | "搜索逐字符高亮 285 | set hlsearch 286 | set incsearch 287 | "行内替换 288 | 289 | set gdefault 290 | 291 | "编码设置 292 | set enc=utf-8 293 | set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 294 | "语言设置 295 | 296 | set langmenu=zh_CN.UTF-8 297 | 298 | set helplang=cn 299 | 300 | " 我的状态行显示的内容(包括文件类型和解码) 301 | "set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} 302 | "set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] 303 | 304 | " 总是显示状态行 305 | set laststatus=2 306 | " 命令行(在状态行下)的高度,默认为1,这里是2 307 | 308 | set cmdheight=2 309 | 310 | " 侦测文件类型 311 | filetype on 312 | " 载入文件类型插件 313 | 314 | filetype plugin on 315 | 316 | " 为特定文件类型载入相关缩进文件 317 | filetype indent on 318 | " 保存全局变量 319 | 320 | set viminfo+=! 321 | 322 | " 带有如下符号的单词不要被换行分割 323 | set iskeyword+=_,$,@,%,#,- 324 | " 字符间插入的像素行数目 325 | 326 | set linespace=0 327 | 328 | " 增强模式中的命令行自动完成操作 329 | set wildmenu 330 | " 使回格键(backspace)正常处理indent, eol, start等 331 | 332 | set backspace=2 333 | 334 | " 允许backspace和光标键跨越行边界 335 | set whichwrap+=<,>,h,l 336 | " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) 337 | 338 | set mouse=a 339 | 340 | set selection=exclusive 341 | 342 | set selectmode=mouse,key 343 | 344 | " 通过使用: commands命令,告诉我们文件的哪一行被改变过 345 | set report=0 346 | " 在被分割的窗口间显示空白,便于阅读 347 | 348 | set fillchars=vert:\ ,stl:\ ,stlnc:\ 349 | 350 | " 高亮显示匹配的括号 351 | set showmatch 352 | " 匹配括号高亮的时间(单位是十分之一秒) 353 | 354 | set matchtime=1 355 | 356 | " 光标移动到buffer的顶部和底部时保持3行距离 357 | set scrolloff=3 358 | " 为C程序提供自动缩进 359 | 360 | set smartindent 361 | 362 | " 高亮显示普通txt文件(需要txt.vim脚本) 363 | au BufRead,BufNewFile * setfiletype txt 364 | "自动补全 365 | 366 | :inoremap ( ()i 367 | 368 | :inoremap ) =ClosePair(')') 369 | 370 | :inoremap { {}O 371 | 372 | :inoremap } =ClosePair('}') 373 | 374 | :inoremap [ []i 375 | 376 | :inoremap ] =ClosePair(']') 377 | 378 | :inoremap " ""i 379 | :inoremap ' ''i 380 | function! ClosePair(char) 381 | if getline('.')[col('.') - 1] == a:char 382 | return "\" 383 | else 384 | return a:char 385 | endif 386 | endfunction 387 | filetype plugin indent on 388 | "打开文件类型检测, 加了这句才可以用智能补全 389 | 390 | set completeopt=longest,menu 391 | 392 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 393 | " CTags的设定 394 | 395 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 396 | let Tlist_Sort_Type = "name" " 按照名称排序 397 | 398 | let Tlist_Use_Right_Window = 1 " 在右侧显示窗口 399 | let Tlist_Compart_Format = 1 " 压缩方式 400 | 401 | let Tlist_Exist_OnlyWindow = 1 " 如果只有一个buffer,kill窗口也kill掉buffer 402 | let Tlist_File_Fold_Auto_Close = 0 " 不要关闭其他文件的tags 403 | 404 | let Tlist_Enable_Fold_Column = 0 " 不要显示折叠树 405 | autocmd FileType java set tags+=D:\tools\java\tags 406 | "autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags 407 | 408 | "let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的 409 | 410 | "设置tags 411 | set tags=tags 412 | "set autochdir 413 | 414 | 415 | 416 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 417 | 418 | "其他东东 419 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 420 | 421 | "默认打开Taglist 422 | let Tlist_Auto_Open=1 423 | """""""""""""""""""""""""""""" 424 | " Tag list (ctags) 425 | 426 | """""""""""""""""""""""""""""""" 427 | 428 | let Tlist_Ctags_Cmd = '/usr/bin/ctags' 429 | 430 | let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的 431 | let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim 432 | 433 | let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口 434 | " minibufexpl插件的一般设置 435 | 436 | let g:miniBufExplMapWindowNavVim = 1 437 | 438 | let g:miniBufExplMapWindowNavArrows = 1 439 | 440 | let g:miniBufExplMapCTabSwitchBufs = 1 441 | let g:miniBufExplModSelTarget = 1 442 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 基于 alpine镜像构建 2 | FROM alpine:latest 3 | # 镜像维护者的信息 4 | LABEL MAINTAINER = 'crper@outlook.com(https://github.com/crper)' 5 | # 基础环境构建 6 | # - 更新源 7 | # - 安装基础环境包 8 | # - 不用更改默认shell了,只要进入的镜像的时候指定shell即可 9 | # - 最后是删除一些缓存 10 | # - 克隆项目 11 | # - 采用自动化构建不考虑国内npm源了 , 可以降低初始化失败的概率 12 | # !! yapi 官方的内网部署教程: https://yapi.ymfe.org/devops/index.html 13 | RUN apk update \ 14 | && apk add --no-cache git nodejs npm bash vim python python-dev gcc libcurl make\ 15 | && rm -rf /var/cache/apk/* \ 16 | && mkdir /yapi && cd /yapi && git clone https://github.com/YMFE/yapi.git vendors \ 17 | && npm i -g node-gyp yapi-cli npm@latest \ 18 | && cd /yapi/vendors && npm i --production; 19 | # 工作目录 20 | WORKDIR /yapi/vendors 21 | # 配置yapi的配置文件 22 | COPY config.json /yapi/ 23 | # 复制执行脚本到容器的执行目录 24 | COPY entrypoint.sh /usr/local/bin/ 25 | # 写好的vim配置文件复制进去 26 | COPY .vimrc /root/ 27 | # 向外暴露的端口 28 | EXPOSE 3000 29 | 30 | # 配置入口为bash shell 31 | ENTRYPOINT ["entrypoint.sh"] 32 | 33 | 34 | # `vim` : 编辑神器 35 | # `tar` : 解压缩 36 | # `make`: 编译依赖的 37 | # `gcc`: GNU编译器套装 38 | # `python`: `python python-dev py-pip`这三个包包括了基本开发环境 39 | # `curl` 可以测试连接也能下载内容的命令行工具 40 | # `git` : 不用说了 41 | # `nodejs` : node 42 | # `nodejs-current-npm` : `alpine`Linux版本需要依赖这个版本,才能让`npm`识别到 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yapi Docker 2 | 3 | > YApi 是一个可本地部署的、打通前后端及QA的、可视化的接口管理平台 [yapi.ymfe.org](https://github.com/YMFE/yapi) 4 | 5 | 6 | --- 7 | 8 | # 提供的内容 9 | 10 | **第一次初始化默认拉取的最新的版本,所以不用指定版本,若是yapi代码不严谨,连新版本初始化都会报错则无解!** 11 | 12 | - `yapi`的部署 13 | - `yapi`的升级 14 | 15 | 16 | --- 17 | 18 | # 创建volume 19 | 20 | - `docker volume create yapi-mongo` 21 | 22 | 创建一个储存卷,用来专门存放`yapi`使用的`mongodb`的数据 23 | 24 | 为什么要独立出来,这是为了以后升级的着想,数据库保留,只要启动的时候关联一下就行了 25 | 26 | 27 | 28 | --- 29 | 30 | # 启动mongodb 31 | 32 | - `docker run -d --name yapi-mongo -v yapi-mongo:/data/db mongo` 33 | 34 | 35 | 为什么要先启动`mongodb`,因为`yapi`初始化的时候依赖`mongodb`,比如创建用户表这些 36 | 37 | 这条命令是什么意思呢? 38 | 39 | ```bash 40 | 41 | -d : 是启动的时候输出容器的id 42 | --name : 是给容器设置一个名字,方便我们控制,比如start,stop 43 | -v : 指定关联的卷 => 本地卷:容器内储存位置 , 就是映射数据保存的地方 44 | 45 | ``` 46 | 47 | 若是需要外部管理这个数据库的话,最好也暴露出来端口, `mongodb`容器默认也暴露了27017端口 48 | 49 | - `docker run -d --name yapi-mongo -v yapi-mongo:/data/db -p 27017:27017 mongo` 50 | 51 | --- 52 | 53 | # 初始化Yapi和启动Yapi 54 | 55 | - `docker run -d --name yapi -p 3000:3000 --link yapi-mongo crper/yapi` 56 | 57 | 58 | 这里比上面多的一个参数就是`--link`,用来使连个容器通讯的,过时命令,官方已经不推荐 59 | 60 | **过程均可用**`docker logs details 容器ID或者name`来看到内部的情况 61 | 62 | 就是`shell`执行过程,比如这个项目就可以在初始化的时候,看到初始化的账号密码(成功) 63 | 64 | 65 | 不管是`mongo`还是`crper/yapi` ,当你请求一个容器不存在的时候, 66 | 67 | 会尝试往`dockhub`上面找,默认拉取镜像`latest`版本,找不到才会报错 68 | 69 | 以下就是基本的初始化信息 70 | 71 | ```bash 72 | 访问链接: 127.0.0.1:3000 73 | 默认的账户名: config.json => adminAccount 这个字段的值 74 | 密码: ymfe.org 75 | ``` 76 | 77 | 78 | --- 79 | 80 | # 升级yapi 81 | 82 | ## 手动升级 83 | 84 | 因为不涉及到容器处理..只是单纯的文件替换,官方也提供了方案,那个`cli`已经默认集成到容器里面 85 | 86 | ```javascript 87 | // https://yapi.ymfe.org/devops/index.html 88 | cd {项目目录} 89 | yapi ls //查看版本号列表 90 | yapi update //升级到最新版本 91 | yapi update -v v1.1.0 //升级到指定版本 92 | ``` 93 | 94 | 升级完毕重启`node`程序亦或者重启容器即可!! 95 | 96 | 97 | 98 | ---- 99 | 100 | # 错误 101 | 102 | 在初始化的时候,执行 103 | 104 | `docker logs --details 容器ID` 105 | 106 | 查看内部终端的执行过程,npm的一些源也不一定靠谱, 107 | 108 | 若是提示`npm`安装报错了,就需要进去换其他源了 109 | 110 | 先启动`crper/yapi`镜像,然后跟着教程走 111 | 112 | 113 | 114 | ```javascript 115 | // npm config set registry [url] 116 | // npm ---- https://registry.npmjs.org/ 117 | // cnpm --- http://r.cnpmjs.org/ 118 | // taobao - http://registry.npm.taobao.org/ 119 | // eu ----- http://registry.npmjs.eu/ 120 | // au ----- http://registry.npmjs.org.au/ 121 | // sl ----- http://npm.strongloop.com/ 122 | // nj ----- https://registry.nodejitsu.com/ 123 | 124 | 125 | // 进入到vendors目录 126 | // 若是有node_modules目录, 127 | // 我们都应该先干掉node_modules 128 | // 这样重新安装依赖才会比较干净 129 | 130 | // 进到vendors目录, 比如设置回官方源 131 | npm config set registry https://registry.npmjs.org/; 132 | 133 | // 安装全局升级工具和依赖编译的npm模块 134 | npm i -g node-gyp yapi-cli \ 135 | npm i --production; 136 | 137 | // 初始化 yapi 138 | node server/install.js 139 | 140 | ``` 141 | 142 | 依赖安装完成就可以再重新初始化,然后重启容器即可 143 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": "3000", 3 | "adminAccount": "crper@outlook.com", 4 | "versionNotify": true, 5 | "db": { 6 | "servername": "yapi-mongo", 7 | "DATABASE": "yapi", 8 | "port": 27017 9 | }, 10 | "mail": { 11 | "enable": false, 12 | "host": "smtp.163.com", 13 | "port": 465, 14 | "from": "***@163.com", 15 | "auth": { 16 | "user": "***@163.com", 17 | "pass": "*****" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # yapi初始化后会有一个init.lock文件 4 | lockPath="/yapi/init.lock" 5 | 6 | 7 | # 进入yapi项目 8 | cd /yapi/vendors 9 | 10 | 11 | # 如果初始化文件文件存在,则直接运行,否则初始化 12 | if [ ! -f "$lockPath" ] 13 | then 14 | # 启动Yapi初始化 15 | node server/install.js 16 | # 若是初始化成功的情况下直接运行yapi 17 | node server/app.js 18 | else 19 | # 运行yapi管理系统 20 | node server/app.js 21 | fi --------------------------------------------------------------------------------