Deployment Steps
Define the steps that are executed during deployment for advanced control.
What are Deployment Steps?
Deployment Steps are a series of actions that are executed during a deployment. They enable you to define complex deployment processes that involve more than just running a script.
Why Use Deployment Steps?
- Modularity - Reusable steps for multiple applications
- Visualization - See the progress of each step
- Error Handling - Stop on errors and see which step failed
- Control - Define what exactly needs to happen during a deployment
Deployment Step Types
Templates
Templates are pre-defined steps provided by Hydra Deploy:
Available Templates:
- Health Check - Check if application is available
- Database Migration - Run database migrations
- Cache Clear - Clear cache
- Backup - Create backup before deployment
- Rollback - Roll back on errors
Custom Steps
Create your own deployment steps for specific use cases:
- Bash scripts
- PowerShell scripts (for Windows)
- Custom checks
- Integration with external services
Managing Deployment Steps
From Application Page
- Go to an Application
- Navigate to the Deployment Steps tab
- View current steps
Creating a Step
Custom Step:
- Click on Add Custom Step
- Fill in the following fields:
- Name - A descriptive name (e.g., “Run Tests”)
- Description - What does this step do?
- Type - Script type (Bash/PowerShell)
- Script - The script to execute
- Click on Save
Adding Template:
- Click on Add Template
- Select a template from the list
- Configure template parameters
- Click on Save
Ordering Steps
The order of deployment steps is important:
- Drag steps to desired position
- Or use arrow buttons to change order
- Save the order
Common Order:
- Create backup
- Stop current application
- Download new version
- Run database migrations
- Clear cache
- Start application
- Run health check
Step Configurations
Script Execution
Bash (Linux/Mac):
#!/bin/bash
# Health check
curl -f http://localhost:3000/health || exit 1
echo "Health check passed"PowerShell (Windows):
# Stop application
Stop-Service -Name MyAppEnvironment Variables
Deployment steps have access to environment variables:
$VERSION- The version being deployed$APP_NAME- Name of the application$PROJECT_NAME- Name of the project$ENVIRONMENT_NAME- Name of the environment$DEPLOYMENT_ID- Unique ID of this deployment
Example:
#!/bin/bash
echo "Deploying version $VERSION to $ENVIRONMENT_NAME"
echo "Application: $APP_NAME"
echo "Project: $PROJECT_NAME"Error Handling
Configure what should happen on an error:
- Continue - Proceed to next steps
- Stop - Stop the deployment and mark as failed
- Retry - Try the step again
Monitoring and Logs
Step Progress
During deployment, you see the progress of each step:
- Pending - The step is waiting to execute
- In Progress - The step is being executed
- Success - The step completed successfully
- Failed - The step failed
Log Output
Each step generates log output:
- Standard output from the script
- Error messages if present
- Timestamp of each step
View the logs in the deployment details page to see what happened.
Best Practices
Atomic Steps
Keep each step simple and independent as possible:
- One task per step
- No complex logic in a single step
- Easier to debug
Idempotency
Make sure steps are repeatable:
- Can run multiple times without causing damage
- Check if something already exists before creating it
- Use conditional logic
Timeouts
Set timeouts for each step:
- Prevent infinite wait times
- Error on timeout
- Proceed to next step or stop the deployment
Use Cases
Database Migrations
For applications with databases:
Step 1 - Backup:
#!/bin/bash
pg_dump $DATABASE_URL > backup.sqlStep 2 - Migrate:
#!/bin/bash
npm run migrateStep 3 - Verify:
#!/bin/bash
# Check if database schema is correct
npm run verify-dbHealth Checks
After deployment, verify that application is running:
#!/bin/bash
# Wait 30 seconds
sleep 30
# Try 5 times to connect
for i in {1..5}; do
if curl -f http://localhost:3000/health; then
echo "Application is healthy"
exit 0
fi
echo "Retrying... ($i/5)"
sleep 10
done
echo "Health check failed"
exit 1Cache Invalidation
Clear cache after deployment:
#!/bin/bash
# Redis cache
redis-cli FLUSHALL
# Or for memcached
echo "flush_all" | nc localhost 11211Troubleshooting
Step Failed
If a deployment step fails:
- View the logs of the specific step
- Check the script for syntax errors
- Verify that all required tools are available
- Test the step manually on the server
- Adjust the step and deploy again
Timeouts
If steps timeout:
- Check if the step needs more time
- Increase the timeout for the step
- Or split the step into multiple smaller steps
Advanced Features
Dependencies
Configure that certain steps only run if earlier steps succeeded:
- Automatically handled by deployment orchestrator
- Failed steps stop further execution
Parallel Execution
Some steps can be executed in parallel:
- Configure if a step can run in parallel
- Speed up deployments by executing independent tasks together
Conditional Execution
Execute steps only under certain conditions:
- Environment-specific steps
- Version-specific steps
- Based on variables or configurations