Skip to content

Commit

Permalink
more robust testdrive
Browse files Browse the repository at this point in the history
  • Loading branch information
RTXUX committed Apr 1, 2024
1 parent c1fc8d0 commit 4dcb611
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions testdrive.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#!/bin/bash -ex
docker run --name gitlab-postgresql -d \

SUFFIX="$RANDOM"

cleanup() {
docker stop "gitlab-${SUFFIX}" || kill -TERM "$(jobs -p)" || true
docker stop "gitlab-redis-${SUFFIX}" || true
docker stop "gitlab-postgresql-${SUFFIX}" || true
}

trap cleanup EXIT

docker run --rm --name "gitlab-postgresql-${SUFFIX}" -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
--env 'DB_EXTENSION=pg_trgm,btree_gist' \
--volume /srv/docker/gitlab/postgresql:/var/lib/postgresql \
sameersbn/postgresql:14-20230628
docker run --name gitlab-redis -d \
docker run --rm --name "gitlab-redis-${SUFFIX}" -d \
--volume /srv/docker/gitlab/redis:/data \
redis:6.2
docker run --name gitlab \
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
docker run --rm --name "gitlab-${SUFFIX}" \
--link "gitlab-postgresql-${SUFFIX}:postgresql" --link "gitlab-redis-${SUFFIX}:redisio" \
--publish 10022:22 --publish 10080:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
Expand All @@ -23,19 +33,28 @@ docker run --name gitlab \
--env OAUTH2_GENERIC_USTC_CLIENT_AUTHORIZE_URL=/authorize \
--env OAUTH2_GENERIC_USTC_CLIENT_TOKEN_URL=/token \
--env OAUTH2_GENERIC_USTC_ID_PATH=gid \
--volume /srv/docker/gitlab/gitlab:/home/git/data \
"$IMAGE_NAME":"$TAG" &
echo "Please wait 4 minutes..."
sleep 4m
url="http://localhost:10080"
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null "$url")
# Check if the status code is not in the success range (200-299)
if [[ $status_code -lt 200 || $status_code -gt 399 ]]; then
echo "Error: Failed to access $url (status code: $status_code)"
exit 1
fi
ret=$(docker exec gitlab cat /home/git/gitlab/config/gitlab.yml | grep -c 'example oauth')
if [[ $ret -ne 1 ]]; then
echo "Error: Failed to find 'example oauth' in gitlab.yml"
exit 1
fi

check() {
local url="http://localhost:10080"
status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null "$url")
# Check if the status code is not in the success range (200-399)
if [[ $status_code -lt 200 || $status_code -gt 399 ]]; then
echo "Error: Failed to access $url (status code: $status_code)"
return 1
fi
ret=$(docker exec "gitlab-${SUFFIX}" cat /home/git/gitlab/config/gitlab.yml | grep -c 'example oauth')
if [[ $ret -ne 1 ]]; then
echo "Error: Failed to find 'example oauth' in gitlab.yml"
return 1
fi
return 0
}

RETRIES="48"
RETRIED=0
WAIT_TIME="5s"

until check || [[ "$((RETRIED++))" == "${RETRIES}" ]]; do
sleep "${WAIT_TIME}"
done

0 comments on commit 4dcb611

Please sign in to comment.