Skip to content

Commit

Permalink
add stat.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-Miao committed Apr 3, 2019
1 parent 4a92afe commit 7ef6bbb
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM node:11 as builder
FROM node:11-alpine as builder

RUN apt-get install -y git python make openssl tar gcc
COPY repositories /etc/apk/repositories
RUN apk update && apk add --no-cache git python make openssl tar gcc
ADD yapi.tgz /home/
RUN mkdir /api && mv /home/package /api/vendors
RUN cd /api/vendors && \
npm install --production --registry https://registry.npm.taobao.org

FROM node:11
FROM node:11-alpine

MAINTAINER ryan.miao
MAINTAINER ryan.miao@nf-3.com
ENV TZ="Asia/Shanghai" HOME="/"
WORKDIR ${HOME}

Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
echo "我们将从这里下载: http://registry.npm.taobao.org/yapi-vendor/download/yapi-vendor-\$1.tgz"


version=1.5.7
version=1.5.10

if [ -n "$1" ]; then
version=$1
Expand All @@ -19,5 +19,5 @@ wget -O yapi.tgz http://registry.npm.taobao.org/yapi-vendor/download/yapi-vendor

echo -e "\033[32m build new image \033[0m"

docker build -t yapi .
docker tag yapi yapi:$version
sudo docker build -t yapi .
sudo docker tag yapi yapi:$version
3 changes: 1 addition & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
#!/bin/sh
set -eo pipefail
shopt -s nullglob

if [ "$1" = '--initdb' ]; then
node /api/vendors/server/install.js
Expand Down
13 changes: 13 additions & 0 deletions init-mongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

db.createUser({ user: 'admin', pwd: 'admin123456', roles: [ { role: "root", db: "admin" } ] });

db.auth("admin", "admin123456");
db.createUser({
user: 'yapi',
pwd: 'yapi123456',
roles: [
{ role: "dbAdmin", db: "yapi" },
{ role: "readWrite", db: "yapi" }
]

});
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ YApi: https://github.com/YMFE/yapi/releases
制作本地的yapi docker镜像。


## 一键启动

```
git clone https://github.com/Ryan-Miao/docker-yapi.git
cd docker-yapi
bash build.sh 1.5.10
bash start.sh init-network
bash start.sh start-mongo
bash start.sh init-mongo
bash start.sh init-yapi
bash start.sh logs-yapi
```


## Run
## 具体步骤


### Step1: run mongodb
Expand Down Expand Up @@ -91,3 +102,4 @@ log: mongodb load success...

完整部署过程: https://www.cnblogs.com/woshimrf/p/docker-install-yapi.html


4 changes: 4 additions & 0 deletions repositories
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
https://mirrors.aliyun.com/alpine/v3.6/main/

https://mirrors.aliyun.com/alpine/v3.6/community/

115 changes: 115 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

function init-network(){
sudo docker network rm tools-net
sudo docker network create --subnet=172.18.0.0/16 tools-net
}

function mk_d(){
local dir_name=$1
if [ ! -d $dir_name ];then
sudo mkdir -p $dir_name
else
echo "dir ${dir_name} exist"
fi

}


function start-mongo(){
mk_d /data/opt/mongodb/data/configdb
mk_d /data/opt/mongodb/data/db/

sudo docker kill mongod
sudo docker rm mongod
sudo docker run \
--name mongod \
-p 27017:27017 \
-v /data/opt/mongodb/data/configdb:/data/configdb/ \
-v /data/opt/mongodb/data/db/:/data/db/ \
--net tools-net --ip 172.18.0.2 \
-d mongo:4 --auth
}

function init-mongo(){
echo "init mongodb account admin and yapi"
sudo docker cp init-mongo.js mongod:/data
sudo docker exec -it mongod mongo admin /data/init-mongo.js
echo "inti mongodb done"
}

function start-yapi(){
echo "start yapi server"
sudo docker run -d -p 3001:3001 --name yapi --net tools-net --ip 172.18.0.3 yapi
echo "end yapi server"
}

function init-yapi(){
echo "init yapi db and start yapi server"
sudo docker run -d -p 3001:3001 --name yapi --net tools-net --ip 172.18.0.3 yapi --initdb
echo "init yapi done"
}

function logs-yapi(){
sudo docker logs --tail 10 yapi
}

function remove(){
sudo rm -r /data/opt/mongodb/
}

function stop(){
sudo docker kill mongod yapi && sudo docker rm yapi mongod
}


function print_usage(){
echo " Usage: bash start.sh <param>"
echo " 可用参数: "
echo " init-network: 初始化网络,第一次运行的时候执行,多次执行只会删除重建 "
echo " start-mongo: 创建数据目录/data/opt/mongodb/data/db/,并启动MongoDB, 前提是init-network完成"
echo " init-mongo: 初始化mongodb的用户,创建yapi用户和db,前提是mongodb已安装,即start-mongo完成"
echo " start-yapi: 单纯启动yapi"
echo " init-yapi: 初始化yapi的db,并启动。前提是MongoDB可以连接,即init-mongo完成"
echo " logs-yapi: 查看yapi容器的日志"
echo " stop: 停止mongodb和yapi,但保留mongodb文件/data/opt/mongodb/data/db/"
echo " remove: 删除db文件"
}


case $1 in
init-network)
init-network
;;
start-mongo)
start-mongo
;;
init-mongo)
init-mongo
;;
start-yapi)
start-yapi
;;
init-yapi)
init-yapi
;;
logs-yapi)
logs-yapi
;;
init)
init-network
start-mongo
init-mongo
init-yapi
logs-yapi
;;
remove)
remove
;;
stop)
stop
;;
*)
print_usage
;;
esac

0 comments on commit 7ef6bbb

Please sign in to comment.