Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Testdrive CI #3

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Docker image automatic build (ghcr)

on:
push:
branches: [ master ]
branches:
- '**'
pull_request:
branches: [ master ]
branches:
- master

env:
REGISTRY: ghcr.io
Expand All @@ -15,9 +17,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image (PR only)
if: github.ref != 'refs/heads/master'
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:$(date +%s)
- name: Set tag for testing
run: |
echo "TAG=$(date +%s)" >> $GITHUB_ENV
- name: Build the Docker image (for testing)
run: |
docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:$TAG
- name: Testdrive
run: |
TAG=$TAG ./testdrive.sh
env:
IMAGE_NAME: ${{ env.IMAGE_NAME }}
- name: Login to ghcr
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
if: github.ref == 'refs/heads/master'
Expand Down
60 changes: 60 additions & 0 deletions testdrive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash -ex

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' \
sameersbn/postgresql:14-20230628
docker run --rm --name "gitlab-redis-${SUFFIX}" -d \
--volume /srv/docker/gitlab/redis:/data \
redis:6.2
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' \
--env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
--env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
--env OAUTH2_GENERIC_USTC_APP_ID=1234 \
--env OAUTH2_GENERIC_USTC_APP_SECRET=example \
--env 'OAUTH2_GENERIC_USTC_LABEL=example oauth' \
--env OAUTH2_GENERIC_USTC_CLIENT_SITE=https://example.com \
--env OAUTH2_GENERIC_USTC_CLIENT_USER_INFO_URL=/userinfo \
--env OAUTH2_GENERIC_USTC_CLIENT_AUTHORIZE_URL=/authorize \
--env OAUTH2_GENERIC_USTC_CLIENT_TOKEN_URL=/token \
--env OAUTH2_GENERIC_USTC_ID_PATH=gid \
"$IMAGE_NAME":"$TAG" &

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
taoky marked this conversation as resolved.
Show resolved Hide resolved
sleep "${WAIT_TIME}"
done
Loading