This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

fabricio

Project Description

Fabricio is a Docker deploy automation tool used along with the Fabric.

Features

  • build Docker images
  • create containers and services from images with provided tags
  • unlimited infrastructures
  • Fabric’s parallel execution mode compatibility
  • rollback containers or services to previous version
  • public and private Docker registries support
  • tasks groups
  • migrations apply and rollback
  • data backup and restore
  • DB master-slave configurations support
  • (NEW) Docker Swarm mode (Docker 1.12+)

See changelog for detailed info.

Basic example

The most basic fabfile.py you can use with the Fabricio is something like this:

from fabricio import docker, tasks


nginx = tasks.DockerTasks(
    service=docker.Container(
        name='nginx',
        image='nginx:stable',
        options={
            'publish': '80:80',
        },
    ),
    hosts=['user@example.com'],
)

Type fab --list in your terminal to see available Fabric commands:

Available commands:

    nginx           full service deploy (prepare -> push -> upgrade)
    nginx.deploy    full service deploy (prepare -> push -> upgrade)
    nginx.rollback  rollback service to a previous version (migrate-back -> revert)
    nginx.upgrade   upgrade service to a new version (backup -> pull -> migrate -> update)

Finally, to deploy such configuration you simply have to execute following bash command:

fab nginx

To display detailed info about command (including available options) use following command: fab --display <command>.

See also Fabricio examples and recipes.

Requirements

Local

  • Python 2.6 or 2.7
  • Fabric 1.x
  • (optional) Docker 1.9+ for building Docker images

Remote

  • sshd
  • Docker 1.9+
  • (optional) Docker 1.12+ for using Docker in Swarm mode

Install

pip install --upgrade fabricio

For system-wide installation macOS users should explicitly provide versions of ‘six’ and ‘setuptools’ packages installed on their system. For example:

sudo pip install --upgrade fabricio six==1.4.1 setuptools==18.5

Roles and infrastructures

You can define as many roles and infrastructures as you need. The following example shows ‘production’ and ‘staging’ configurations for two-roles deploy configuration:

from fabric import colors, api as fab
from fabricio import docker, tasks


@tasks.infrastructure
def staging():
    fab.env.roledefs.update(
        balancer=['user@staging.example.com'],
        web=['user@staging.example.com'],
    )


@tasks.infrastructure(color=colors.red)
def production():
    fab.env.roledefs.update(
        balancer=['user@balancer.example.com'],
        web=['user@web1.example.com', 'user@web2.example.com'],
    )

balancer = tasks.DockerTasks(
    service=docker.Container(
        name='balancer',
        image='registry.example.com/nginx:balancer',
        options={
            'publish': ['80:80', '443:443'],
            'volume': '/etc/cert:/etc/cert:ro',
        },
    ),
    roles=['balancer'],
)

web = tasks.DockerTasks(
    service=docker.Container(
        name='web',
        image='registry.example.com/nginx:web',
        options={
            'publish': '80:80',
            'volume': '/media:/media',
        },
    ),
    roles=['web'],
)

Here is the list of available commands:

Available commands:

    production          select production infrastructure to run task(s) on
    production.confirm  automatically confirm production infrastructure selection
    staging             select staging infrastructure to run task(s) on
    staging.confirm     automatically confirm staging infrastructure selection
    balancer            full service deploy (prepare -> push -> upgrade)
    balancer.deploy     full service deploy (prepare -> push -> upgrade)
    balancer.rollback   rollback service to a previous version (migrate-back -> revert)
    balancer.upgrade    upgrade service to a new version (backup -> pull -> migrate -> update)
    web                 full service deploy (prepare -> push -> upgrade)
    web.deploy          full service deploy (prepare -> push -> upgrade)
    web.rollback        rollback service to a previous version (migrate-back -> revert)
    web.upgrade         upgrade service to a new version (backup -> pull -> migrate -> update)

‘production’ and ‘staging’ are available infrastructures here. To deploy to a particular infrastructure just provide it before any other Fabric command. For example:

