Skip to main content

Generic CI/CD

Integrate Cloud Cost Analyzer into any CI/CD system using curl and the CLI.

Some platforms have first-class CCA packages that are cleaner than raw shell: GitHub Actions, GitLab CI (CI/CD Component), and Jenkins (Shared Library). A CircleCI Orb and a Buildkite Plugin are planned. The universal install-script path below works everywhere in the meantime.

Quick Start

These examples use standard shell commands that work with any CI system (CircleCI, Travis CI, Buildkite, Drone, etc.).

Basic Script

#!/bin/bash
set -e

# Install CCA
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca

# Run scan (requires AWS credentials in environment)
./cca scan --provider aws --mode managed --output json > results.json

# Display summary
echo "=== Cost Analysis Results ==="
echo "Findings: $(jq '.findings | length' results.json)"
echo "Monthly Savings: $(jq '.summary.total_monthly_savings' results.json)"

Required Environment Variables

AWS

export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_REGION="us-east-1"
export CCA_API_KEY="cca_live_xxxxx" # For managed mode

Azure

export AZURE_CLIENT_ID="your-client-id"
export AZURE_CLIENT_SECRET="your-client-secret"
export AZURE_TENANT_ID="your-tenant-id"
export AZURE_SUBSCRIPTION_ID="your-subscription-id"
export CCA_API_KEY="cca_live_xxxxx" # For managed mode

API-Only Integration (No CLI)

If you can't install the CLI, use the API directly with curl:

#!/bin/bash
set -e

API_URL="https://cca.dragonfractal.com/api/v1"
API_KEY="cca_live_xxxxx"

# List recent scans
curl -s -H "x-api-key: $API_KEY" \
"$API_URL/cli/scans" | jq .

# Get a specific scan
SCAN_ID="your-scan-id"
curl -s -H "x-api-key: $API_KEY" \
"$API_URL/cli/scans/$SCAN_ID" | jq .

CircleCI

# .circleci/config.yml
version: 2.1

jobs:
cost-analysis:
docker:
- image: cimg/base:current
steps:
- run:
name: Install CCA
command: |
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
sudo mv cca /usr/local/bin/
- run:
name: Run Cost Analysis
command: cca scan --provider aws --mode managed
environment:
AWS_REGION: us-east-1

workflows:
weekly-scan:
triggers:
- schedule:
cron: "0 9 * * 1"
filters:
branches:
only: main
jobs:
- cost-analysis:
context: aws-credentials

Buildkite

# .buildkite/pipeline.yml
steps:
- label: ":money_with_wings: Cost Analysis"
command: |
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
./cca scan --provider aws --mode managed
env:
AWS_REGION: "us-east-1"

Docker

Run CCA in a Docker container:

docker run --rm \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e AWS_REGION=us-east-1 \
-e CCA_API_KEY \
dragonfractal/cca:latest \
scan --provider aws --mode managed

Compliance Script

A reusable script that fails on critical findings:

#!/bin/bash
# cost-check.sh - Run as part of any CI pipeline
set -e

# Install if not present
if ! command -v cca &> /dev/null; then
curl -LO https://releases.dragonfractal.com/cca/latest/cca-linux-amd64.tar.gz
tar -xzf cca-linux-amd64.tar.gz
chmod +x cca
export PATH="$PATH:$(pwd)"
fi

# Run scan
cca scan --provider "${PROVIDER:-aws}" --output json > /tmp/cca-results.json

# Parse results
FINDINGS=$(jq '.findings | length' /tmp/cca-results.json)
CRITICAL=$(jq '[.findings[] | select(.severity == "Critical")] | length' /tmp/cca-results.json)
SAVINGS=$(jq '.summary.total_monthly_savings' /tmp/cca-results.json)

echo "================================"
echo "Cost Analysis Summary"
echo "================================"
echo "Total Findings: $FINDINGS"
echo "Critical: $CRITICAL"
echo "Monthly Savings: \$$SAVINGS"
echo "================================"

# Fail on critical findings
if [ "$CRITICAL" -gt 0 ]; then
echo "ERROR: $CRITICAL critical findings detected!"
exit 1
fi

echo "All clear - no critical findings."

Next Steps