Harbor配置Swagger远程REST API

通过Swagger查看和测试Harbor的远程接口

Harbor 源码地址:https://github.com/vmware/harbor

一、下载 Swagger 运行脚本和文件

从 Harbor 源码仓库中(docs)下载两个文件:prepare-swagger.shswagger.yaml

文档路径:https://github.com/vmware/harbor/tree/master/docs

Harbor配置Swagger远程REST API_第1张图片

二、修改 prepare-swagger.sh 脚本
#!/bin/bash
# 设置成和Harbor仓库相同的访问方式
SCHEME=https
# Harbor仓库所在的地址
SERVER_IP=192.168.80.42
set -e
echo "Doing some clean up..."
rm -f *.tar.gz
echo "Downloading Swagger UI release package..."
wget https://github.com/swagger-api/swagger-ui/archive/v2.1.4.tar.gz -O swagger.tar.gz
echo "Untarring Swagger UI package to the static file path..."
mkdir -p ../src/ui/static/vendors
tar -C ../src/ui/static/vendors -zxf swagger.tar.gz swagger-ui-2.1.4/dist
echo "Executing some processes..."
sed -i.bak 's/http:\/\/petstore\.swagger\.io\/v2\/swagger\.json/'$SCHEME':\/\/'$SERVER_IP'\/static\/resources\/yaml\/swagger\.yaml/g' \
../src/ui/static/vendors/swagger-ui-2.1.4/dist/index.html
sed -i.bak '/jsonEditor: false,/a\        validatorUrl: null,' ../src/ui/static/vendors/swagger-ui-2.1.4/dist/index.html
mkdir -p ../src/ui/static/resources/yaml
cp swagger.yaml ../src/ui/static/resources/yaml
sed -i.bak 's/host: localhost/host: '$SERVER_IP'/g' ../src/ui/static/resources/yaml/swagger.yaml
sed -i.bak 's/  \- http$/  \- '$SCHEME'/g' ../src/ui/static/resources/yaml/swagger.yaml
echo "Finish preparation for the Swagger UI."

修改好后运行脚本,会把包解压到Harbor的项目下static文件夹中

# 运行脚本
./prepare-swagger.sh

三、配置Harbor仓库启动编排的yml文件

docker-compose.yml 文件 ui.volumes 段中的添加两行内容

- ../src/ui/static/vendors/swagger-ui-2.1.4/dist:/harbor/static/vendors/swagger
- ../src/ui/static/resources/yaml/swagger.yaml:/harbor/static/resources/yaml/swagger.yaml

Harbor配置Swagger远程REST API_第2张图片

修改好后重启启动Harbor仓库,我们可以访问Swagger的页面:https://192.168.80.42/static/vendors/swagger/index.html

Harbor配置Swagger远程REST API_第3张图片

你可能感兴趣的:(Docker,API)