Skip to content

Commit

Permalink
fix: use compose v2 on GHA tests (#121)
Browse files Browse the repository at this point in the history
* fix: use compose v2 on GHA tests

* fix(ci): use compose v2 API

* extend timeout
  • Loading branch information
Victoremepunto authored Aug 13, 2024
1 parent dbf093e commit b1a1fc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
node-version: 18
- name: Setup E2E testing environment
run: docker-compose -f deployments/compose.yaml up -d --build
run: docker compose -f deployments/compose.yaml up -d --build
- name: Wait for Keycloak import to complete
run: deployments/wait_for_keycloak_import.sh deployments/compose.yaml
- name: Install test environment
Expand Down
28 changes: 13 additions & 15 deletions deployments/wait_for_keycloak_import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

COMPOSE_FILE="$1"
CONTAINER_NAME="keycloak"
COMPOSE_COMMAND=""
CONTAINER_ENGINE=""
SUCCESS_LOG_ENTRY="Keycloak.*started in \d+ms"
START_SECONDS="$SECONDS"
TIMEOUT="60"
Expand All @@ -11,16 +11,18 @@ command_exists() {
command -v "$1" >/dev/null
}

set_compose_command() {
if command_exists "docker-compose"; then
echo "docker-compose"
elif command_exists "podman-compose"; then
echo "podman-compose"
get_container_engine() {
if command_exists "docker"; then
echo -n "docker"
elif command_exists "podman"; then
echo -n "podman"
else
return 1
fi
}

success_entry_found() {
grep -Pq "$SUCCESS_LOG_ENTRY" <<< "$("$COMPOSE_COMMAND" -f "$COMPOSE_FILE" logs "$CONTAINER_NAME" 2>/dev/null)"
grep -Pq "$SUCCESS_LOG_ENTRY" <<<"$("$CONTAINER_ENGINE" compose -f "$COMPOSE_FILE" logs "$CONTAINER_NAME" 2>/dev/null)"
}

init_checks() {
Expand All @@ -30,15 +32,12 @@ init_checks() {
return 1
fi

COMPOSE_COMMAND="$(set_compose_command)"

if [ -z "$COMPOSE_COMMAND" ]; then
if ! CONTAINER_ENGINE="$(get_container_engine)"; then
echo "cannot find either docker-compose nor podman-compose in PATH"
return 1
fi
}


wait_for() {

echo -n "waiting for ${CONTAINER_NAME}"
Expand All @@ -47,16 +46,15 @@ wait_for() {
echo -n '.'
sleep 1

if [[ $(( SECONDS - START_SECONDS )) -gt $TIMEOUT ]]; then
"$COMPOSE_COMMAND" -f "$COMPOSE_FILE" logs "$CONTAINER_NAME"
if [[ $((SECONDS - START_SECONDS)) -gt $TIMEOUT ]]; then
"$CONTAINER_ENGINE" compose -f "$COMPOSE_FILE" logs "$CONTAINER_NAME"
echo "$CONTAINER_NAME failed to reach ready status under $TIMEOUT seconds"
return 1
fi
done

echo -e "\n Took $(( SECONDS - START_SECONDS )) seconds"
echo -e "\n Took $((SECONDS - START_SECONDS)) seconds"
}

init_checks || exit 1
wait_for || exit 1

0 comments on commit b1a1fc6

Please sign in to comment.