fab staging balancer web

Tags

Almost every Fabricio command takes optional argument ‘tag’ which means Docker image tag to use when deploying container or service. For instance, if you want to deploy specific version of your application you can do it as following:

fab app.deploy:v1.2

By default, value for tag is taken from Container/Service Image.

Rollback

To return container or service to a previous version execute command fab app.rollback.

Forced update

fab app.update:force=yes

force=yes is used to force container or service update.

Private Docker registry

It is often when production infrastructure has limited access to the Internet or your security policy does not allow using of public Docker image registries. In such case Fabricio offers ability to use private Docker registry which can be used also as an intermediate registry for the selected infrastructure. To use this option you have to have local Docker registry running within your LAN and also Docker client on your PC. If you have Docker installed you can run up Docker registry locally by executing following command:

docker run --name registry --publish 5000:5000 --detach registry:2

When your local Docker registry is up and run you can provide custom registry which will be used as an intermediate Docker registry accessed via reverse SSH tunnel:

from fabricio import docker, tasks

nginx = tasks.DockerTasks(
    service=docker.Container(
        name='nginx',
        image='nginx:stable',
        options={
            'publish': '80:80',
        },
    ),
    registry='localhost:5000',
    ssh_tunnel_port=5000,
    hosts=['user@example.com'],
)

Note, that you can provide custom registry and/or account within ‘image’ parameter like this:

image='custom-registry.example.com/user/image:tag'

List of commands in this case updated with additional two commands:

nginx.prepare   build Docker image
nginx.push      push built Docker image to the registry

The first one pulls Image from the original registry and the second pushes it to the local registry which is used as main registry for all configuration’s infrastructures.

Building Docker images

Using Fabricio you can also build Docker images from local sources and deploy them to your servers. This example shows how this can be set up:

from fabricio import docker, tasks

app = tasks.ImageBuildDockerTasks(
    service=docker.Container(
        name='app',
        image='your_docker_hub_account/app',
    ),
    hosts=['user@example.com'],
    build_path='src',
)

Commands list for ImageBuildDockerTasks is same as for DockerTasks with provided custom registry. The only difference is that ‘prepare’ builds image instead of pulling it from the original registry.

And of course, you can use your own private Docker registry:

from fabricio import docker, tasks

app = tasks.ImageBuildDockerTasks(
    service=docker.Container(
        name='app',
        image='app',
    ),
    registry='registry.your_company.com',
    hosts=['user@example.com'],
    build_path='src',
)

Docker services (swarm mode)

Fabricio also can work with Docker services AKA (Also Known As) swarm mode (Docker 1.12+):

from fabricio import docker, tasks

nginx = tasks.DockerTasks(
    service=docker.Service(
        name='nginx',
        image='nginx:stable',
        options={
            'publish': '8080:80',
            'replicas': 3,
        },
    ),
    hosts=['user@manager'],
)
Release History

Release History

This version
History Node

0.3.24

History Node

0.3.23

History Node

0.3.22

History Node

0.3.21

History Node

0.3.20

History Node

0.3.19

History Node

0.3.18

History Node

0.3.17

History Node

0.3.16

History Node

0.3.15

History Node

0.3.14

History Node

0.3.12

History Node

0.3.11

History Node

0.3.10

History Node

0.3.9

History Node

0.3.8

History Node

0.3.7

History Node

0.3.6

History Node

0.3.1

History Node

0.3

History Node

0.2.17

History Node

0.2.16

History Node

0.2.14

History Node

0.2.13

History Node

0.2.12

History Node

0.2.11

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2

History Node

0.1.17

History Node

0.1.16

History Node

0.1.15

History Node

0.1.14

History Node

0.1.13

History Node

0.1.12

History Node

0.1.11

History Node

0.1.10

History Node

0.1.9

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
fabricio-0.3.24.tar.gz (24.0 kB) Copy SHA256 Checksum SHA256 Source Mar 8, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting