• Stars
    star
    116
  • Rank 297,839 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created over 11 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elegant deployment with Fabric and Puppet.

Loom

Build Status

Elegant deployment with Fabric and Puppet.

Loom does the stuff Puppet doesn't do well or at all: bootstrapping machines, giving them roles, deploying Puppet code and installing reusable Puppet modules. It's useful for both serverless and master/agent Puppet installations.

It also includes some Fabric tasks for building and uploading app code โ€“ย something that is particularly complex to do with Puppet.

Install

$ sudo pip install loom

Getting started

First of all, you create fabfile.py and define your hosts:

from fabric.api import *
from loom import puppet
from loom.tasks import *

env.user = 'root'
env.environment = 'prod'
env.roledefs = {
    'web': ['prod-web-1.example.com', 'prod-web-2.example.com'],
    'db': ['prod-db-1.example.com'],
}

You can then define any third-party Puppet modules you want in a file called Puppetfile:

forge "http://forge.puppetlabs.com"
mod "puppetlabs/nodejs"
mod "puppetlabs/mysql"

(This is for librarian-puppet, a tool for installing reusable Puppet modules. It can also install from Git, etc.)

Your own modules are put in a directory called modules/ in the same directory as fabfile.py. Roles are defined in a magic module called roles which contains manifests for each role. (If you've used Puppet before, this is a replacement for node definitions.)

For example, modules/roles/manifests/db.pp defines what the db role is:

class roles::db {
  include mysql
  # ... etc
}

And that's it!

Let's set up a database server. First, bootstrap the host (in this example, the single db host you defined in env.roledefs):

$ fab -R db puppet.install

Then install third party Puppet modules, upload your local modules, and apply them:

$ fab -R db puppet.update puppet.apply

Every time you make a change to your modules, you can run that command to apply them. Because this is just Fabric, you can write a task in fabfile.py to do it too:

@task
def deploy_puppet():
    execute(puppet.update)
    execute(puppet.apply)

Then you could use the included "all" task to update Puppet on all your hosts:

$ fab all deploy_puppet

Apps

Loom includes a bunch of Fabric tasks for building and uploading code. It assumes you've set up a role for the app (e.g., "web"), and that role has all of the packages you require and an Upstart init script to start the app.

Apps in Loom are configured using env.apps. It is a dictionary where the key is the name of the app and the value is a dictionary with these keys:

  • repo (required): A Git URL of the repo that contains your app.
  • role (required): The role that the app will be uploaded to.
  • build: A script to run locally before uploading (e.g. to build static assets or install local dependencies).
  • post-upload: A script to run on each server after uploading.
  • init: The name of the Upstart script to start/restart after uploading.

You must also define a directory for your apps to live in with env.app_root.

For example, suppose this was your fabfile.py:

from fabric.api import *
from loom import app, puppet
from loom.tasks import *

env.user = 'root'
env.environment = 'prod'
env.roledefs = {
    'web': ['prod-web-1.example.com', 'prod-web-2.example.com'],
    'db': ['prod-db-1.example.com'],
}
env.app_root = '/home/ubuntu'
env.apps['web'] = {
    "repo": "https://user:[email protected]/mycompany/mycompany-web.git",
    "role": "web",
    "build": "script/build",
    "init": "web",
}

You then need a modules/roles/manifests/web.pp that sets up /etc/init/web.conf to run your app in /home/ubuntu/web.

To deploy your app, run:

$ fab app.deploy:web

This will:

  1. Pull your GitHub repository locally.
  2. Run script/build.
  3. Upload your code to /home/ubuntu/web on both prod-app-1.example.com and prod-app-2.example.com.
  4. Run sudo restart web.

OS support

It's only been tested on Ubuntu 12.04. I would like to support more things. Send patches!

API

Look at the source for now. It's all Fabric tasks, and they're pretty easy to read. (Sorry.)

Running the tests

$ pip install -r dev-requirements.txt
$ script/test

Contributors

More Repositories

1

jsnes

A JavaScript NES emulator.
JavaScript
5,921
star
2

jsnes-web

A browser UI for JSNES, a JavaScript NES emulator
JavaScript
569
star
3

django-shorturls

A URL shortening app for Django
Python
405
star
4

serverless-docker

Build serverless apps with Docker
305
star
5

funker

Functions as Docker containers
252
star
6

dynamicaudio.js

An interface for the Web Audio API with a Flash shim for older browsers
JavaScript
168
star
7

whiskerboard

Stashboard, now with less vendor lock-in.
Python
112
star
8

otter

A server that runs your client-side apps.
CoffeeScript
82
star
9

django-class-based-views

Work on class-based views, now part of Django 1.3. For a backport to Django 1.2, see https://github.com/sorl/django-cbv
Python
79
star
10

serverless-docker-voting-app

A serverless web app built with Docker
HTML
60
star
11

naming-test-suite

How I name products/projects/tools
39
star
12

vNES

A mirror of Jamie Sanders' Java NES emulator, which once lived at virtualnes.com
Java
36
star
13

django-docker-heroku-template

Get a Django app up and running in dev, test, and production with best practices in 10 minutes
Python
35
star
14

python-echoprint

Python library for the Echoprint music identification service
C++
27
star
15

dockerrun

A dead simple Python library for running Docker commands
Python
25
star
16

funker-example-voting-app

An example app using Funker
JavaScript
24
star
17

pspec

Python testing for humans.
Python
21
star
18

syndication-view

Django feeds as class based views, now part of Django 1.2.
Python
21
star
19

pytest_django

A Django plugin for py.test.
Python
19
star
20

django-database-files

A storage system for Django that stores uploaded files in the database.
Python
19
star
21

docker-export-volumes

A Docker image to export volumes from containers
Python
16
star
22

go-dcgi

CGI, but with Docker containers
Go
13
star
23

django-docker-cloud-template

A template for creating Django applications that run on Docker Cloud
Python
12
star
24

funker-go

Funker for Go
Go
12
star
25

heroku-tarsnap-backups

Make offsite backups of Heroku apps on Tarsnap
Shell
11
star
26

django-mptt

It's MPTT, but with abstract model awesomeness.
Python
11
star
27

docker-redoc

A Docker image which serves ReDoc documentation
HTML
11
star
28

funker-python

Python
9
star
29

swarm-viz

HTML
9
star
30

miles

A JavaScript framework for actually getting things done
JavaScript
8
star
31

dotfiles

Vim Script
8
star
32

virtualdocker

Go
8
star
33

docker-reticulate-splines

Shell
7
star
34

herokup

Upload stuff to Heroku that isn't in Git.
Shell
7
star
35

funker-node

JavaScript
7
star
36

jstunes

A JavaScript audio player
JavaScript
7
star
37

rrun

rsync the current directory and run a command over ssh
Shell
6
star
38

docker-sdk-go

WIP: Prototype of a better Go client for Docker
Go
5
star
39

fir.sh

SCSS
5
star
40

paperpets

Mini origami pets for Little Printer
CSS
5
star
41

jsnes-roms

4
star
42

charingcross

Project planning with GitHub issues
Python
4
star
43

docker-api-reference

WIP: Better API reference for Docker, built on Swagger
HTML
3
star
44

docker-go-client-example

Go
3
star
45

vqgan-clip

Python
3
star
46

antsy

Multi-line console animation in Go
Go
2
star
47

cog-segformer

Python
2
star
48

ip

Python
2
star
49

backbone-otter

Tools for writing Otter apps with Backbone
JavaScript
2
star
50

puppet-cloudkick

A Puppet module for Cloudkick.
Shell
2
star
51

haikuplayer

Python
2
star
52

docker-sdk-python

WIP
Python
2
star
53

riffusion-cog

Riffusion as a Cog model
Python
2
star
54

docker-cloud-subdomains

Automatic Heroku-style subdomains for Docker Cloud
Python
2
star
55

internetarchive-pdfjs-isbn-links

JavaScript
2
star
56

hubot-shipping-forecast

CoffeeScript
1
star
57

replicate-screenshots

1
star
58

docker-oauth2_proxy

1
star
59

interlock-haproxy-swarm

Interlock configured to use a Swarm set up by Machine
Shell
1
star
60

python-sdk

Facebook Platform Python SDK
Python
1
star
61

patchwork

JavaScript
1
star
62

compose-mongodb-demo

Python
1
star