Use the CLI
How to use Stackhero's CLI
Note: The Stackhero CLI is currently not publicly available. If you would like to access it, feel free to email us at support@stackhero.io.
Introduction
The Stackhero CLI (Command Line Interface) is a versatile tool designed to streamline the management of stacks and services. Supporting Linux, macOS, and Windows platforms, it offers a wide range of functionalities tailored for developers and system administrators.
Currently in its beta phase, the CLI is under active development. Updates are rolled out regularly to incorporate new features and address user feedback. If you have any suggestions or encounter issues, your input is highly appreciated.
Authentication
To authenticate with your Stackhero account, you can use this command:
./stackhero login
Running this command will prompt you to enter your email and password, securely connecting you to your account.
Example
Here is a sample script to help you create a new stack, add a Node.js service to it, and configure access using your SSH public key:
Before executing this script, ensure you have your organisation ID. You can find it by running
./stackhero organizations-listand setting the resulting ID to theorganizationIdvariable in the script.
#!/bin/bash
# Exit the script if any command fails
set -e
# Retrieve your organisation ID using "./stackhero organizations-list"
# Replace the placeholder below with the actual ID
organizationId="org-XXXXXX"
# Define stack and service parameters
stackName="My New Stack"
serviceStoreId="svs-jx7xob"
instanceStoreId="ist-4a63fd"
# Prepare the Node.js configuration
sshKey=$(cat ~/.ssh/id_rsa.pub)
configuration="{ \"sshPublicKeys\": [ { \"label\": \"\", \"key\": \"${sshKey}\" } ]}"
# Create the new stack
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 ""
# Wait for the service to be operational
echo "Waiting for the service to be up and running (~2 minutes)..."
./stackhero --format=script service-wait-for \
--service-id=${serviceId}
echo ""
# Configure the new service
echo "Configuring the service..."
./stackhero --format=script service-configuration-set \
--service-id=${serviceId} \
--configuration="${configuration}"
echo ""
# Finalise and confirm setup
echo "Waiting for the service to finalise setup..."
./stackhero --format=script service-wait-for \
--service-id=${serviceId}
echo ""
echo "Setup complete. The new stack is ready for production."
Save this script under a file name such as myFirstAutomation.sh. To make it executable, you can use the following command:
chmod +x myFirstAutomation.sh
Finally, run the script with:
./myFirstAutomation.sh
Once executed successfully, you should see an output like this:
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