透過指令列部署 Proxy

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

本主題將說明如何透過指令列部署 Proxy。Apigee Edge 提供兩種從指令列部署的選項。第一種是使用以 Python 編寫的 Apigee Edge 部署工具。另一種則是設定及執行殼層指令碼。

直接處理系統中的 Proxy 來源檔案時,請使用指令列部署技巧。許多原因都可能導致離線作業。您可以使用偏好的 XML 編輯器,或是開發需要 Java 程式設計且主要使用 IDE 的政策。本節所述的技巧可讓您將來源檔案上傳並部署至所選的 API 服務環境。

如果您主要在管理 UI 中,請參閱在 UI 中部署 Proxy

您目前查看的是 Apigee Edge 說明文件。
參閱 Apigee X 說明文件
資訊

執行 Apigee Edge Python 部署工具

Apigee Edge Python 部署工具可與 Edge Management API 搭配使用,藉此匯入及部署 API Proxy。這項工具包含在 GitHub 上的 API 平台範例發布中。請參閱使用 API Proxy 範例

使用 Apigee Edge Python 工具,透過單一簡單的程序匯入 (上傳) 及部署 API。

部署工具必須在 API 平台範例發布時的基礎目錄執行,其中基本目錄是 setuptools 目錄的父項目錄。

在下列指令中,替換 Proxy 名稱、您的 Edge 使用者名稱和密碼、Edge 機構和環境,以及包含 API Proxy「apiproxy"」目錄的目錄路徑:

python tools/deploy.py -n proxyname -u name:passW -o org -e env -d proxypath -p /

例如:

python tools/deploy.py -n weatherapi -u me@myCo.com:foo -o myCo -e test -d weatherapi -p /

這個指令會壓縮檔案、將檔案推送至 Apigee Edge 上的機構,然後部署至指定環境。

部署工具會自動探索 API Proxy 目前的修訂版本、取消部署現有的修訂版本,並部署 API Proxy 逐步增加的修訂版本。

成功後,輸出內容會以下列格式顯示:

Writing ./<proxybasedir>/apiproxy/weatherapi.xml to apiproxy/weatherapi.xml
Writing ./<proxybasedir>/apiproxy/proxies/default.xml to apiproxy/proxies/default.xml
Writing ./<proxybasedir>/apiproxy/targets/default.xml to apiproxy/targets/default.xml
Imported new proxy version 1
Environment: test
  Revision: 1 BasePath = /
  State: deployed

根據預設,這項工具會將 API Proxy 上傳至 https://api.enterprise.apigee.com,並對應至雲端中的 Edge。您也可以指定 -h 標記,使用這項工具將 API Proxy 上傳至地端部署版本:

python tools/deploy.py -n weatherapi -u me@myCo.com:foo -o myCo -e test -d weatherapi -p / -h https://192.168.11.111:8080

在這個範例中,您會指定 Edge 管理伺服器的 IP 位址。如果您已為管理伺服器建立 DNS 記錄,可以使用下列格式指定網址:

https://ms_URL:8080

指令的完整旗標清單如下:

  • -n:API Proxy 的名稱。
  • -u:在 Apigee Edge 中機構帳戶的使用者名稱和密碼。
  • -o:您帳戶所屬機構的名稱。
  • -e:應部署 API Proxy 的環境 (testprod)。
  • -d:包含 API Proxy 檔案的目錄路徑。您的 API Proxy 檔案必須儲存在名為「apiproxy」的目錄中。這個值是包含「apiproxy」目錄的目錄路徑,而非「apiproxy」目錄本身的路徑。
  • -p:用來比對模式的 URI 路徑,以便將傳入訊息轉送至這個 API Proxy 部署作業。在大多數情況下,除非您有進階部署和轉送需求,否則可以將這個值設為「/」。API Proxy 轉送作業的主要路徑是在 API Proxy 的 ProxyEndpoint 設定檔中定義。
  • -h:邊緣網址。根據預設,網址是 https://api.enterprise.apigee.com,對應至雲端中的 Edge。如果是地端部署部署作業,請使用 Edge 管理伺服器網址和通訊埠 8080,如下所示:
    https://ms_URL:8080

    您也可以使用管理伺服器的 IP 位址,例如 https://192.168.11.111:8080

設定及執行部署殼層指令碼

最簡單的方法是執行 API Proxy 範例提供的部署指令碼。殼層指令碼會包裝 Apigee Edge Python 部署工具。

/simplyProxy 目錄執行:

$ sh deploy.sh

畫面上會顯示下列訊息:

Enter your password for user {myname} in the Apigee Enterprise organization {org_name}, followed by [ENTER]: 

輸入密碼,然後按下 ENTER 鍵。

畫面上會顯示下列訊息:

Deploying to test on https://api.enterprise.apigee.com using {myname} on enterprise.apigee.com and {org_name} on enterprise.apigee.com

如果看到以下選項:

Enter your password for user Your USERNAME on enterprise.apigee.com in the Apigee Enterprise organization Your ORG on enterprise.apigee.com, followed by [ENTER]: 

代表您需要修改平台範例發布中的 /setup/setenv.sh 檔案。如需操作說明,請參閱 README 或 Apigee Edge API

成功之後,部署工具 ZIP 會將 /apiproxy, 下的檔案匯入貴機構 Apigee Edge,再將 API Proxy 部署至「test」環境。

您現在可以叫用 API Proxy 了。