Skip to main content

Common commands for deployment on a VPS.

Project description

This is a base set of Fabric deployment functions for projects based on Django, Nginx, uWSGI Emperor, Memcached and PostgreSQL. Both Fabric 2 and legacy Fabric 1 systems are supported.

Fabric is a handy tool for automating deployment processes. Unlike Salt or Ansible, you’re writing code from the beginning rather than diving into a Turing Tarpit of templated YAML. Also unlike Salt, Ansible or shell scripts, Fabric neatly coordinates both local and remote SSH tasks. While Fabric may not be your best choice for provisioning, it works well as a simple and flexible tool for automatic custom workflows.

Installation (Fabric 2.*)

If Fabric 2 is available as an operating system package:

$ sudo apt install fabric invoke
$ pip install --user vps-deploy


$ pip install --user fabric invoke vps-deploy

Legacy installation for Fabric 1.*

Fabric 1.* is recommended only for supporting existing projects. For new projects, use Fabric 2.*.

Since Fabric 1.* is Python 2-only and you’re probably using a Python 3 virtual env, you’ll need to install Fabric and VPS Deploy as a –user package:

# System package for Fabric, user package for vps-deploy:
$ sudo apt install fabric
$ pip install --user vps-deploy

# All in user packages:
$ pip install --user fabric~=1.14 vps-deploy

Alternately, while Fabric 1.* remains available for some operating systems, you could also install it that way.

Getting started

To get started, create a in your top-level project directory. It might look something like this:

from fabric import task
from invoke.collection import Collection

from vps_deploy import django_fabric2 as df2

hosts = ['']

def deploy(c):
        # Sentry needs access to Git repo.
            '.git', 'deploy', 'env', 'project'],
        read_write=['project', 'project/collected_static/CACHE'],

ns = Collection(
    task(df2.download_postgres_db, hosts=hosts),
    task(df2.mirror_postgres_db, hosts=hosts),
    task(df2.mirror_media, hosts=hosts),
    # Built-in Fabric config.
    'run': {
        'echo': True,
        # Needed so local commands work. Can also use FABRIC_RUN_REPLACE_ENV.
        'replace_env': False,
        # Needed for Guix. Can also use FABRIC_RUN_SHELL.
        # 'shell': '/run/current-system/profile/bin/bash',

    # Our custom project config.
    'env': {
        'branch': 'master',
        'app_user': 'www-data',
        'db_name': 'exampledb',
        'project_dir': '/srv/exampleproject',
        'media_dir': 'project/media',
        'virtualenv': '/srv/venvs/exampleproject-django-py38',
        'site_name': 'examplesite',
        'requirements': 'requirements/production.txt',
        'settings': '',
        'uwsgi_conf': 'deploy/uwsgi.ini',
        'nginx_conf': 'deploy/nginx.conf',
        'python': '/usr/bin/python3.8',


To make a deployment:

fab –prompt-for-sudo-password deploy

This depends on a few things being already set up, such as SSH access to the server and having the server-site software and accounts set up. Those tend to to be better handled with configuration management tools like Salt or Ansible (and potentially triggered by Fabric!).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vps-deploy-0.4.10.tar.gz (10.8 kB view hashes)

Uploaded source

Built Distribution

vps_deploy-0.4.10-py3-none-any.whl (23.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page