Automate, automate, automate.
Automating deployment is critical for our staging tests to mean anything. By making sure the deployment procedure is repeatable, we give ourselves assurances that everything will go well when we deploy to production. (These days people sometimes use the words “infrastructure as code” to describe automation of deployments, and provisioning.)
Fabric is a tool which lets you automate commands that you want to run on servers. “fabric3” is the Python 3 fork:
$ pip install fabric3
It’s safe to ignore any errors that say “failed building wheel” during the Fabric3 installation, as long as it says “Successfully installed…” at the end.
The usual setup is to have a file called fabfile.py, which will
contain one or more functions that can later be invoked from a command-line
fab, like this:
That will call
function_name, passing in a connection to the server at
SERVER_ADDRESS. There are lots of other options for specifying usernames and
passwords, which you can find out about using
best way to see how it works is with an example.
I made earlier, automating all the deployment steps we’ve been going through.
The main function is called
deploy; that’s the one we’ll invoke from the command line. It then calls out to several helper functions, which we’ll build together one by ...