Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for running commands on multiple environments #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
ref origin/master
post-deploy /var/www/myapp.com/update.sh

You can also use group names for environments to be able to deploy and run commands on them.

[develop:appA]
key /path/to/some.pem

[develop:appB]
key /path/to/some.pem


Run an `deploy(1)` on an entire group by using the `:*` string after the group name.

deploy develop:*

## Directives

### key (optional)
Expand Down
62 changes: 52 additions & 10 deletions bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ set_config_path() {
#

config_section() {
grep "^\[$1" $CONFIG &> /dev/null
case "$1" in
*":*" ) grep "^\[$1:" $CONFIG &> /dev/null;;
* ) grep "^\[$1" $CONFIG &> /dev/null;;
esac
}

#
Expand Down Expand Up @@ -151,7 +154,7 @@ config() {
if test $# -eq 0; then
cat $CONFIG
else
config_get $1
multiple_env config_get $1
fi
}

Expand Down Expand Up @@ -337,6 +340,45 @@ update() {
&& log "updated $VERSION -> `./bin/deploy --version`"
}

get_multi_env() {
local multiple_env
local env_group

case "$ENV" in
*":*" )
env_group=$ENV
env_group=${env_group//:*/}

multiple_env=`grep "^\[${ENV}:" $CONFIG`

# remove brackets
multiple_env=${multiple_env//\[/}
multiple_env=${multiple_env//\]/}

echo $multiple_env
;;
* ) echo $ENV;;
esac
}

#
# Run the given <cmd> on all <env>.
#

multiple_env() {
local multi_env="`get_multi_env`"
local orig_env=$ENV

for env in $multi_env; do
ENV=$env
log [$ENV] "$@"
$@
done

ENV=$orig_env

}

# parse argv

while test $# -ne 0; do
Expand All @@ -347,13 +389,13 @@ while test $# -ne 0; do
-c|--config) set_config_path $1; shift ;;
-C|--chdir) log cd $1; cd $1; shift ;;
-T|--no-tests) TEST=0 ;;
run|exec) require_env; run "cd `config_get path`/current && $@"; exit ;;
console) require_env; console; exit ;;
curr|current) require_env; current_commit; exit ;;
prev|previous) require_env; nth_deploy_commit 2; exit ;;
revert) require_env; revert_to ${1-1}; exit ;;
setup) require_env; setup $@; exit ;;
list) require_env; list_deploys; exit ;;
run|exec) require_env; multiple_env run "cd `config_get path`/current && $@"; exit ;;
console) require_env; multiple_env console; exit ;;
curr|current) require_env; multiple_env current_commit; exit ;;
prev|previous) require_env; multiple_env nth_deploy_commit 2; exit ;;
revert) require_env; multiple_env revert_to ${1-1}; exit ;;
setup) require_env; multiple_env setup $@; exit ;;
list) require_env; multiple_env list_deploys; exit ;;
update) update; exit ;;
config) config $@; exit ;;
*)
Expand All @@ -370,4 +412,4 @@ require_env
check_for_local_changes

# deploy
deploy "${REF:-`config_get ref`}"
multiple_env deploy "${REF:-`config_get ref`}"