├── .gitignore ├── Dockerfile ├── README.md ├── images └── webhook.png └── scripts ├── deploy.sh ├── startup.sh └── webhook.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos 2 | 3 | RUN yum install -y epel-release && yum update -y && yum install -y node npm make nginx git 4 | RUN npm install -g aglio drakov 5 | 6 | COPY scripts/startup.sh /usr/local/bin/ 7 | COPY scripts/deploy.sh /usr/local/bin/ 8 | COPY scripts/webhook.js /usr/local/bin/ 9 | 10 | RUN chmod -R 755 /usr/local/bin/* 11 | 12 | CMD /usr/local/bin/deploy.sh && /usr/local/bin/startup.sh 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Api Blueprint Docker 2 | [![Docker Stars](https://img.shields.io/docker/stars/dozer47528/api-blueprint-docker.svg)](https://hub.docker.com/r/dozer47528/api-blueprint-docker/) 3 | [![Docker Pulls](https://img.shields.io/docker/pulls/dozer47528/api-blueprint-docker.svg)](https://hub.docker.com/r/dozer47528/api-blueprint-docker/) 4 | [![Image Size](https://img.shields.io/imagelayers/image-size/dozer47528/api-blueprint-docker/latest.svg)](https://imagelayers.io/?images=dozer47528/api-blueprint-docker:latest) 5 | [![Image Layers](https://img.shields.io/imagelayers/layers/dozer47528/api-blueprint-docker/latest.svg)](https://imagelayers.io/?images=dozer47528/api-blueprint-docker:latest) 6 | 7 | ## How to use? 8 | `docker run --name test -e "repository=https://github.com/dozer47528/api-blueprint-test.git" -p 80:80 -p 8080:8080 -p 3000:3000 -d dozer47528/api-blueprint-docker` 9 | 10 | Replace the `https://github.com/dozer47528/api-blueprint-test.git` with your own repository. 11 | 12 |   13 | 14 | #### How change `aglio` parameter 15 | Add this parameter like this:`-e "aglio=--theme-template triple"` 16 | 17 | Full command like this: 18 | 19 | `docker run --name test -e "aglio=--theme-template triple" -e "repository=https://github.com/dozer47528/api-blueprint-test.git" -p 80:80 -p 8080:8080 -p 3000:3000 -d dozer47528/api-blueprint-docker` 20 | 21 | aglio document: [https://github.com/danielgtaylor/aglio#executable](https://github.com/danielgtaylor/aglio#executable) 22 | 23 |   24 | 25 | #### How to support private repositiry? 26 | Create ssh keys in your host and add parameter like this:`-v ~/.ssh:/root/.ssh` 27 | 28 | Full command like this: 29 | 30 | `docker run --name test -v ~/.ssh:/root/.ssh -e "repository=https://github.com/dozer47528/api-blueprint-test.git" -p 80:80 -p 8080:8080 -p 3000:3000 -d dozer47528/api-blueprint-docker` 31 | 32 |   33 | 34 | #### Ports explain: 35 | 36 | * `80` : document server 37 | * `3000` : mock server 38 | * `8080` : webhook server 39 | 40 |   41 | 42 | #### How does it work? 43 | 44 | When you first run or call the webhook: 45 | 46 | 1. use `aglio` convert all file like `*.apib` to `*.html`. 47 | 2. copy all the files (include origin html file in the repository) to `nginx` root. 48 | 3. restart `nginx` (auto reload). 49 | 4. restart `drakov` (by script). 50 | 51 |   52 | 53 | ## How to config auto deploy 54 | The server will auto reload every 5 minutes. 55 | 56 | And you can add webhook in your repository settings. 57 | 58 | ![settings](https://raw.githubusercontent.com/dozer47528/api-blueprint-docker/master/images/webhook.png) 59 | -------------------------------------------------------------------------------- /images/webhook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dozer47528/api-blueprint-docker/3c5c46281a9fa973eb905656a3755367f72ce18f/images/webhook.png -------------------------------------------------------------------------------- /scripts/deploy.sh: -------------------------------------------------------------------------------- 1 | if [ -d /opt/api-blueprint ] 2 | then 3 | cd /opt/api-blueprint 4 | git checkout -f 5 | git clean -f 6 | git pull 7 | else 8 | git clone $repository /opt/api-blueprint 9 | cd /opt/api-blueprint 10 | fi 11 | 12 | find . -name "*.apib" | sed 's/.apib//' | xargs -i -t aglio -i {}.apib `echo $aglio` -o {}.html 13 | rm -rf /usr/share/nginx/html/* 14 | cp -R * /usr/share/nginx/html/ 15 | -------------------------------------------------------------------------------- /scripts/startup.sh: -------------------------------------------------------------------------------- 1 | nginx 2 | drakov -f "/opt/api-blueprint/*.apib" --public & 3 | node /usr/local/bin/webhook.js 4 | -------------------------------------------------------------------------------- /scripts/webhook.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var exec = require('child_process').exec; 3 | 4 | var cmdStr = 'bash -c /usr/local/bin/deploy.sh'; 5 | 6 | setInterval(function() { 7 | console.log("Start auto reload.") 8 | exec(cmdStr, function(err, stdout, stderr) { 9 | if (err) { 10 | console.error(err); 11 | } else { 12 | console.log("Update success!"); 13 | console.log(stdout); 14 | } 15 | }); 16 | }, 5 * 60 * 1000); 17 | 18 | http.createServer(function(req, res) { 19 | console.log("Start webhook reload.") 20 | exec(cmdStr, function(err, stdout, stderr) { 21 | if (err) { 22 | console.error(err); 23 | } else { 24 | console.log("Update success!"); 25 | console.log(stdout); 26 | } 27 | }); 28 | res.writeHead(200, { 29 | 'Content-Type': 'text/plain' 30 | }); 31 | res.end(""); 32 | 33 | }).listen(8080); 34 | --------------------------------------------------------------------------------