From a091f6f935730e7958597b0956724557375c06a1 Mon Sep 17 00:00:00 2001 From: wemeya <1013939285@qq.com> Date: Fri, 9 Jun 2017 13:45:51 +0800 Subject: [PATCH] modify prepare-swagger.sh and configure_swagger.md --- docs/configure_swagger.md | 49 +++++++++++++++++---------------------- docs/prepare-swagger.sh | 1 + 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/docs/configure_swagger.md b/docs/configure_swagger.md index dbb246c94..6acd8eca4 100644 --- a/docs/configure_swagger.md +++ b/docs/configure_swagger.md @@ -1,8 +1,6 @@ # View and test Harbor REST API via Swagger -A Swagger file is provided for viewing and testing Harbor REST API. First, you should get the source code of Harbor: -```sh - git clone git@github.com:vmware/harbor.git -``` +A Swagger file is provided for viewing and testing Harbor REST API. + ### Viewing Harbor REST API * Open the file **swagger.yaml** under the _docs_ directory in Harbor project; * Paste all its content into the online Swagger Editor at http://editor.swagger.io. The descriptions of Harbor API will be shown on the right pane of the page. @@ -10,15 +8,15 @@ A Swagger file is provided for viewing and testing Harbor REST API. First, you s ![Swagger Editor](img/swaggerEditor.png) ### Testing Harbor REST API -From time to time, you may need to mannually test Harbor REST API. You can deploy the Swagger file into Harbor's service node. +From time to time, you may need to mannually test Harbor REST API. You can deploy the Swagger file into Harbor's service node. Suppose you install Harbor through online or offline installer, you should have a Harbor directory after you un-tar the installer, such as **~/harbor**. **Caution:** When using Swagger to send REST requests to Harbor, you may alter the data of Harbor accidentally. For this reason, it is NOT recommended using Swagger against a production Harbor instance. -* Change the directory to _docs_ in Harbor project. +* Download _prepare-swagger.sh_ and _swagger.yaml_ under the _docs_ directory to your local Harbor directory, e.g. **~/harbor**. ```sh - cd docs + wget https://raw.githubusercontent.com/vmware/harbor/master/docs/prepare-swagger.sh https://raw.githubusercontent.com/vmware/harbor/master/docs/swagger.yaml ``` -* Edit the script file _prepare-swagger.sh_ under the _docs_ directory. +* Edit the script file _prepare-swagger.sh_. ```sh vi prepare-swagger.sh ``` @@ -30,15 +28,15 @@ From time to time, you may need to mannually test Harbor REST API. You can deplo ```sh SERVER_ID= ``` -* Run the shell script. It downloads a Swagger package and extracts files into the _static_ directory in Harbor project. +* Change the file mode. +```sh + chmod +x prepare-swagger.sh +```` +* Run the shell script. It downloads a Swagger package and extracts files into the _../static_ directory. ```sh ./prepare-swagger.sh ``` -* Change the directory to _make_ -```sh - cd ../make/dev -``` -* Edit the _docker-compose.yml_ file. +* Edit the _docker-compose.yml_ file under your local Harbor directory. ```sh vi docker-compose.yml ``` @@ -48,25 +46,20 @@ From time to time, you may need to mannually test Harbor REST API. You can deplo ui: ... volumes: - - ./config/ui/app.conf:/etc/ui/app.conf - - ./config/ui/private_key.pem:/etc/ui/private_key.pem + - ./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 ## - - ../../src/ui/static/vendors/swagger-ui-2.1.4/dist:/go/bin/static/vendors/swagger - - ../../src/ui/static/resources/yaml/swagger.yaml:/go/bin/static/resources/yaml/swagger.yaml + - ../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 ... ``` -* Rebuild Harbor project +* Recreate Harbor containers ```docker - docker-compose build -``` -* Clean up the previous running version. NOTE: The command does not remove your existing data. -```docker - docker-compose rm -``` -* Start the new Harbor build -```docker - docker-compose up + docker-compose down -v & docker-compose up -d ``` + * Because a session ID is usually required by Harbor API, **you should log in first from a browser.** * Open another tab in the same browser so that the session is shared between tabs. * Enter the URL of the Swagger page in Harbor as below. The `````` should be replaced by the IP address or the hostname of the Harbor server. diff --git a/docs/prepare-swagger.sh b/docs/prepare-swagger.sh index 82fbebc55..41b9c8a95 100755 --- a/docs/prepare-swagger.sh +++ b/docs/prepare-swagger.sh @@ -7,6 +7,7 @@ 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' \