People strive for the path of least resistance, and when they do, steps get missed and things go wrong. I've found that if you want a task completed in a specific way, you must make it easier and more beneficial to do it that way than any other way. Luckily we have tools to make the our tasks easy to complete.
In this post I'll talk about two ways to automate complex tasks using git and Fabric. I won't cover the intricacies of doing the scripting. Instead I'll cover what should or could be scripted to make your processes consistent and easy.
When my team was switching from Subversion to git several years ago, we discovered that typing
git mycommand will try to execute
git-mycommand. Even though I can't find any documentation for this behavior, trust me, it works.
We recognized that some of the steps of our workflow were quite long. We wanted quite a few things done, and chances are people would forget steps. Plus, if at some point we decided to change the process slightly, re-training would be required.
So, we created a set of bash commands to automate our procedures, and fix common mistakes.
This made training easier. The basic workflow was:
git start-branch <branchname>or
git pull-branch <branchname>depending on if you were working on a new feature or modifying something someone else started.
- Do your work and use
git push-branch <branchname>to move (or update) the branch on the server.
- When the branch was done, run
git finish-branch <branchname>.
That made training easy because with six commands, anyone could maintain our workflow. It was also easier to use these commands, even for git experts, because each command typically encapsulated more than one command.
How did you get the commands on their computers?
Good question! The commands are kept in a public repository. They had to execute two commands:
git clone <repo url>wherever they wanted to keep the code
cd <repo directory>
Updating the commands only required:
cd <repo directory>
And chances are we could have simplified that whole process too, but there wasn't a need.
Scripting processes with Fabric
Would it surprise you that all one must do to deploy changes to our production servers is run the command
fab update? Fabric makes training new developers to our procedures easy. Besides the scripts for managing test instances, discussed in an earlier post, we have scripts for:
- Pushing a SSH key to a server
- Updating the production servers
- Creating a database
With these scripts we have made processes that we do very rarely (pushing a key to a server and creating a database) easy to remember, and make complicated procedures (updating the production servers) consistent for anyone to do.
Where are your pain points?
How to tell you need a script:
- You inwardly sigh when you have to do a task
- You have to search the internet for the way to do a task that you only did a couple times before
- You have to refer to a cheat sheet any time you have to complete a certain task
- You don't trust anyone to do certain tasks because they are easy to screw up
- People keep doing certain tasks wrong
Scripting your workflows and tasks will make your life and that of your team better.