CircleCI Integration
Rack Gateway provides native CircleCI integration for automated deploy approvals. When configured, the gateway automatically approves CircleCI workflow jobs after an admin approves the deployment request.
Overview
Section titled “Overview”The integration streamlines the deployment workflow:
Admins only approve once in the gateway. CircleCI jobs proceed automatically.
Configuration
Section titled “Configuration”Gateway Environment Variables
Section titled “Gateway Environment Variables”# CircleCI API token with workflow approval permissionsCIRCLECI_TOKEN=your-circleci-api-tokenGetting a CircleCI Token:
- Visit https://app.circleci.com/settings/user/tokens
- Click “Create New Token”
- Name it “Rack Gateway Deploy Approvals”
- Copy the token immediately
Per-App Settings
Section titled “Per-App Settings”Each app using CircleCI needs these settings:
| Setting | Required | Description | Example |
|---|---|---|---|
vcs_provider | Yes | Version control provider | github |
vcs_repo | Yes | Repository (org/repo) | MyOrg/myapp |
ci_provider | Yes | CI system | circleci |
circleci_approval_job_name | Yes | Approval job name | approve_deploy_prod |
circleci_auto_approve_on_approval | Yes | Enable auto-approval | true |
# Per-app settings via environmentRGW_APP_MYAPP_SETTING_VCS_PROVIDER=githubRGW_APP_MYAPP_SETTING_VCS_REPO=MyOrg/myappRGW_APP_MYAPP_SETTING_CI_PROVIDER=circleciRGW_APP_MYAPP_SETTING_CIRCLECI_APPROVAL_JOB_NAME=approve_deploy_productionRGW_APP_MYAPP_SETTING_CIRCLECI_AUTO_APPROVE_ON_APPROVAL=true- Navigate to Apps
- Select your application
- Open the Settings tab
- Configure CircleCI integration settings
- Save changes
CircleCI Workflow Configuration
Section titled “CircleCI Workflow Configuration”Complete Example
Section titled “Complete Example”version: 2.1
workflows: deploy: jobs: - test - build: requires: - test
# Request approval from Rack Gateway - request_approval: requires: - build
# CircleCI approval job (auto-approved by gateway) - approve_deploy_production: type: approval requires: - request_approval
# Deploy after approval - deploy: requires: - approve_deploy_production
jobs: test: docker: - image: cimg/node:18.0 steps: - checkout - run: npm test
build: docker: - image: cimg/node:18.0 steps: - checkout - run: npm run build
request_approval: docker: - image: docspringcom/ci:deploy steps: - run: name: Request deploy approval command: | rack-gateway deploy-approval request \ --app myapp \ --git-commit "$CIRCLE_SHA1" \ --branch "$CIRCLE_BRANCH" \ --ci-metadata "{\"workflow_id\":\"$CIRCLE_WORKFLOW_ID\",\"pipeline_number\":<< pipeline.number >>}" \ --message "Deploy $CIRCLE_BRANCH@${CIRCLE_SHA1:0:7} to production" environment: RACK_GATEWAY_API_TOKEN: $RACK_GATEWAY_API_TOKEN RACK_GATEWAY_URL: $RACK_GATEWAY_URL
deploy: docker: - image: docspringcom/ci:deploy steps: - checkout - run: name: Deploy via Rack Gateway command: rack-gateway deploy --app myapp environment: RACK_GATEWAY_API_TOKEN: $RACK_GATEWAY_API_TOKEN RACK_GATEWAY_URL: $RACK_GATEWAY_URLKey Points
Section titled “Key Points”request_approvaljob: Uses CLI to create approval request with CI metadataapprove_deploy_productionjob: CircleCI approval job (type: approval) that blocks workflow- Job name must match: Approval job name must match
circleci_approval_job_namesetting - CI metadata: Include
workflow_idandpipeline_number
CI Metadata Format
Section titled “CI Metadata Format”The gateway requires specific metadata for auto-approval:
{ "workflow_id": "$CIRCLE_WORKFLOW_ID", "pipeline_number": "<< pipeline.number >>"}| Field | Source | Purpose |
|---|---|---|
workflow_id | $CIRCLE_WORKFLOW_ID | Identify workflow for job approval |
pipeline_number | << pipeline.number >> | Build pipeline URL for display |
Tailscale Setup
Section titled “Tailscale Setup”If your gateway is accessible only via Tailscale (recommended), CircleCI needs to connect to your Tailscale network.
Docker Image
Section titled “Docker Image”Use a CI image with Tailscale installed:
jobs: request_approval: docker: - image: docspringcom/ci:deployCircleCI Contexts
Section titled “CircleCI Contexts”Configure these contexts:
deploy-app context (shared):
TAILSCALE_OAUTH_SECRET- Tailscale OAuth client secret
Per-environment contexts (e.g., convox-production):
RACK_GATEWAY_URL- Gateway Tailscale hostnameRACK_GATEWAY_API_TOKEN- API token withcicdrole
Tailscale Connection
Section titled “Tailscale Connection”Commands automatically handle Tailscale connection:
steps: - setup_tailscale - run: rack-gateway deploy-approval request ...The setup_tailscale command:
- Starts Tailscale daemon
- Connects using OAuth secret as ephemeral node
- Verifies connectivity to gateway
Auto-Approval Flow
Section titled “Auto-Approval Flow”When admin approves in gateway:
What Gateway Needs
Section titled “What Gateway Needs”| Source | Data |
|---|---|
| CI metadata | workflow_id |
| App settings | circleci_approval_job_name |
| Gateway config | CIRCLECI_TOKEN |
Pipeline URL Display
Section titled “Pipeline URL Display”The gateway builds URLs for display in the web UI:
Formula:
https://app.circleci.com/pipelines/{vcs_short}/{vcs_repo}/{pipeline_number}VCS Short Codes:
github→ghbitbucket→bb
Example:
https://app.circleci.com/pipelines/gh/MyOrg/myapp/1234Multiple Environments
Section titled “Multiple Environments”For multiple deployment environments, use different approval job names:
Staging Gateway
Section titled “Staging Gateway”RGW_APP_MYAPP_SETTING_CIRCLECI_APPROVAL_JOB_NAME=approve_deploy_stagingProduction Gateway
Section titled “Production Gateway”RGW_APP_MYAPP_SETTING_CIRCLECI_APPROVAL_JOB_NAME=approve_deploy_productionCircleCI Workflow
Section titled “CircleCI Workflow”workflows: deploy: jobs: - test - build
# Staging - request_approval_staging: requires: [build] - approve_deploy_staging: type: approval requires: [request_approval_staging] - deploy_staging: requires: [approve_deploy_staging]
# Production - request_approval_production: requires: [deploy_staging] - approve_deploy_production: type: approval requires: [request_approval_production] - deploy_production: requires: [approve_deploy_production]Troubleshooting
Section titled “Troubleshooting”CircleCI Shows “Not Connected”
Section titled “CircleCI Shows “Not Connected””- Verify
CIRCLECI_TOKENis set on gateway - Restart gateway after adding environment variable
- Check token hasn’t expired
- Verify token permissions
Test token:
curl -H "Circle-Token: YOUR_TOKEN" https://circleci.com/api/v2/meJob Not Auto-Approved
Section titled “Job Not Auto-Approved”Checklist:
-
circleci_auto_approve_on_approvalistrue -
circleci_approval_job_namematches exactly -
ci_metadataincludesworkflow_id -
CIRCLECI_TOKENhas correct permissions - App
ci_provideris set tocircleci
Check gateway logs:
convox logs --app rack-gateway | grep -i circleciCommon error messages:
| Error | Cause |
|---|---|
approval job 'xxx' not found in workflow | Job name mismatch |
403 Forbidden | Token lacks permissions or expired |
workflow not found | Invalid workflow_id in metadata |
API Token Permissions
Section titled “API Token Permissions”If you see 403 Forbidden:
- Token needs
write:buildsscope - Regenerate if necessary:
- Visit https://app.circleci.com/settings/user/tokens
- Create new token
- Update
CIRCLECI_TOKEN - Restart gateway
Wrong Pipeline URL
Section titled “Wrong Pipeline URL”Verify settings:
vcs_provideris correct (github)vcs_repois inorg/repoformatpipeline_numberis in CI metadata
Security Considerations
Section titled “Security Considerations”Token Storage
Section titled “Token Storage”- Store
CIRCLECI_TOKENas environment variable, never in git - Use Convox secrets or AWS Secrets Manager
- Rotate tokens every 90 days
Token Permissions
Section titled “Token Permissions”The CircleCI token can approve ANY workflow in your organization:
- Use a dedicated service account
- Monitor approval audit logs
- Restrict token scope to
write:buildsonly
Approval Validation
Section titled “Approval Validation”Gateway validates:
- Request exists and is
pending - API token has
cicdrole - Admin has
adminrole and passes MFA - CI metadata is valid
- App settings are configured
Next Steps
Section titled “Next Steps”- GitHub Integration - PR verification and comments
- Approval Workflow - Detailed workflow
- API Tokens - Token management