範例:端對端建立 service
本文件是使用 CLI指南的一部分。請在此處查看完整指南:安裝並使用 Stackhero CLI,從命令列、scripts、CI 與 AI agents 管理您的 stacks 與 services。
以下是一個範例 script,示範如何建立 stack、加入 service、等待其就緒,並擷取其 credentials。此範例完全採用非互動方式,並使用 STACKHERO_TOKEN 環境變數。
#!/bin/bash
set -e
export STACKHERO_TOKEN="usr-xxxxxx:your-token"
serviceStore="directus" # A service store name. See: `stackhero services-store-list`
instance="1GB" # An instance (size) name. See: `stackhero instances-store-list --service-store=directus`
region="europe" # A region name. See: `stackhero regions-list`
# Create a stack (uses your only organization, add `--organization` if you have several)
stackId=$(stackhero --format=script stack-create \
--name="My stack")
echo "Stack: ${stackId}"
# Add a service (names are resolved automatically, and the stack ID above also works)
serviceId=$(stackhero --format=script service-add \
--stack="My stack" \
--service-store="${serviceStore}" \
--instance="${instance}" \
--region="${region}")
echo "Service: ${serviceId}"
# Wait for the service to be running
stackhero service-wait-for --service="${serviceId}"
# Retrieve credentials and configuration
stackhero service-configuration-get --service="${serviceId}" --format=json
每個 service 文件頁面都包含一份可直接執行的 Automate with the CLI 指南,並依該 service 量身打造,讓您擁有開始使用所需的一切。