Files
dokku/tests/test_deploy

75 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2015-01-03 10:55:40 -08:00
set -xeo pipefail
2014-12-13 18:56:31 -08:00
SELF=$(which "$0")
APP="$1"
TARGET="$2"
FORWARDED_PORT="$3"
SHOULD_FAIL="$4"
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() {
echo "************ $1 succeeded but should have failed ************"
destroy_app
exit 1
}
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
pushd "$TMP" &>/dev/null || exit 1
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM EXIT
2016-03-02 10:50:09 -08: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
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"
git commit -m 'initial commit'
if [[ "$SHOULD_FAIL" == true ]]; then
git push target "master:$BRANCH" && succeeded git-push
else
git push target "master:$BRANCH" || failed git-push
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
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
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