CI/CD integration
- Prepare your environment
- Set up authentication credentials:
# Store credentials in a secure CI/CD variable
export N9_CLIENT_ID="your-client-id"
export N9_CLIENT_SECRET="your-client-secret"- Create a configuration file (
~/.config/nobl9/config.toml
):
defaultContext = "ci-pipeline"
[Contexts]
[Contexts.ci-pipeline]
clientId = "${N9_CLIENT_ID}"
clientSecret = "${N9_CLIENT_SECRET}" - Install sloctl in your CI/CD pipeline
Option A: Using the Docker image (recommended)
# In your CI/CD configuration:
stages:
- deploy-slos
deploy-slos:
stage: deploy-slos
image: nobl9/sloctl:latest
script:
# Set up the authentication configuration
- mkdir -p /home/appuser/.config/nobl9
- echo "$N9_CONFIG" > /home/appuser/.config/nobl9/config.toml
# Apply SLO definitions using sloctl
- sloctl apply -f ./slo-definitions/
Option B: Direct installation using sloctl
# In your CI/CD configuration:
stages:
- deploy-slos
deploy-slos:
stage: deploy-slos
script:
# Download and install sloctl
- curl -L https://github.com/nobl9/sloctl/releases/latest/download/sloctl_Linux_x86_64.tar.gz | tar xz
- chmod +x sloctl
- mv sloctl /usr/local/bin/
# Set up configuration
- mkdir -p ~/.config/nobl9
- echo "$N9_CONFIG" > ~/.config/nobl9/config.toml
# Apply SLO definitions
- sloctl apply -f ./slo-definitions/
- Structure your SLO definitions repository:
repository-root/
├── .gitlab-ci.yml (or other CI/CD config)
├── slo-definitions/
│ ├── production/
│ │ ├── api-service.yaml
│ │ ├── database.yaml
│ │ └── frontend.yaml
│ ├── staging/
│ │ ├── api-service.yaml
│ │ └── database.yaml
│ └── shared/
│ ├── alert-methods.yaml
│ └── alert-policies.yaml
└── README.md
- Create validation steps
validate-slos:
stage: validate
image: nobl9/sloctl:latest
script:
# Validate SLO YAML syntax without applying
- for file in $(find ./slo-definitions -name "*.yaml"); do
echo "Validating $file";
sloctl apply -f $file --dry-run;
done
- Implement continuous delivery of SLOs
# GitLab CI example for branch-based deployments
deploy-to-staging:
stage: deploy
image: nobl9/sloctl:latest
script:
- sloctl config use-context staging
- sloctl apply -f ./slo-definitions/staging/
- sloctl apply -f ./slo-definitions/shared/
only:
- develop
deploy-to-production:
stage: deploy
image: nobl9/sloctl:latest
script:
- sloctl config use-context production
- sloctl apply -f ./slo-definitions/production/
- sloctl apply -f ./slo-definitions/shared/
only:
- main
when: manual # Requires manual approval
- Add reporting and verification
verify-deployment:
stage: verify
image: nobl9/sloctl:latest
script:
# Check if SLOs were properly applied
- sloctl get slos --project my-project > applied-slos.txt
# Optional: Generate report of current SLO status
- for slo in $(sloctl get slos -o name --project my-project); do
sloctl replay $slo --last 24h >> slo-status-report.txt;
done
# Archive reports as artifacts
- echo "SLO deployment completed successfully"
artifacts:
paths:
- applied-slos.txt
- slo-status-report.txt
Best practices for CI/CD integration
- Version control all SLO definitions - Track changes and apply proper review processes
- Use environment-specific contexts - Maintain separate configurations for dev, staging, and production
- Implement dry-run validation - Test changes before applying them to production
- Add automatic testing - Verify SLO configurations work as expected
- Use descriptive commit messages - Document why SLO changes were made
- Implement role-based permissions - Limit who can deploy to production
- Include post-deployment verification - Confirm SLOs are correctly applied
- Automate rollbacks - Be prepared to revert to previous SLO definitions if needed
This CI/CD integration allows teams to maintain SLOs as code, ensuring consistency, traceability, and automation in managing service level objectives across environments.