Selective Deployment
This guide explains how to configure selective deployment for the MyStoryFlow monorepo, ensuring that only affected applications are rebuilt when changes are made.
Overview
Selective deployment uses Turborepo’s turbo-ignore to analyze which applications are affected by changes in a commit. This significantly reduces build times and deployment overhead by only building applications that have actually changed.
Prerequisites
- Turborepo installed (
turbo-ignorepackage) - Vercel projects set up for each application
- Proper monorepo structure with
turbo.jsonconfiguration
Configuration Steps
1. Install Dependencies
Ensure turbo-ignore is installed in the root package.json:
{
"devDependencies": {
"turbo-ignore": "^2.3.3"
}
}
``` -->
### 2. Configure Vercel Dashboard (Critical Step)
**Important**: The selective deployment must be configured in the Vercel Dashboard, NOT in `vercel.json` files.
For each Vercel project:
1. **Navigate to Project Settings**
- Go to your Vercel dashboard
- Select the project (e.g., web-app, marketing-site, docs-app, admin-app, tools-app)
- Click on "Settings"
2. **Configure Git Settings**
- In the left sidebar, click on "Git"
- Scroll down to "Ignored Build Step"
3. **Set Custom Ignore Command**
- Select "Custom" from the dropdown
- Enter: `npx turbo-ignore`
- Click "Save"
4. **Repeat for All Projects**
- web-app: `npx turbo-ignore`
- marketing-site: `npx turbo-ignore`
- docs-app: `npx turbo-ignore`
- admin-app: `npx turbo-ignore`
- tools-app: `npx turbo-ignore`
### 3. Verify vercel.json Configuration
Ensure your `vercel.json` files do NOT contain `ignoreCommand`:
```json
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"buildCommand": "cd ../.. && npx turbo run build --filter=web-app",
"outputDirectory": ".next",
"installCommand": "cd ../.. && npm install"
}
``` -->
**Note**: Remove any `ignoreCommand` properties from `vercel.json` files as they are invalid and will cause configuration errors.
### 4. Configure turbo.json
Ensure your `turbo.json` uses the modern format:
```json
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"globalEnv": ["NEXT_PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_ANON_KEY"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "dist/**"],
"env": ["NEXT_PUBLIC_SUPABASE_URL"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
``` -->
## How It Works
### 1. Change Detection
When you push changes to your repository:
1. Vercel receives the webhook
2. For each project, Vercel runs the configured ignore command: `npx turbo-ignore`
3. `turbo-ignore` analyzes the changes and determines if the current app is affected
4. If affected: Build proceeds (exit code 1)
5. If not affected: Build is skipped (exit code 0)
### 2. Dependency Analysis
`turbo-ignore` considers:
- Direct file changes in the app directory
- Changes to shared packages the app depends on
- Changes to global configuration files
- Dependency relationships defined in `package.json`
## Testing Selective Deployment
### Local Testing
Test the ignore logic locally:
```bash
# Navigate to an app directory
cd apps/web-app
# Run turbo-ignore
npx turbo-ignore
# Check exit code
echo $?
# 0 = skip build
# 1 = proceed with build
``` -->
### Deployment Testing
1. **Make a targeted change**:
```bash
# Edit a file in only one app
echo "// test change" >> apps/web-app/app/page.tsx
git add -A
git commit -m "test: web-app only change"
git push
``` -->
2. **Monitor Vercel Dashboard**:
- Only the web-app project should build
- Other projects should show "Build skipped" or "Ignored"
3. **Check build logs**:
- Look for turbo-ignore execution in the build logs
- Verify the ignore logic is working correctly
## Common Scenarios
### App-Specific Changes
```bash
# Only affects web-app
apps/web-app/app/page.tsx
# Only affects marketing-site
apps/marketing-site/src/app/page.tsx
``` -->
### Shared Package Changes
```bash
# Affects all apps using the shared package
packages/ui/src/components/Button.tsx
``` -->
### Global Configuration Changes
```bash
# May affect all apps
turbo.json
package.json
.env.example
``` -->
## Troubleshooting
### All Apps Building Despite Selective Config
**Cause**: Dashboard configuration not properly set
**Solution**:
1. Double-check each project's Git settings in Vercel Dashboard
2. Ensure "Custom" is selected with `npx turbo-ignore`
3. Save settings and test with a targeted change
### Build Skipped When It Shouldn't Be
**Cause**: Dependency relationships not detected
**Solution**:
1. Check `package.json` dependencies
2. Verify shared package imports are correct
3. Test turbo-ignore locally to debug dependency detection
### Error: "turbo-ignore command failed"
**Cause**: Package not installed or turbo.json configuration issues
**Solution**:
1. Ensure `turbo-ignore` is in root `package.json`
2. Verify `turbo.json` syntax is valid
3. Check Node.js version compatibility
## Benefits
- **Faster Deployments**: Only affected apps are built
- **Reduced Resource Usage**: Lower build minutes consumption
- **Parallel Deployments**: Multiple apps can deploy simultaneously
- **Better Developer Experience**: Faster feedback on changes
## Monitoring
Monitor selective deployment effectiveness:
1. **Vercel Dashboard**: Check build frequency per project
2. **Build Logs**: Verify turbo-ignore execution
3. **Deployment Times**: Compare before/after selective deployment
4. **Resource Usage**: Monitor build minutes consumption
With proper configuration, you should see significant reductions in unnecessary builds and faster deployment times for your monorepo.