Package: fabricio
Fabricio is aDockerdeploy automation tool used along with theFabric.Featuresbuild Docker imagescreate containers and services from images with provided tagsunlimited infrastructuresFabric’s parallel execution mode compatibilityrollback containers or services to previous versionpublic and private Docker registries supportdeploy over SSH tunnel (e.g. access to image registry, proxy, etc.)migrations apply and rollbackdata backup and restoreDocker services (Swarm mode)Docker stacks (Docker Compose 3.0+)Kubernetes configurationsSeechangelogfor detailed info.Basic exampleThe most basicfabfile.pyyou can use with the Fabricio may look something like this:fromfabricioimportdocker,tasksapp=tasks.DockerTasks(service=docker.Container(name='app',image='nginx:stable-alpine',options={'publish':'80:80',},),hosts=['user@example.com'],)Typefab --listin your terminal to see available Fabric commands:Available commands:

    app.deploy  deploy service (prepare -> push -> backup -> pull -> migrate -> update)Finally, to deploy such configuration you simply have to execute following bash command:fabapp.deploySee also Fabricioexamples and recipes.RequirementsLocalPython 2.7, 3.4*, 3.5*, 3.6*, 3.7*, 3.8*(optional) Docker 1.9+ for building Docker images*Fabric3is used for compatibility with Python 3.xRemotesshdDocker 1.9+Docker 1.12+ for using Docker servicesInstallpipinstallfabricioNote for macOS usersBecause of Python 2 on macOS marked as system component you can’t upgrade its modules which are trying to be upgraded during the Fabricio install (e.g.sixandsetuptools). Instead, you can try to install last version of Python 2 usingHomebrew:brewinstallpython2and then:pip2installfabricioContributeAll proposals and improvements are welcomed through apull requestorissue. Just make sure all tests are running fine.Install test dependenciespipinstall.[test]Running testspython-munittest2discovertests--verboseRoles and infrastructuresYou can define as many roles and infrastructures as you need. The following example shows ‘production’ and ‘test’ configurations for two-roles deploy configuration:fromfabricimportcolors,apiasfabfromfabricioimportdocker,tasks,infrastructure@infrastructuredeftesting():fab.env.roledefs.update(api=['user@testing.example.com'],web=['user@testing.example.com'],)@infrastructure(color=colors.red)defproduction():fab.env.roledefs.update(api=['user@api1.example.com','user@api2.example.com'],web=['user@web.example.com'],)web=tasks.DockerTasks(service=docker.Container(name='web',image='registry.example.com/web:latest',options={'publish':['80:80','443:443'],'volume':'/media:/media',},),roles=['web'],)api=tasks.DockerTasks(service=docker.Container(name='api',image='registry.example.com/api:latest',options={'publish':'80:80',},),roles=['api'],)Here is the list of available commands:Available commands:

    production  select production infrastructure, 'production.confirm' skips confirmation dialog
    testing     select testing infrastructure, 'testing.confirm' skips confirmation dialog
    api.deploy  deploy service (prepare -> push -> backup -> pull -> migrate -> update)
    web.deploy  deploy service (prepare -> push -> backup -> pull -> migrate -> update)‘production’ and ‘testing’ are available infrastructures here. To deploy to a particular infrastructure just provide it before any other Fabric command(s). For example:fabtestingapi.deployweb.deploySeeInfrastructures and rolesexample for more details.TagsAlmost 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:fabapp.deploy:release-42By default, value for tag is taken from Container/Service Image.Also it is possible to completely (and partially) replace registry/account/name/tag/digest of image to deploy:fabapp.deploy:registry.example.com/registry-account/app-image:release-42fabapp.deploy:nginx@sha256:36b0181554913b471ae33546a9c19cc80e97f44ce5e7234995e307f14da57268RollbackTo return container or service to a previous state execute this command:fabapp.rollbackIdempotencyFabricio always tries to skip unnecessary container/service update. However, update can be forced by addingforce=yesparameter:fabapp.deploy:force=yesPrivate Docker registryIt 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:dockerrun--nameregistry--publish5000:5000--detachregistry:2When your local Docker registry is up and run you can provide customregistrywhich will be used as an intermediate Docker registry accessed via reverse SSH tunnel:fromfabricioimportdocker,tasksapp=tasks.DockerTasks(service=docker.Container(name='app',image='nginx:stable-alpine',options={'publish':'80:80',},),registry='localhost:5000',ssh_tunnel='5000:5000',hosts=['user@example.com'],)SeeHello Worldexample for more details.Building Docker imagesUsing 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:fromfabricioimportdocker,tasksapp=tasks.ImageBuildDockerTasks(service=docker.Container(name='app',image='registry.example.com/registry-account/app-image:latest-release',),hosts=['user@example.com'],build_path='.',)By executing commandapp.deployFabricio will try to build image usingDockerfilefrom the folder provided bybuild_pathparameter. After that image will be pushed to the registry (registry.example.com in the example above). And deploy itself will start on the last step.SeeBuilding Docker imagesexample for more details.Docker servicesFabricio can deploy Docker services:fromfabricioimportdocker,tasksservice=tasks.DockerTasks(service=docker.Service(name='my-service',image='nginx:stable',options={'publish':'8080:80','replicas':3,},),hosts=['user@manager'],)SeeDocker servicesexample for more details.Docker stacksDocker stacks are also supported (available since Docker 1.13):fromfabricioimportdocker,tasksstack=tasks.DockerTasks(service=docker.Stack(name='my-docker-stack',options={'compose-file':'my-docker-compose.yml',},),hosts=['user@manager'],)SeeDocker stacksexample for more details.Kubernetes configurationKubernetes configuration can be deployed using following settings:fromfabricioimportkubernetes,tasksk8s=tasks.DockerTasks(service=kubernetes.Configuration(name='my-k8s-configuration',options={'filename':'configuration.yml',},),hosts=['user@manager'],)SeeKubernetes configurationexample for more details.