Created
May 14, 2014 15:38
-
-
Save andrewgross/b6612087007ba437cd69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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