Esempio: creare un servizio end-to-end
Questa documentazione fa parte della guida Usare la CLI. Consulta la guida completa qui: Installa e usa la CLI di Stackhero per gestire stack e servizi dalla riga di comando, da script, CI e agenti AI.
Ecco uno script di esempio che mostra come creare uno stack, aggiungere un servizio, attendere che sia pronto e recuperarne le credenziali. Questo esempio è completamente non interattivo e usa la variabile d'ambiente 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
Ogni pagina della documentazione di un servizio include una guida Automate with the CLI pronta all'uso e adattata a quel servizio, così hai tutto ciò che ti serve per iniziare.