Hooks
Hooks allow you to run custom scripts at specific points during deployment.
Available Hooks
| Hook | Location | Timing |
|---|---|---|
pre-build | CI runner | Before Docker images are built |
post-build | CI runner | After Docker images are built |
pre-deploy | Server | Before Swarm stack deployment |
post-deploy | Server | After successful deployment |
Setup
Create shell scripts in .deployment/hooks/:
- pre-build.sh
- post-build.sh
- pre-deploy.sh
- post-deploy.sh
All hooks are optional. If a hook file doesnāt exist, it is skipped.
Jinja2 Templating
Hooks are rendered with Jinja2 before execution. You can use any Ansible variable:
#!/bin/bash
echo "Deploying {{ project_name }} version {{ version }} to {{ env }}"
# Access environment variables
DATABASE_URL="{{ lookup('env', 'DATABASE_URL') }}"Examples
Pre-build: Generate assets
#!/bin/bash
echo "Generating static assets..."
npm run build:assetsPost-build: Security scan
#!/bin/bash
echo "Running security scan..."
docker scan {{ project_name }}:{{ version }} || truePre-deploy: Database backup
#!/bin/bash
echo "Creating database backup before deployment..."
pg_dump $DATABASE_URL > /backups/pre-deploy-{{ version }}.sqlPost-deploy: Notify team
#!/bin/bash
curl -X POST "https://hooks.slack.com/services/xxx" \
-H "Content-Type: application/json" \
-d '{"text":"Deployed {{ project_name }} {{ version }} to {{ env }}"}'Configuration
Hooks are enabled by default. Configure in .deployment/config.yml:
hooks:
enabled: true # Enable/disable all hooks (default: true)
timeout: 300 # Timeout per hook in seconds (default: 300)If a hook fails, the deployment continues with a warning. Hooks do not block deployments.