View and test Harbor REST API via Swagger
官方原文参考
###目录:harbor/docs/configure_swagger.md
####1>下载prepare-swagger.sh和swagger.yaml 文件到本地文件夹
我自己文件目录:/opt/harbor-swagger-ui
[root@localhost harbor-swagger-ui]# wget https://raw.githubusercontent.com/vmware/harbor/master/docs/prepare-swagger.sh https://raw.githubusercontent.com/vmware/harbor/master/docs/swagger.yaml
--2018-07-19 15:35:07-- https://raw.githubusercontent.com/vmware/harbor/master/docs/prepare-swagger.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.72.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.72.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1080 (1.1K) [text/plain]
Saving to: ‘prepare-swagger.sh’
100%[====================================================================================================>] 1,080 --.-K/s in 0s
2018-07-19 15:35:57 (111 MB/s) - ‘prepare-swagger.sh’ saved [1080/1080]
--2018-07-19 15:35:57-- https://raw.githubusercontent.com/vmware/harbor/master/docs/swagger.yaml
Reusing existing connection to raw.githubusercontent.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 112066 (109K) [text/plain]
Saving to: ‘swagger.yaml’
100%[====================================================================================================>] 112,066 26.3KB/s in 4.2s
2018-07-19 15:36:02 (26.3 KB/s) - ‘swagger.yaml’ saved [112066/112066]
FINISHED --2018-07-19 15:36:02--
Total wall clock time: 54s
Downloaded: 2 files, 110K in 4.2s (26.6 KB/s)
####2>编辑文件prepare-swagger.sh.
vi prepare-swagger.sh
编辑协议用http或者https【根据安装harbor来定】,自己harbor服务IP地址
SCHEME=<HARBOR_SERVER_SCHEME>
SERVER_IP=<HARBOR_SERVER_DOMAIN>
另外:如果端口不是默认的80的话,这里也要配置一致内容,不然会提示不成功
Change the file mode
[root@localhost harbor-swagger-ui]# chmod +x prepare-swagger.sh
在当前目前下运行shell script,下载文件和创建文件等,可仔细看脚本便知
[root@localhost harbor-swagger-ui]# ./prepare-swagger.sh
Doing some clean up...
Downloading Swagger UI release package...
--2018-07-19 15:49:34-- https://github.com/swagger-api/swagger-ui/archive/v2.1.4.tar.gz
Resolving github.com (github.com)... 13.250.177.223, 52.74.223.119, 13.229.188.59
Connecting to github.com (github.com)|13.250.177.223|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/swagger-api/swagger-ui/tar.gz/v2.1.4 [following]
--2018-07-19 15:49:42-- https://codeload.github.com/swagger-api/swagger-ui/tar.gz/v2.1.4
Resolving codeload.github.com (codeload.github.com)... 13.229.189.0, 13.250.162.133, 54.251.140.56
Connecting to codeload.github.com (codeload.github.com)|13.229.189.0|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1036338 (1012K) [application/x-gzip]
Saving to: ‘swagger.tar.gz’
100%[====================================================================================================>] 1,036,338 41.1KB/s in 13s
2018-07-19 15:49:57 (80.2 KB/s) - ‘swagger.tar.gz’ saved [1036338/1036338]
Untarring Swagger UI package to the static file path...
Executing some processes...
Finish preparation for the Swagger UI.
####3>编辑文件docker-compose.yml.
可以全局查找自己的文件:find | grep docker-compose.yml
[root@localhost /]# find | grep docker-compose.yml
./var/www/html/resource/harbor/docker-compose.yml
./var/www/html/resource/harbor/ha/docker-compose.yml
[root@localhost /]# cd ./var/www/html/resource/harbor/
[root@localhost harbor]# ls
common docker-compose.notary.yml ha harbor.v1.5.1.tar.gz LICENSE prepare
docker-compose.clair.yml docker-compose.yml harbor.cfg install.sh NOTICE
[root@localhost harbor]# vi docker-compose.yml
添加的内容如下:一定要注意路径问题,检查下是否存在##
...
ui:
...
volumes:
- ./common/config/ui/app.conf:/etc/ui/app.conf:z
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z
- /data/secretkey:/etc/ui/key:z
- /data/ca_download/:/etc/ui/ca/:z
## add two lines as below 一定要注意路径问题,检查下是否存在##
- /opt/src/ui/static/vendors/swagger-ui-2.1.4/dist:/harbor/static/vendors/swagger
- /opt/src/ui/static/resources/yaml/swagger.yaml:/harbor/static/resources/yaml/swagger.yaml
...
####4>Recreate Harbor containers
[root@localhost harbor]# docker-compose down -v && docker-compose up -d
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-ui ... done
Stopping harbor-adminserver ... done
Stopping harbor-db ... done
Stopping redis ... done
Stopping registry ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-ui ... done
Removing harbor-adminserver ... done
Removing harbor-db ... done
Removing redis ... done
Removing registry ... done
Removing harbor-log ... done
Removing network harbor_harbor
Creating network "harbor_harbor" with the default driver
Creating harbor-log
Creating registry
Creating harbor-db
Creating harbor-adminserver
Creating redis
Creating harbor-ui
Creating harbor-jobservice
Creating nginx
访问地址:
http://<HARBOR_SERVER>/static/vendors/swagger/index.html