Coder Social home page Coder Social logo

loom's Introduction

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

loom's People

Contributors

aanand avatar bfirsh avatar blaine avatar sherzberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loom's Issues

librarian-puppet: Add procedure to update module

Currently puppet.update executes "librarian-puppet install" which is useful if we add new modules.

However, if we update the Puppetfile to bump version/reference numbers to use a later version, we'll want to run "librarian-puppet update" instead.

pspec -> Attest -> progressbar dependency broken on Travis

Here's a Travis build log that's confusing me:

https://travis-ci.org/bfirsh/loom/jobs/27383665

I think I'm just misunderstanding how pip resolves between 2.3 and 2.3-dev. By checking via archive.org I've confirmed that progressbar 2.3 has never existed; only 2.3-dev has ever existed.

I probably should have raised this issue in Attest but I noticed that @bfirsh is involved with all these projects, and moreover this is only effecting me in loom.

Host specific puppet configuration

I would like to have specific host specific config, such as timezone data. What are your thoughts on how to best implement this?

I was thinking about making something similar to how roles work so that it auto grabs the correct file from modules/hosts. For example modules/hosts/trex.pp would map to the trex host entry in the env.roledefs map.

Any other ideas? Thanks!

Loom requires fabric before you can install.

I think I broke the install of loom when I added the version number to loom/init.py. Is the from . import config required in loom/init.py? If not, removing it should fix this. If it is required, let me know and I can come up with something else.

Selecting specific servers

Would be nice to be able to type "fab -R db-1 puppet.apply" or whatever instead of using -H and the fqdn.

Unable to run tests locally.

I created a fork and tried to run the tests locally, but they fail. My steps:

virtualenv --no-site-packages --distribute venv
source venv/bin/activate
pip install -r dev-requirements.txt --allow-external progressbar --allow-unverified progressbar
pip install -r requirements.txt
script/test

Output:

(venv)>script/test
Traceback (most recent call last):
  File "/Users/richard/Sites/dev/loom/venv/bin/pspec", line 9, in <module>
    load_entry_point('pspec==0.0.2', 'console_scripts', 'pspec')()
  File "/Users/richard/Sites/dev/loom/venv/lib/python2.7/site-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/richard/Sites/dev/loom/venv/lib/python2.7/site-packages/pkg_resources.py", line 2431, in load_entry_point
    return ep.load()
  File "/Users/richard/Sites/dev/loom/venv/lib/python2.7/site-packages/pkg_resources.py", line 2147, in load
    ['__name__'])
  File "/Users/richard/Sites/dev/loom/venv/lib/python2.7/site-packages/pspec/__init__.py", line 2, in <module>
    from .collectors import run
  File "/Users/richard/Sites/dev/loom/venv/lib/python2.7/site-packages/pspec/collectors.py", line 2, in <module>
    from attest.utils import import_dotted_name, deep_get_members
ImportError: No module named utils

Any ideas? Maybe attest needs to be pinned in dev-requirements.txt?

puppet.install_master fails

Attempting to reinstall install a puppet master results in the following error:

ironix@zarniwoop-cat:~/poeti.ca/fabric-puppet $ fab -R puppetmaster puppet.install_master
[174.37.225.26] Executing task 'puppet.install_master'
[174.37.225.26] Executing task 'install_agent'
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/fabric/main.py", line 717, in main
    *args, **kwargs
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 299, in execute
    multiprocessing
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 198, in _execute
    return task.run(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 112, in run
    return self.wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/loom/puppet.py", line 77, in install_master
    execute(install_agent)
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 299, in execute
    multiprocessing
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 198, in _execute
    return task.run(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/fabric/tasks.py", line 112, in run
    return self.wrapped(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/loom/puppet.py", line 87, in install_agent
    execute(install_puppet)
NameError: global name 'install_puppet' is not defined

site.pp: Need ability to define extra content

After spending far, far too long working with puppetlabs-firewall, I came to the conclusion that this module will only reliably work if I can place some top-scope defaults within site.pp

Unfortunately loom does not give me control of site.pp. As a workaround, I added an additional task to fabfile.py to force an overwrite of the file.

Feature: Vagrant remote deployment

So, here I am with a 4-year old MacBook and a super fast desktop PC where I run my VMs. My laptop is a fantastic environment for development. My Windows desktop? Better for gaming imo. However, it would be fantastic if I could use that machine for remote development using Vagrant, but managed from my laptop. =D

Vagrant is a wonderful tool for bringing up VMs on demand on the fly, but it currently doesn't support doing so on remote machines. This is where loom could come in handy. I've been thinking that one could integrate some simple support for managing Vagrant on a remote machine, similar to how we provision a new server with Puppet.

Anyhow, I'm going to start working on implementing such feature as well as some basic FreeBSD support.

Would love to get your input on this.

puppet.conf: environment (prod, staging, etc...)

The $::environment variable is not picked up by puppet unless it is within the [main] block.

Move 'environment = {prod,staging}' into [main] block. Otherwise the $::environment variable defaults to production.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.