I'm already a developer

Happy Deploy Life with Fabric

Today I will explain how to use Fabric for deploy.

What is Fabric

Fabric is

  • A tool to execute arbitrary Python function via the command line.
  • A library of subroutines (built on low-level libraries) easily via SSH and execute Python-like shell command.

Fabric can automate the deployment work. You do not have to manually access and work on the server each time. For example, I wrote a file that created a method called yum_update as shown below.

And then, you can use this file like a following command.

Setting for Fabric

In the above command, We can run the command by specifying the user name, secret key of ssh, host name. However, they can also be written on a file. This time, what I made for my server is as follows.

Here is the point.

env.hosts = ['host name']
env.user = 'user name'
env.key_filename = 'key file path'

And then, you can use a following command. It is simple.

fab [execute method]

To explain this file a little. You can see that lcd() and local() are used for local processing. We are sending files on the remote server with put(). To run the command on the remote server, use run().

Deployment Automation happiness

We can leave the deployment process with this Fabric.

fab deploy

This command is just simple. It is very convenient. Everyone can spend a happy deployment life by using Fabric :)