2013-10-29 17:13:02 -05:00
|
|
|
#!/usr/bin/env bash
|
2014-12-14 14:45:49 -08:00
|
|
|
set -eo pipefail
|
2014-12-13 18:56:31 -08:00
|
|
|
|
|
|
|
|
SELF=$(which $0); APP="$1"; TARGET="$2"; FORWARDED_PORT="$3"
|
2013-12-11 21:41:05 +00:00
|
|
|
REMOTE="dokku@$TARGET"
|
|
|
|
|
REPO="test-$(basename $APP)-$RANDOM"
|
|
|
|
|
|
2014-12-13 18:56:31 -08:00
|
|
|
destroy_app(){
|
|
|
|
|
echo $REPO | ssh $REMOTE apps:destroy $REPO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failed(){
|
2014-12-14 14:55:26 -08:00
|
|
|
echo "************ $1 failed ************"
|
2014-12-16 16:42:29 -08:00
|
|
|
# destroy_app
|
2014-12-13 18:56:31 -08:00
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 03:37:00 -07:00
|
|
|
TMP=$(mktemp -d -t "$TARGET.XXXXX")
|
2014-12-13 18:56:31 -08:00
|
|
|
rmdir $TMP && cp -r "$(dirname "$SELF")"/$APP $TMP
|
2013-06-10 21:26:31 -07:00
|
|
|
cd $TMP
|
|
|
|
|
git init
|
2013-06-23 03:45:45 -07:00
|
|
|
git config user.email "robot@example.com"
|
|
|
|
|
git config user.name "Test Robot"
|
2013-12-11 21:41:05 +00:00
|
|
|
git remote add target $REMOTE:$REPO
|
|
|
|
|
|
|
|
|
|
[[ -f gitignore ]] && mv gitignore .gitignore
|
2013-06-10 21:26:31 -07:00
|
|
|
git add .
|
2013-12-11 21:41:05 +00:00
|
|
|
|
|
|
|
|
[[ -x pre-commit ]] && ./pre-commit $REMOTE $REPO
|
2013-06-10 21:26:31 -07:00
|
|
|
git commit -m 'initial commit'
|
2014-12-14 14:45:49 -08:00
|
|
|
git push target master || failed git-push
|
2014-12-13 18:56:31 -08:00
|
|
|
if [[ -x post-deploy ]]; then
|
|
|
|
|
./post-deploy $REMOTE $REPO || failed post-deploy
|
|
|
|
|
fi
|
2013-12-11 21:41:05 +00:00
|
|
|
|
2014-12-14 14:45:49 -08:00
|
|
|
URL=$(dokku url $REPO)$FORWARDED_PORT
|
2013-06-30 01:47:10 -05:00
|
|
|
sleep 2
|
2014-12-13 18:56:31 -08:00
|
|
|
if (./check_deploy $URL); then
|
|
|
|
|
echo "-----> Deploy success!"
|
|
|
|
|
else
|
2013-06-30 02:27:36 -05:00
|
|
|
sleep 4
|
2014-12-13 18:56:31 -08:00
|
|
|
if (./check_deploy $URL); then
|
|
|
|
|
echo "-----> Deploy success!"
|
|
|
|
|
else
|
|
|
|
|
failed check-deploy
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2013-12-11 21:41:05 +00:00
|
|
|
|
2014-12-13 18:56:31 -08:00
|
|
|
destroy_app
|