InfluxDB: 3. The lifecycle script

This documentation is part of the CI pipeline integration with GitHub Actions and GitLab CI guide. You can view the complete guide here: Launch a real InfluxDB service from your GitHub Actions or GitLab CI pipeline, run your tests against it, and automatically remove it afterwards.

👋 Welcome to the Stackhero documentation

Stackhero provides a fully managed InfluxDB cloud environment, designed for speed and simplicity:

  • Unlimited writes, queries, dashboards, tasks, and buckets.
  • Unlimited data retention: keep your metrics for as long as you need.
  • Unlimited network and disk transfers, with no hidden limits.
  • One-click updates: always benefit from the latest features and fixes.
  • Consistent performance and enhanced security on your own private, dedicated infrastructure.

With Stackhero, you can focus on your data and analysis. Deploying InfluxDB cloud hosting only takes a few minutes, with every setup optimised for long-term reliability.

Below is a complete example script that manages the entire service lifecycle. It demonstrates how straightforward the setup is, requiring just a few commands. You can copy the ready-made YAML for your platform from the sections below.

#!/bin/bash
set -euo pipefail

# STACKHERO_TOKEN is provided by the CI secret, the CLI picks it up automatically.

stack="CI"                              # The stack created in step 2
serviceStore="influxdb"             # The InfluxDB service store
instance="10G"        # Change this as needed (see step 4)
region="europe"                         # Region name (see stackhero regions-list)

# 1. Install the client used for the smoke test (as root, or prefix with sudo)
apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl

# 2. Install the CLI on the runner
curl -fsSL https://www.stackhero.io/install.sh | STACKHERO_INSTALL_DIR="$HOME/.local/bin" sh
export PATH="$HOME/.local/bin:$PATH"

# 3. Add InfluxDB to the CI stack and capture its service ID
serviceId=$(stackhero --format=script service-add \
  --stack="$stack" \
  --service-store="$serviceStore" \
  --instance="$instance" \
  --region="$region")
echo "Service added: $serviceId"

# 4. Delete the service when the script ends, whether it succeeds or fails
trap 'stackhero service-delete --service="$serviceId" --confirm' EXIT

# 5. Wait until the service is running (this usually takes a few minutes)
timeout 15m stackhero service-wait-for --service="$serviceId"

# 6. Retrieve the configuration (contains the generated credentials)
config=$(stackhero service-configuration-get --service="$serviceId" --format=json)

# 7. Extract the credentials you need
host=$(echo "$config" | jq -r '.configuration.domain')

# 8. Smoke test: Call the InfluxDB health endpoint.
curl -fsS "https://$host:8086/health" | grep -q '"status":"pass"'

echo "✅ InfluxDB is reachable from CI."

The only clean-up required is deleting the service: the stack remains for the next run. In the YAML below, this deletion is a separate step that the CI always executes, even if a test fails, so you are never billed for a service you are no longer using.

timeout 15m sets a limit on the wait. If the service does not start, the run fails quickly and the service is deleted, rather than waiting for your CI's time limit.