mirror of
https://github.com/dokku/dokku.git
synced 2025-12-25 16:29:30 +01:00
And set to DOKKU_DEPLOY_BRANCH. Idea from https://github.com/dokku/dokku/pull/4167#issuecomment-717607136
75 lines
1.5 KiB
Bash
Executable File
75 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -xeo pipefail
|
|
|
|
SELF=$(which "$0")
|
|
APP="$1"
|
|
TARGET="$2"
|
|
FORWARDED_PORT="$3"
|
|
SHOULD_FAIL="$4"
|
|
BRANCH="${5:-master}"
|
|
REMOTE="dokku@$TARGET"
|
|
REPO="test-$(basename "$APP")-$RANDOM"
|
|
|
|
destroy_app() {
|
|
# shellcheck disable=SC2029
|
|
echo "$REPO" | ssh "$REMOTE" apps:destroy "$REPO"
|
|
}
|
|
|
|
failed() {
|
|
echo "************ $1 failed ************"
|
|
destroy_app
|
|
exit 1
|
|
}
|
|
|
|
succeeded() {
|
|
echo "************ $1 succeeded but should have failed ************"
|
|
destroy_app
|
|
exit 1
|
|
}
|
|
|
|
TMP=$(mktemp -d "/tmp/$TARGET.XXXXX")
|
|
rmdir "$TMP" && cp -r "$(dirname "$SELF")/$APP" "$TMP"
|
|
|
|
pushd "$TMP" &>/dev/null || exit 1
|
|
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM EXIT
|
|
|
|
git init
|
|
git config user.email "robot@example.com"
|
|
git config user.name "Test Robot"
|
|
git remote add target "${REMOTE}:${REPO}"
|
|
|
|
[[ -f gitignore ]] && mv gitignore .gitignore
|
|
git add .
|
|
|
|
[[ -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
|
|
if [[ -x post-deploy ]]; then
|
|
./post-deploy "$REMOTE" "$REPO" || failed post-deploy
|
|
fi
|
|
|
|
if [[ "$SHOULD_FAIL" == true ]]; then
|
|
echo "-----> Deploy failed (as it should have)!"
|
|
destroy_app
|
|
exit 0
|
|
fi
|
|
|
|
URL=$(dokku url "$REPO")$FORWARDED_PORT
|
|
sleep 2
|
|
if (./check_deploy "$URL"); then
|
|
echo "-----> Deploy success!"
|
|
else
|
|
sleep 4
|
|
if (./check_deploy "$URL"); then
|
|
echo "-----> Deploy success!"
|
|
else
|
|
failed check-deploy
|
|
fi
|
|
fi
|
|
|
|
destroy_app
|