2013-10-29 17:13:02 -05:00
|
|
|
#!/usr/bin/env bash
|
2015-01-03 10:55:40 -08:00
|
|
|
set -xeo pipefail
|
2014-12-13 18:56:31 -08:00
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
SELF=$(which "$0")
|
|
|
|
|
APP="$1"
|
|
|
|
|
TARGET="$2"
|
|
|
|
|
FORWARDED_PORT="$3"
|
|
|
|
|
SHOULD_FAIL="$4"
|
2020-12-08 23:15:11 +09:00
|
|
|
BRANCH="${5:-master}"
|
2013-12-11 21:41:05 +00:00
|
|
|
REMOTE="dokku@$TARGET"
|
2016-02-22 10:16:57 -08:00
|
|
|
REPO="test-$(basename "$APP")-$RANDOM"
|
2013-12-11 21:41:05 +00:00
|
|
|
|
2015-09-03 22:38:24 -04:00
|
|
|
destroy_app() {
|
2016-02-22 10:16:57 -08:00
|
|
|
# shellcheck disable=SC2029
|
|
|
|
|
echo "$REPO" | ssh "$REMOTE" apps:destroy "$REPO"
|
2014-12-13 18:56:31 -08:00
|
|
|
}
|
|
|
|
|
|
2015-09-03 22:38:24 -04:00
|
|
|
failed() {
|
2014-12-14 14:55:26 -08:00
|
|
|
echo "************ $1 failed ************"
|
2014-12-16 17:37:43 -08:00
|
|
|
destroy_app
|
2014-12-13 18:56:31 -08:00
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 22:38:24 -04:00
|
|
|
succeeded() {
|
2015-07-11 13:21:57 +02:00
|
|
|
echo "************ $1 succeeded but should have failed ************"
|
|
|
|
|
destroy_app
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 19:46:46 -07:00
|
|
|
TMP=$(mktemp -d "/tmp/$TARGET.XXXXX")
|
2016-02-22 10:16:57 -08:00
|
|
|
rmdir "$TMP" && cp -r "$(dirname "$SELF")/$APP" "$TMP"
|
2016-03-02 10:50:09 -08:00
|
|
|
|
2019-01-07 01:04:17 -05:00
|
|
|
pushd "$TMP" &>/dev/null || exit 1
|
2019-02-02 13:49:24 -05:00
|
|
|
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM EXIT
|
2016-03-02 10:50:09 -08:00
|
|
|
|
2013-06-10 21:26:31 -07:00
|
|
|
git init
|
2013-06-23 03:45:45 -07:00
|
|
|
git config user.email "robot@example.com"
|
|
|
|
|
git config user.name "Test Robot"
|
2016-02-22 10:16:57 -08:00
|
|
|
git remote add target "${REMOTE}:${REPO}"
|
2013-12-11 21:41:05 +00:00
|
|
|
|
|
|
|
|
[[ -f gitignore ]] && mv gitignore .gitignore
|
2013-06-10 21:26:31 -07:00
|
|
|
git add .
|
2013-12-11 21:41:05 +00:00
|
|
|
|
2016-02-22 10:16:57 -08:00
|
|
|
[[ -x pre-commit ]] && ./pre-commit "$REMOTE" "$REPO"
|
2013-06-10 21:26:31 -07:00
|
|
|
git commit -m 'initial commit'
|
2015-07-11 13:21:57 +02:00
|
|
|
if [[ "$SHOULD_FAIL" == true ]]; then
|
2020-12-08 23:15:11 +09:00
|
|
|
git push target "master:$BRANCH" && succeeded git-push
|
2015-07-11 13:21:57 +02:00
|
|
|
else
|
2020-12-08 23:15:11 +09:00
|
|
|
git push target "master:$BRANCH" || failed git-push
|
2015-07-11 13:21:57 +02:00
|
|
|
fi
|
2014-12-13 18:56:31 -08:00
|
|
|
if [[ -x post-deploy ]]; then
|
2016-02-22 10:16:57 -08:00
|
|
|
./post-deploy "$REMOTE" "$REPO" || failed post-deploy
|
2014-12-13 18:56:31 -08:00
|
|
|
fi
|
2013-12-11 21:41:05 +00:00
|
|
|
|
2015-07-11 13:21:57 +02:00
|
|
|
if [[ "$SHOULD_FAIL" == true ]]; then
|
|
|
|
|
echo "-----> Deploy failed (as it should have)!"
|
|
|
|
|
destroy_app
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2016-02-22 10:16:57 -08:00
|
|
|
URL=$(dokku url "$REPO")$FORWARDED_PORT
|
2013-06-30 01:47:10 -05:00
|
|
|
sleep 2
|
2016-02-22 10:16:57 -08:00
|
|
|
if (./check_deploy "$URL"); then
|
2014-12-13 18:56:31 -08:00
|
|
|
echo "-----> Deploy success!"
|
|
|
|
|
else
|
2013-06-30 02:27:36 -05:00
|
|
|
sleep 4
|
2016-02-22 10:16:57 -08:00
|
|
|
if (./check_deploy "$URL"); then
|
2014-12-13 18:56:31 -08:00
|
|
|
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
|