Skip to content

Commit

Permalink
fix(ci): use compose v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoremepunto committed Aug 12, 2024
1 parent db43e31 commit 1dc88b4
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 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" -f "$COMPOSE_FILE" logs "$CONTAINER_NAME" 2>/dev/null)"
}

init_checks() {
Expand All @@ -29,10 +31,8 @@ init_checks() {
echo "cannot read compose file: '${COMPOSE_FILE}'"
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
Expand All @@ -48,7 +48,7 @@ wait_for() {
sleep 1

if [[ $(( SECONDS - START_SECONDS )) -gt $TIMEOUT ]]; then
"$COMPOSE_COMMAND" -f "$COMPOSE_FILE" logs "$CONTAINER_NAME"
"$CONTAINER_ENGINE" compose -f "$COMPOSE_FILE" logs "$CONTAINER_NAME"
echo "$CONTAINER_NAME failed to reach ready status under $TIMEOUT seconds"
return 1
fi
Expand All @@ -59,4 +59,3 @@ wait_for() {

init_checks || exit 1
wait_for || exit 1

0 comments on commit 1dc88b4

Please sign in to comment.