Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created October 11, 2012 22:02
Show Gist options
  • Save fnichol/3875795 to your computer and use it in GitHub Desktop.
Save fnichol/3875795 to your computer and use it in GitHub Desktop.
orderup - Creates a tarball of Chef cookbooks from a Cheffile for chef-solo

orderup

Description

Creates a tarball of Chef cookbooks from a Berksfile or Cheffile for chef-solo.

Installation

Copy the program to your local machine (perhaps ~/bin?) and install Berkshelf or Librarian-Chef:

$ mkdir -p $HOME/bin
$ (cd $HOME/bin && curl -sLO http://git.io/orderup)
$ chmod 755 $HOME/bin/orderup
$ gem install berkshelf librarian

Usage

Berkshelf

Need a cookbooks to deploy Sensu? Create yourself a Berksfile with the following:

#!/usr/bin/env ruby
#^syntax detection

site :opscode

cookbook 'sensu'

# this cookbook is not published on the community site
cookbook 'redis', :git => 'git://github.com/miah/chef-redis.git'

Now create your cookbooks tarball with a daily build timestamp!

$ orderup sensu-$(date +%Y%m%d)

Upload to an HTTP server or push out to a node for a chef-solo run.

Librarian-Chef

Need a cookbooks to run a Ruby application server? Create yourself a Cheffile with the following:

#!/usr/bin/env ruby
#^syntax detection

site 'http://community.opscode.com/api/v1'

cookbook 'ruby_build'
cookbook 'rbenv_system_pkgs', :git => 'https://github.com/fnichol/chef-rbenv_system_pkgs',
                              :ref => 'v0.1.0'
cookbook 'rbenv',             :git => 'git://github.com/fnichol/chef-rbenv.git',
                              :ref => 'v0.6.10'
cookbook 'fanfare',           :git => 'git://github.com/fnichol/chef-fanfare.git'

Now create your cookbooks tarball!

$ orderup rubyapp

Upload to an HTTP server or push out to a node for a chef-solo run.

#!/usr/bin/env bash
set -e
log() { printf -- "-----> $*\n" ; return $? ; }
fail() { printf -- "\nERROR: $*\n" ; exit 1 ; }
if [[ -f "$PWD/Berksfile" ]] ; then
if command -v berks >/dev/null ; then
fetch_cmd="berks install --path cookbooks"
depfile="Berksfile"
else
fail "berks is not found in PATH. Please 'gem install berkshelf'"
fi
elif [[ -f "$PWD/Cheffile" ]] ; then
if command -v librarian-chef >/dev/null ; then
fetch_cmd="librarian-chef install --clean --verbose"
depfile="Cheffile"
else
fail "librarian-chef is not found in PATH. Please 'gem install librarian'"
fi
else
fail "Berksfile or Cheffile must be present in $PWD"
fi
name="$1"
build="$PWD/build-$$"
log "Preparing build project"
mkdir -p $build
cp -f $PWD/${depfile}* $build/
log "Fetching cookbooks and their dependencies"
(cd $build && $fetch_cmd)
log "Creating $PWD/$name.tar.gz"
rm -f $PWD/$name.tar{,.gz}
(cd $build && tar cf $(dirname $PWD)/$name.tar cookbooks/)
gzip $PWD/$name.tar
log "Cleaning up"
rm -rf $build
log "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment