Appearance
CI/CD & Deployment Guide
This document provides comprehensive instructions for setting up and managing the CI/CD pipeline and deployment process for the Bookr monorepo project.
Overview
The project uses:
- Gitea Actions for CI/CD workflows
- Docker for containerization
- Gitea Container Registry for image storage
- Dokploy for deployment orchestration
- Turbo for monorepo build optimization
Quick Setup
- Configure Gitea Secrets
- Set up Dokploy Applications
- Update Deployment Configuration
- Push to trigger your first deployment!
Gitea Secrets Configuration
Navigate to your repository settings → Secrets and add the following secrets:
Required Secrets
| Secret Name | Description | Example Value |
|---|---|---|
GITEA_REGISTRY_USERNAME | Your Gitea username for container registry | your-username |
GITEA_REGISTRY_PASSWORD | Your Gitea password or access token | your-password-or-token |
DOKPLOY_URL | Base URL of your Dokploy instance | https://dokploy.example.com |
DOKPLOY_API_TOKEN | Dokploy API token for deployments | dp_xxx... |
How to Get These Values
Gitea Registry Credentials
- Go to your Gitea instance
- Navigate to User Settings → Applications → Access Tokens
- Create a new token with
package:writepermissions - Use your username and this token
Dokploy API Token
- Log into your Dokploy dashboard
- Go to Settings → API Tokens
- Create a new token with deployment permissions
- Copy the token (starts with
dp_)
Dokploy Setup
1. Create Applications
For each application (api, web, sample-app), create corresponding applications in Dokploy:
Create Application:
- Name:
bookr-{app-name}-{environment}(e.g.,bookr-api-development) - Source: Docker Image
- Image:
gitea.bookr.dev:3000/usr_unknown/bookr-{app-name}:latest
- Name:
Configure Environment:
- Set appropriate environment variables
- Configure port mappings
- Set health check endpoints (if applicable)
Note the Application ID:
- After creation, note the application ID from the URL
- Example:
https://dokploy.example.com/dashboard/project/123/application/456→ ID is456
2. Environment Setup
Create applications for each environment:
- Development: For
develop,feat/*branches - Staging: For
stagingbranch - Production: For
main/masterbranches
Deployment Configuration
Update deployment.json
Edit the deployment.json file in your repository root:
json
{
"environments": {
"development": {
"api_app_id": "your-actual-api-dev-id",
"web_app_id": "your-actual-web-dev-id",
"sample_app_id": "your-actual-sample-app-dev-id"
},
"staging": {
"api_app_id": "your-actual-api-staging-id",
"web_app_id": "your-actual-web-staging-id",
"sample_app_id": "your-actual-sample-app-staging-id"
},
"production": {
"api_app_id": "your-actual-api-prod-id",
"web_app_id": "your-actual-web-prod-id",
"sample_app_id": "your-actual-sample-app-prod-id"
}
},
"registry": {
"url": "gitea.bookr.dev:3000",
"namespace": "your-gitea-username-or-org"
}
}Registry Configuration
Update the registry settings in deployment.json:
- url: Your Gitea instance registry URL
- namespace: Your Gitea username or organization name
Workflows
Check Workflow (.gitea/workflows/check.yaml)
Triggers: Push to main branches, pull requests
Steps:
- Install dependencies
- Run type checking
- Run linting
- Run tests
Branch Configuration:
- Runs on:
main,master,develop,staging,feat/deployment - PR target:
main,master,develop
Deploy Workflow (.gitea/workflows/deploy.yaml)
Triggers:
- Push to deployment branches
- Manual workflow dispatch
Steps:
- Checks: Runs check workflow first
- Prepare:
- Determines target environment
- Detects changed applications
- Reads deployment configuration
- Build:
- Builds only changed applications
- Creates and pushes Docker images
- Tags images appropriately
- Deploy:
- Deploys via Dokploy API
- Runs in parallel for multiple apps
Branch-to-Environment Mapping
| Branch Pattern | Target Environment |
|---|---|
main, master | production |
staging | staging |
develop, feat/* | development |
Manual Deployment
Via Gitea UI
- Go to Actions tab in your repository
- Select "Deploy" workflow
- Click "Run workflow"
- Choose:
- Branch to deploy from
- Target environment
- Whether to force deploy all apps
Via Command Line
You can also deploy manually using the scripts:
bash
# Deploy specific app to specific environment
node scripts/deploy.js development api
node scripts/deploy.js production web
# Build and push Docker image
node scripts/docker-build.js api latest gitea.bookr.dev:3000 usr_unknownApplication Detection
The workflow automatically detects which applications need deployment:
Change Detection
- App Changes: Monitors
apps/{app-name}/directories - Shared Changes: If
packages/changes, deploys all apps - Force Deploy: Manual override to deploy all apps
Build Optimization
- Uses Turbo to build only changed applications
- Builds dependencies automatically via
dependsOnconfiguration
Docker Image Tagging Strategy
| Environment | Tag Pattern |
|---|---|
| Development | latest |
| Staging | {git-sha}-staging |
| Production | {git-sha}-production |
Images are always tagged as both specific version and latest for the environment.
Troubleshooting
Common Issues
1. "App ID not configured"
Solution: Update deployment.json with actual Dokploy application IDs
2. "Docker login failed"
Solution: Verify Gitea registry credentials in secrets
3. "Deployment API call failed"
Solution:
- Check Dokploy API token validity
- Verify Dokploy URL is accessible
- Ensure application exists in Dokploy
4. "No applications detected for deployment"
Solution:
- Ensure changes are in monitored directories (
apps/,packages/) - Use manual deployment with force deploy option
Debug Information
View Deployment Logs
- Check Gitea Actions logs for build issues
- Check Dokploy application logs for deployment issues
- Review Docker registry for image availability
Verify Configuration
bash
# Test deployment script locally
export DOKPLOY_URL="your-dokploy-url"
export DOKPLOY_API_TOKEN="your-token"
node scripts/deploy.js development api
# Test Docker build locally
node scripts/docker-build.js api latestSecurity Best Practices
Secrets Management:
- Use Gitea secrets for sensitive data
- Rotate API tokens regularly
- Use least privilege access
Image Security:
- Regular base image updates
- Scan images for vulnerabilities
- Use multi-stage builds to minimize attack surface
Environment Isolation:
- Separate Dokploy projects per environment
- Different credentials per environment
- Network isolation between environments
Environment Variables
Application-Level Environment Variables
Each application should manage its own environment variables:
API Application (apps/api)
- Database connections
- API keys
- Service endpoints
Web Application (apps/web)
- API base URLs
- Feature flags
- Analytics tokens
Sample Application (apps/sample-app)
- Configuration specific to sample app
Dokploy Environment Configuration
Configure environment variables in Dokploy for each application:
- Navigate to Application Settings
- Go to Environment Variables section
- Add variables as key-value pairs
- Use secrets for sensitive values
Monitoring and Observability
Health Checks
The deployment includes health check configuration:
yaml
healthcheck:
test:
[
'CMD',
'node',
'-e',
"require('http').get('http://localhost:3001/health', res => process.exit(res.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))",
]
interval: 1m30s
timeout: 30s
retries: 5
start_period: 30sDeployment Status
Monitor deployments via:
- Gitea Actions for CI/CD pipeline status
- Dokploy dashboard for application status
- Application health endpoints
Advanced Configuration
Custom Build Arguments
Modify scripts/docker-build.js to accept additional build arguments:
bash
# Example: Custom Node version
node scripts/docker-build.js api latest gitea.bookr.dev:3000 usr_unknown 20Environment-Specific Builds
Customize builds per environment by modifying the Dockerfile:
dockerfile
ARG NODE_ENV=production
ARG BUILD_ENV=developmentMulti-Registry Support
The scripts support pushing to multiple registries:
bash
# Push to different registry
node scripts/docker-build.js api v1.0.0 my-registry.com my-orgMigration from Webhook Approach
If migrating from the old webhook-based deployment:
- Update Secrets: Replace webhook URLs with API tokens
- Configure App IDs: Add application IDs to
deployment.toml - Test Deployments: Run manual deployments to verify setup
- Remove Old Webhooks: Clean up webhook secrets after verification
Support
For issues or questions:
- Check the troubleshooting section above
- Review Gitea Actions logs
- Check Dokploy application status
- Verify all configuration files and secrets
This documentation covers the complete CI/CD and deployment setup. Keep it updated as your infrastructure evolves.