Engineering
Feature Spotlight: Streamlining Post-Deployment with Aptible's After-Success and After-Failure Hooks
Mario de la Ossa
Engineering
Aptible has expanded its deployment capabilities with new after-success and after-failure hooks, providing developers with more control over what happens after key deployment operations. Whether you're deploying, restarting, configuring, or scaling, these hooks allow you to automate custom tasks based on the success or failure of these operations.
These hooks are added to your .aptible.yml file, and they run after specific operations like deploy, restart, configure, and scale. The success hooks trigger when the operation is confirmed to be successful, such as after your Release Containers are up and healthy. Conversely, the failure hooks run when an operation fails and needs to be rolled back. These hooks are executed in an isolated, ephemeral container directly on your container image, which gives you the full power you need to automate tasks.
Practical Use Cases
Notifying Teams After a Successful Deployment
If you want to notify your team once a deployment succeeds, you can use the after_deploy_success hook. For example, you could send a Slack notification with a simple one-liner using curl:
Cleaning Up Resources After a Failed Restart
To automate the cleanup of resources or alerting relevant teams after a restart failure, use the after_restart_failure hook, feeding it any command your image understands, be it a bash script, python, ruby, or anything else you've added to your image:
Perhaps a PagerDuty notification?
Custom Scaling Logic
If you have specific logic that should run after a successful scaling operation, the after_scale_success hook can automate this:
Updating Your Hooks
To integrate these hooks into your deployment process, simply add them to your .aptible.yml
file. The hooks will take effect the next time you initiate a deploy. This allows you to continuously refine and automate your deployment workflows, ensuring that your operations are both resilient and efficient.
Aptible’s after-success and after-failure hooks give you powerful tools to automate and customize your app management. By leveraging these hooks, you can ensure your application responds dynamically to the outcomes of critical operations, reducing manual overhead and improving reliability. Whether it's sending a Slack notification, cleaning up resources, or executing custom scripts, these hooks make your deployments more adaptable and efficient.