CI/CD Integration
Canine supports deploying applications only when Continuous Integration (CI) checks pass by using deploy webhooks with API tokens. This allows you to maintain quality gates and ensure that broken code never reaches production.
Overview
By default, Canine automatically deploys your application whenever you push to a connected GitHub branch. However, you may want to:
- Only deploy after CI/CD tests pass
- Integrate with GitHub Actions, GitLab CI, or other CI systems
- Control deployment timing from external systems
- Implement custom approval workflows
Deploy webhooks allow you to trigger deployments programmatically from your CI/CD pipeline.
Setting up Deploy Webhooks
Step 1: Create an API Token
First, you need to generate an API token to authenticate webhook requests:
- Navigate to Settings → API Tokens in your Canine dashboard
- Click + New API Token
- Give your token a descriptive name (e.g., "GitHub Actions Deploy Token")
- Select the appropriate permissions (at minimum, you'll need
deploy:writepermissions) - Click Create Token
- Important: Copy the token immediately - you won't be able to see it again
Store this token securely. You'll use it to authenticate deployment requests from your CI system.
Step 2: Disable Automatic Deployments
To prevent Canine from automatically deploying on every push:
- Go to Projects → Your Project → Settings
- Under GitHub Integration, uncheck Auto-deploy on push
- Save your changes
Now deployments will only occur when triggered via the webhook.
Step 3: Get Your Deploy Webhook URL
Each project has a unique deploy webhook URL:
- Navigate to Projects → Your Project → Settings
- Find the Deploy Webhook section
- Copy the webhook URL - it should look like:
https://canine.example.com/api/v1/projects/{project_id}/deploy
Triggering Deployments from CI
GitHub Actions Example
Create a workflow file (e.g., .github/workflows/deploy.yml) in your repository:
name: Deploy to Canine
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
# Your test commands here
npm install
npm test
deploy:
needs: test # Only runs if tests pass
runs-on: ubuntu-latest
steps:
- name: Trigger Canine deployment
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CANINE_API_TOKEN }}" \
-H "Content-Type: application/json" \
https://canine.example.com/api/v1/projects/YOUR_PROJECT_ID/deploy
Setup Instructions:
- Go to your GitHub repository Settings → Secrets and variables → Actions
- Click New repository secret
- Name it
CANINE_API_TOKENand paste your API token as the value - Update the webhook URL with your actual project ID
- Commit and push the workflow file
GitLab CI Example
Add this to your .gitlab-ci.yml:
stages:
- test
- deploy
test:
stage: test
script:
- npm install
- npm test
deploy:
stage: deploy
only:
- main
script:
- |
curl -X POST \
-H "Authorization: Bearer ${CANINE_API_TOKEN}" \
-H "Content-Type: application/json" \
https://canine.example.com/api/v1/projects/YOUR_PROJECT_ID/deploy
Setup Instructions:
- Go to Settings → CI/CD → Variables in your GitLab project
- Add a variable named
CANINE_API_TOKENwith your API token - Mark it as Protected and Masked for security
- Update the webhook URL with your actual project ID
Advanced Configuration
Deploying Specific Branches or Commits
You can specify which branch or commit to deploy by adding parameters to your webhook request:
curl -X POST \
-H "Authorization: Bearer ${CANINE_API_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"branch": "staging", "commit": "abc123"}' \
https://canine.example.com/api/v1/projects/YOUR_PROJECT_ID/deploy
Conditional Deployments
Deploy only when specific conditions are met:
GitHub Actions:
- name: Deploy to production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CANINE_API_TOKEN }}" \
-H "Content-Type: application/json" \
https://canine.example.com/api/v1/projects/PROD_PROJECT_ID/deploy
- name: Deploy to staging
if: github.ref == 'refs/heads/develop'
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CANINE_API_TOKEN }}" \
-H "Content-Type: application/json" \
https://canine.example.com/api/v1/projects/STAGING_PROJECT_ID/deploy
GitLab CI:
deploy-production:
stage: deploy
only:
- main
script:
- curl -X POST -H "Authorization: Bearer ${CANINE_API_TOKEN}" -H "Content-Type: application/json" https://canine.example.com/api/v1/projects/PROD_PROJECT_ID/deploy
deploy-staging:
stage: deploy
only:
- develop
script:
- curl -X POST -H "Authorization: Bearer ${CANINE_API_TOKEN}" -H "Content-Type: application/json" https://canine.example.com/api/v1/projects/STAGING_PROJECT_ID/deploy
Notification on Deployment
Get notified when deployments complete:
# Trigger deployment and save response
response=$(curl -X POST \
-H "Authorization: Bearer ${CANINE_API_TOKEN}" \
-H "Content-Type: application/json" \
https://canine.example.com/api/v1/projects/YOUR_PROJECT_ID/deploy)
deployment_id=$(echo $response | jq -r '.deployment_id')
# Send notification to Slack
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"Deployment ${deployment_id} triggered for project\"}" \
${SLACK_WEBHOOK_URL}
Security Best Practices
- Never commit API tokens to your repository - Always use secret management features provided by your CI system
- Use separate tokens for different environments - Create distinct tokens for staging and production
- Rotate tokens regularly - Update your API tokens every 90 days
- Limit token permissions - Only grant the minimum required permissions (e.g.,
deploy:writefor the specific project) - Monitor token usage - Check your Canine audit logs for unexpected deployment activity
Troubleshooting
Deployment webhook returns 401 Unauthorized
- Verify your API token is correct and hasn't expired
- Check that the token has the required
deploy:writepermissions - Ensure the
Authorizationheader is properly formatted:Bearer YOUR_TOKEN
Deployment webhook returns 404 Not Found
- Verify the project ID in the webhook URL is correct
- Ensure the project still exists and hasn't been deleted
Deployments are still happening automatically
- Confirm that Auto-deploy on push is disabled in project settings
- Check that you saved the settings after making changes
- Note: Existing webhooks from GitHub may still be active; you can remove them in your GitHub repository settings under Webhooks
Related Documentation
- Projects
- Preview Apps - Learn about automatic deployments for pull requests
- Web Services