Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created May 14, 2014 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgross/b6612087007ba437cd69 to your computer and use it in GitHub Desktop.
Save andrewgross/b6612087007ba437cd69 to your computer and use it in GitHub Desktop.
deploy_cookbook ()
{
EXPECTED_ARGS=2;
BAD_ARGS_ERROR_CODE=65;
if [ $# -ne $EXPECTED_ARGS ]; then
echo 'Usage: deploy_cookbook ${ENV} ${COOKBOOK}';
return $BAD_ARGS_ERROR_CODE;
fi;
environment=$1;
cookbook=$2;
if [[ $environment == "prod" ]]; then
environment="production";
fi;
if [[ $environment == "staging" ]]; then
freeze="";
else
freeze="--freeze";
fi;
echo "Checking that ${cookbook} is up to date with remote";
local grep_code;
pushd ${CHEF_PATH}/cookbooks/${cookbook} > /dev/null;
git remote update;
git status -uno | grep 'Your branch is behind';
grep_code=$?;
popd > /dev/null;
if [[ "${grep_code}" == "0" ]]; then
echo "${cookbook} is not up to date, exiting";
return 1;
fi;
pushd $CHEF_PATH > /dev/null;
bundle exec knife cookbook upload $cookbook $freeze -c ${CHEF_PATH}/${environment}/knife.rb || return 1;
bundle exec knife spork promote $environment $cookbook -c ${CHEF_PATH}/staging/knife.rb || return 1;
bundle exec knife environment from file ${CHEF_PATH}/environments/${environment}.json -c ${CHEF_PATH}/${environment}/knife.rb || return 1;
git commit;
git push;
popd > /dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment