Skip to content

Instantly share code, notes, and snippets.

@codingfoo
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingfoo/0c442e4f4a50598f51fc to your computer and use it in GitHub Desktop.
Save codingfoo/0c442e4f4a50598f51fc to your computer and use it in GitHub Desktop.
Script for deploying iron.io workers
#!/usr/bin/env sh
set -o nounset
set -o errexit
set -o pipefail
shopt -s nullglob
declare -a environments=("production" "staging" "development")
declare -a workers=(*.worker)
workers=(${workers[@]/\.worker/}) # remove .worker extension
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
run_setup=false
while getopts e:w:hq opt; do
case $opt in
q)
run_setup=true
;;
e)
if ( containsElement $OPTARG "${environments[@]}" )
then
declare -a environments=($OPTARG)
else
echo "Environment not found"
exit 1
fi
;;
w)
if ( containsElement $OPTARG "${workers[@]}" )
then
declare -a workers=($OPTARG)
else
echo "Worker not found"
exit 1
fi
;;
h)
echo "-h this message"
echo "-e <env> specify an environment"
echo "-w <worker> specify a worker"
echo "-q run setup"
exit 0
;;
esac
done
# Setup queues
if $run_setup
then
echo "Set up"
ruby ./setup.rb
fi
# Copy iron credentials into the local directory
cp ../../iron.json iron.json
cp ../../config/settings.yml settings.yml
for environment in "${environments[@]}"
do
cp ../../config/settings/${environment}.yml env_settings.yml
for worker in "${workers[@]}"
do
IRON_ENV=${environment} iron_worker upload ${worker} --env ${environment}
done
for worker in "${workers[@]}"
do
iron_worker webhook ${worker} --env ${environment}
done
done
# cleanup on exit
function cleanup {
rm iron.json
rm settings.yml
rm env_settings.yml
}
trap cleanup EXIT
# clear command line after ctrl-c
trap "{ echo; exit 1; }" INT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment