Skip to content

Instantly share code, notes, and snippets.

@cmmartin
Created October 19, 2015 17:14
Show Gist options
  • Save cmmartin/f14c589d92d0261ff4c7 to your computer and use it in GitHub Desktop.
Save cmmartin/f14c589d92d0261ff4c7 to your computer and use it in GitHub Desktop.
A simple script for deploying to various dokku instances
#!/bin/bash
readonly user="my_dokku_username"
readonly host="my_hostname"
readonly targets=(
# git branch | project name | virtual host
# list your dokku instances here...
)
# execute from the project root
if [ ${PWD##*/} == "scripts" ]; then
cd ..
fi
options=()
for target in ${targets[@]}
do
IFS=$'|' read -r branch project vhost <<< "$target"
git remote remove $branch
git remote add $branch ${user}@${vhost}.${host}:${project}
options+=(${branch})
done
echo "Select a deployment target"
PS3="Enter choice (1-${#options[@]}): "
select opt in "${options[@]}" "Cancel"; do
case "$REPLY" in
1 ) IFS=$'|' read -r branch project vhost <<< "${targets[REPLY - 1]}";;
2 ) IFS=$'|' read -r branch project vhost <<< "${targets[REPLY - 1]}";;
3 ) IFS=$'|' read -r branch project vhost <<< "${targets[REPLY - 1]}";;
$(( ${#options[@]}+1 )) ) echo "Goodbye"; exit 0;;
*) echo "Invalid option. Try again."; continue;;
esac
break
done
echo "$(tput bold)"
echo "Deploying..."
echo "Project: $project"
echo "Branch: $branch"
echo "Server: $vhost.$host"
echo "$(tput sgr0)"
npm test
if [ $? == 0 ]; then # No deploying unless the tests pass :)
echo "$(tput bold)Tests passed...$(tput sgr0)"
CURRENT_ENV=`ssh -t $user@$vhost.$host config:get $project NODE_ENV`
echo "$(tput bold)NODE_ENV is set to $CURRENT_ENV"
read -p "Do you want to change it? (Y/n) $(tput sgr0)" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "$(tput bold)NODE_ENV=" NEXT_ENV
read -p "Really set NODE_ENV to $NEXT_ENV? (Y/n) $(tput sgr0)" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
ssh -t ${user}@${vhost}.${host} config:set ${project} NODE_ENV=$NEXT_ENV
fi
fi
git push ${branch} master
if [ $? == 0 ]; then
echo "$(tput setaf 2) $(tput bold) SUCCESS $(tput sgr0)"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment