使用 CLI
如何使用 Stackhero 的 CLI
注意:Stackhero CLI 目前尚未公開提供。如需訪問,請隨時發送電郵至 [email protected]。
介紹
Stackhero CLI(命令行介面)是一個多功能工具,旨在簡化堆疊和服務的管理。支援 Linux、macOS 和 Windows 平台,提供廣泛的功能,專為開發人員和系統管理員量身定制。
目前處於測試階段,CLI 正在積極開發中。定期推出更新以整合新功能並回應用戶反饋。如果您有任何建議或遇到問題,我們非常感謝您的反饋。
認證
要使用您的 Stackhero 帳戶進行認證,您可以使用以下命令:
./stackhero login
執行此命令將提示您輸入您的電郵和密碼,安全地連接到您的帳戶。
範例
以下是一個示例腳本,幫助您創建新堆疊,添加 Node.js 服務並使用您的 SSH 公鑰配置訪問:
在執行此腳本之前,請確保您擁有您的組織 ID。您可以通過運行
./stackhero organizations-list找到它,並將獲得的 ID 設置為腳本中的organizationId變量。
#!/bin/bash
# 如果任何命令失敗則退出腳本
set -e
# 使用 "./stackhero organizations-list" 獲取您的組織 ID
# 將下面的佔位符替換為實際 ID
organizationId="org-XXXXXX"
# 定義堆疊和服務參數
stackName="My New Stack"
serviceStoreId="svs-jx7xob"
instanceStoreId="ist-4a63fd"
# 準備 Node.js 配置
sshKey=$(cat ~/.ssh/id_rsa.pub)
configuration="{ \"sshPublicKeys\": [ { \"label\": \"\", \"key\": \"${sshKey}\" } ]}"
# 創建新堆疊
echo "Creating stack..."
stackId=$(./stackhero --format=script stack-create \
--organization-id="${organizationId}" \
--name="${stackName}")
echo "The stack was created with the ID ${stackId}"
echo ""
echo "Adding service..."
serviceId=$(./stackhero --format=script service-add \
--stack-id=${stackId} \
--service-store-id=${serviceStoreId} \
--instance-store-id=${instanceStoreId})
echo "The service has been added with the ID ${serviceId}"
echo ""
# 等待服務運行
echo "Waiting for the service to be up and running (~2 minutes)..."
./stackhero --format=script service-wait-for \
--service-id=${serviceId}
echo ""
# 配置新服務
echo "Configuring the service..."
./stackhero --format=script service-configuration-set \
--service-id=${serviceId} \
--configuration="${configuration}"
echo ""
# 完成並確認設置
echo "Waiting for the service to finalize setup..."
./stackhero --format=script service-wait-for \
--service-id=${serviceId}
echo ""
echo "Setup complete. The new stack is ready for production."
將此腳本保存為 myFirstAutomation.sh 等文件名。要使其可執行,您可以使用以下命令:
chmod +x myFirstAutomation.sh
最後,運行腳本:
./myFirstAutomation.sh
成功執行後,您應該會看到如下輸出:
Creating stack...
The stack was created with the ID stk-XXXXXX
Adding service...
The service has been added with the ID svc-XXXXXX
Waiting for service to be up and running (~2 minutes)...
ok
Configure the service
ok
Waiting for service to be up and running...
ok
All done, the new stack is ready for production