Skip to content

Instantly share code, notes, and snippets.

@boundvariable
Created June 28, 2011 06:46
Show Gist options
  • Save boundvariable/1050621 to your computer and use it in GitHub Desktop.
Save boundvariable/1050621 to your computer and use it in GitHub Desktop.
git post-update distribute with mcollective
#!/usr/bin/env ruby
require 'rubygems'
require 'mcollective'
class Deployer
include MCollective::RPC
# config, including passwords for mcollective bus
# in the local machine mcollective config
def load_config()
File.expand_path("/etc/mcollective/client.cfg")
end
# init the mcollective config
def mc_rpc(agent)
rpcclient agent,
:configfile => load_config(),
:options => {
:config => load_config(),
:disctimeout => 2,
:timeout => 120,
:verbose => true,
:filter => ::MCollective::Util.empty_filter}
end
def deploy(identity, version, opts)
# use the deployer agent, that lives on the target machines
deploy_agent = mc_rpc "deployer"
# use fact filter to target machines that have the particular application
deploy_agent.fact_filter "application", identity
# tell them to fetch the 'slug' from s3
deploy_agent.fetch :repo => "s3", :version => version
# tell them to release the new version
deploy_agent.release :version => version
end
end
deployer = Deployer.new
puts "Deploy to #{ARGV[0]} version #{ARGV[1]}"
# deploy this version of the project to machines that have this project.
# for example, deploy("4af6d00d9102bb0fadcca541d774226abca51128", "myproject")
# would get all of the machines running "myproject" to fetch 4af6d00d9102bb0fadcca541d774226abca51128.tar.bz2
# from s3 and deploy it.
deployer.deploy("#{ARGV[0]}", ARGV[1])
#!/bin/sh
echo "Inspecting changes"
# get the commit id for head
rev=$(git rev-parse HEAD)
echo "Compressing"
# use the directory of this empty git project to determine project name
project=$(basename `pwd` | sed 's/[.]git//g')
# bzip it. could also do a --format on archive
git archive master | bzip2 > /tmp/${project}.${rev}.tar.bz2
# call the upload script
/path/to/upload.rb 'bucket' $project $rev
echo "Distributing"
# call the deploy script
/path/to/deploy.rb $project $rev
echo "Done"
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
storage = Fog::Storage.new(:provider => 'AWS',
:aws_access_key_id => '',
:aws_secret_access_key => '')
# figure out where this 'slug' has to go
directory = storage.directories.get(ARGV[0])
project = ARGV[1]
revision = ARGV[2]
project_rev = "#{project}.#{revision}"
source = "/tmp/#{project_rev}.tar.bz2"
file = directory.files.create(:body => File.open(source),
:key => "#{project_rev}.tar.bz2",
:public => false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment