diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a133c0e..aee6659 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,8 @@ jobs: strategy: matrix: python-version: [ '3.7', '3.8', '3.9', '3.10' ] + env: + GITHUB_ACTIONS: true steps: - uses: actions/checkout@v2 - name: setup python diff --git a/tests/resources/create-sirix-users.sh b/tests/resources/create-sirix-users.sh index 40d50ac..4d22222 100755 --- a/tests/resources/create-sirix-users.sh +++ b/tests/resources/create-sirix-users.sh @@ -6,11 +6,18 @@ USERNAME="admin" PASSWORD="admin" ROLES="create,modify,delete,view" +# Determine if running in GitHub Actions or locally +if [ "$GITHUB_ACTIONS" == "true" ]; then + KEYCLOAK_HOST="keycloak" +else + KEYCLOAK_HOST="localhost" +fi + user_exists() { $KEYCLOAK_HOME/bin/kcadm.sh get users -r "$REALM" -q "username=$USERNAME" --fields username | grep -q "\"username\" : \"$USERNAME\"" } -$KEYCLOAK_HOME/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user "$USERNAME" --password "$PASSWORD" +$KEYCLOAK_HOME/bin/kcadm.sh config credentials --server http://$KEYCLOAK_HOST:8080 --realm master --user "$USERNAME" --password "$PASSWORD" if user_exists; then echo "User '$USERNAME' already exists in realm '$REALM'." @@ -25,4 +32,4 @@ else echo "Failed to add user '$USERNAME' to realm '$REALM'." exit 1 fi -fi \ No newline at end of file +fi diff --git a/tests/resources/docker-compose.yml b/tests/resources/docker-compose.yml index b8249a3..d700b2c 100644 --- a/tests/resources/docker-compose.yml +++ b/tests/resources/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.4' services: keycloak: build: . @@ -22,10 +21,10 @@ services: networks: - auth-network healthcheck: - test: "curl -f http://localhost:8080/ || exit 1" - timeout: 3s - start_period: 10s - retries: 20 + test: [ "CMD", "curl", "-f", "http://keycloak:8080/realms/master" ] + interval: 60s + timeout: 20s + retries: 10 server: image: sirixdb/sirix ports: diff --git a/tests/resources/wait-for-keycloak.sh b/tests/resources/wait-for-keycloak.sh index 0d3e999..e0ab024 100755 --- a/tests/resources/wait-for-keycloak.sh +++ b/tests/resources/wait-for-keycloak.sh @@ -3,8 +3,15 @@ # Start Keycloak in the background /opt/keycloak/bin/kc.sh "$@" & +# Determine if running in GitHub Actions or locally +if [ "$GITHUB_ACTIONS" == "true" ]; then + KEYCLOAK_HOST="keycloak" +else + KEYCLOAK_HOST="localhost" +fi + # Wait for Keycloak to be ready -until curl -sf http://localhost:8080 > /dev/null; do +until curl -sf http://$KEYCLOAK_HOST:8080 > /dev/null; do echo "Waiting for Keycloak to be ready..." sleep 5 done @@ -13,4 +20,4 @@ done /opt/keycloak/scripts/create-sirix-users.sh # Keep the container running -wait \ No newline at end of file +wait