use url-parser and fetch wait-for script from remote
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Robert Kaussow 2020-02-03 23:10:48 +01:00
parent 92d47323c8
commit 554bd28f5f
3 changed files with 10 additions and 82 deletions

View File

@ -14,7 +14,11 @@ RUN addgroup -g 101 -S app && \
apk --update add --virtual .build-deps tar curl && \
apk --update add openssl postgresql-libs ca-certificates && \
curl -SsL -o /usr/local/bin/gomplate https://github.com/hairyhenderson/gomplate/releases/download/v3.5.0/gomplate_linux-amd64-slim && \
curl -SsL -o /usr/local/bin/url-parser https://github.com/xoxys/url-parser/releases/download/v0.1.0/url-parser-0.1.0-linux-amd64 && \
curl -SsL -o /usr/local/bin/wait-for https://raw.githubusercontent.com/xoxys/wait-for/master/wait-for && \
chmod 755 /usr/local/bin/gomplate && \
chmod 755 /usr/local/bin/url-parser && \
chmod 755 /usr/local/bin/wait-for && \
mkdir -p /app/web-vault /app/data && \
curl -SsL ${VAULT_TARBALL} | tar xz -C /app/web-vault && \
apk del .build-deps && \

View File

@ -1,13 +1,16 @@
#!/usr/bin/env sh
set -eo pipefail
set -eo
/usr/local/bin/gomplate -V -o /app/.env -f /etc/templates/env.tmpl
if [ ! -z "$BITWARDENRS_WAIT_FOR_HOST" ] && [ ! -z "$BITWARDENRS_WAIT_FOR_PORT" ]
if [ "$BITWARDENRS_WAITFOR_ENABLED" = true ]
then
WAITFOR_HOST=$(url-parse host --url "$BITWARDENRS_DATABASE_URL")
WAITFOR_PORT=$(url-parse port --url "$BITWARDENRS_DATABASE_URL")
printf "Wait for database server ...\n"
/usr/local/bin/wait-for
/usr/local/bin/wait-for "${WAITFOR_HOST}":"${WAITFOR_PORT:-5432}"
fi
printf "Start Bitwarden Server ...\n"

View File

@ -1,79 +0,0 @@
#!/usr/bin/env sh
BITWARDENRS_WAIT_FOR_TIMEOUT=15
QUIET=0
echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
}
usage() {
exitcode="$1"
cat << USAGE >&2
Usage:
$cmdname host:port [-t timeout] [-- command args]
-q | --quiet Do not output any status messages
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit "$exitcode"
}
wait_for() {
for i in `seq $BITWARDENRS_WAIT_FOR_TIMEOUT` ; do
nc -z "$BITWARDENRS_WAIT_FOR_HOST" "$BITWARDENRS_WAIT_FOR_PORT" > /dev/null 2>&1
result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
exec "$@"
fi
exit 0
fi
sleep 1
done
echo "Operation timed out" >&2
exit 1
}
while [ $# -gt 0 ]
do
case "$1" in
*:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-t)
TIMEOUT="$2"
if [ "$TIMEOUT" = "" ]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
break
;;
--help)
usage 0
;;
*)
echoerr "Unknown argument: $1"
usage 1
;;
esac
done
if [ "$HOST" = "" -o "$PORT" = "" ]; then
echoerr "Error: you need to provide a host and port to test."
usage 2
fi
wait_for "$@"