How to deploy an application with Bolt
You've been iterating on some code and finally have that new feature working. You submit a Pull Request, there are a few comments that you address quickly then the PR gets merged. What happens next? It's time for deployment. Read on if you're interested in learning how Bolt can be used to deploy your application.
Why do we use Bolt?
If you don’t know what Bolt is, it’s a lighting-fast way to start automating your infrastructure in an agentless way. We use Bolt to automate how we deploy applications, patch systems, and plenty of other tasks that we want to automate at scale without too much fuss.
Onto the code
Before we get started showing off the Bolt code, we should probably go over
what our application is. We use a tool called StackStorm for orchestrating our automation workflows. StackStorm is an event-driven automation platform that we use to integrate the best-of-breed tools across the DevOps landscape. These integrations are possible using StackStorm's plugin mechanism called packs (short for Packages). Packs are Git repos that contain code written in a variety of different languages:
Python, anything executable, and Orquesta workflows (YAML).
Actions are pieces of code that can perform arbitrary automation or remediation tasks in your environment. They can be written in any programming language to do just about anything such as making API calls or invoking external tools like Bolt, Puppet, Terraform, Packer, etc.
When an action invokes an external tool, it is necessary to deploy the tool-specific code alongside a pack. Here are a few examples of external tools we use and where the code for those tools gets deployed:
- Puppet/Bolt (
- Terraform (
- Packer (
- Many others are available, check out the StackStorm Exchange
From a high-level, pack deployment consists of the following steps:
- Clone Git repos
- Create a deployment archive
- Copy the archive to the StackStorm host
- Extract the archive
- Put automation code in its proper spot
- Register packs with StackStorm
There are two nodes in this process, the Bolt control node where the deployment is triggered from and the StackStorm node(s) that the code will be deployed to. Our Bolt control node is either our Jenkins server or a developers laptop. The Bolt plan is initiated from the control node where it does some prep work, copies the files over to the StackStorm nodes, and then performs the deployment steps on those nodes.
Cloning Git repos
In order for us to deploy code, we need to have the code first. Logically, the first step in the process is cloning all of the Git repos we need for our deployment. These Git repos contain code for interacting with other tools such as Puppet, Bolt, Terraform, Packer, etc. Cloning the repos is accomplished using the following plan:
In this plan we utilize the vcsrepo forge module
in an apply block. This saves us the hassle of having to artisanally craft the correct
command. You may ask why we love Bolt? It's because we can reuse all of the awesome modules
from the Forge!
This code clones our Git repos on our Bolt control node, in the
extern/ directory, and now
we have all of the code needed to perform a deployment.
Creating an archive
Next we need to archive all of the various files we need for the deployment:
This plan uses
git ls-files to list all of the files in our repo (all of the StacKStorm Packs)
and combines it with all of the external tool code that we cloned into the
The files list is then used to create a
.tar.gz archive in the
Copy the archive
The archvie now needs to make its way to the StackStorm nodes, to do this we utilize the built-in
Extract the archive
Extracting the archive is as simple as running a
Place automation code in its proper spot
Next we need to put the code for our external different tools in the correct directories so those tools can utilize them affectively. We do this using symlinks. Alternatively we could copy the code into the desired directory.
For Puppet/Bolt code we create a symlink from
For Packer code we create a symlink from
Register packs with StackStorm
In the final step of our deployment we need to move the StackStorm pack code into
the directory where StackStorm expects (
/opt/stackstorm/packs), then register the packs
(StackStorm loads the data from the filesystem into its database) and finally setup a Python
virtualenv for each pack:
For copying the code we again utilize an
apply block with a
file resource to copy
the pack's code from
/opt/stackstorm/packs. Next we
st2 pack register command to load all of the Pack information from the filesystem
into the StackStorm database. Finally we run the
st2 run packs.setup_virtualenv action
to create a Python
virtualenv for each pack.
Try deploying an application with Bolt
Bolt is an amazing tool with a ton of use cases. In this post we've demonstrated how the
DevOps team at Encore Technologies utilizes Bolt to package and deploy our automation code
to StackStorm hosts. If you're inspired by what you've seen here you can get started with
Bolt by checking out the documentation.
Sometimes documentation doesn't answer all of your questions, or maybe you just need to
talk to a real person, in this case come visit the
Puppet Slack. We'll be hanging out in the
Nick Maludy is the DevOps Manager at Encore Technologies.