Skip to content

Commit

Permalink
Testdrive CI
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Mar 31, 2024
1 parent 530ade9 commit 333765a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
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
41 changes: 41 additions & 0 deletions testdrive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash -ex
docker run --name gitlab-postgresql -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 \
--volume /srv/docker/gitlab/redis:/data \
redis:6.2
docker run --name gitlab \
--link gitlab-postgresql:postgresql --link gitlab-redis: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 \
--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 299 ]]; then
echo "Error: Failed to access $url (status code: $status_code)"
exit 1
fi
ret=$(docker exec -it 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

0 comments on commit 333765a

Please sign in to comment.