Skip to content

Commit

Permalink
Added healthcheck command for test containers. Add uploading of test …
Browse files Browse the repository at this point in the history
…results.
  • Loading branch information
ekharkunov committed Nov 4, 2024
1 parent c2852c7 commit b8db285
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/application-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ jobs:
--generate-notes \
--target ${{ github.sha }} \
${{ github.workspace }}/gh_release/*.jar
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-result
path: ${{ github.workspace }}/server/build/reports/tests/
retention-days: 10
- name: Notify if tests failed
uses: homoluctus/slatify@cd4b4a1158cfb3e26fe1ee35c1cd4f0247dfbf96
if: failure()
Expand Down
7 changes: 7 additions & 0 deletions server/docker/common-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ services:
user: extender
environment:
- EXAMPLE_VAR=1
healthcheck:
# Extender's port is hardcoded here.
test: wget --no-verbose --tries=1 --spider http://localhost:9000/actuator/health
interval: 10s
timeout: 2s
retries: 10
start_period: 5s
common_builder:
platform: linux/amd64
volumes:
Expand Down
45 changes: 45 additions & 0 deletions server/scripts/start-test-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,48 @@ if [ "$GITHUB_ACTION" != "" ]; then
fi

docker compose -p $APPLICATION -f ${DIR}/../docker/docker-compose.yml --profile $COMPOSE_PROFILE up -d

# Retry configuration
max_retries=10
retry_interval=15

check_containers_health() {
all_healthy=true

for container in $(docker ps -q); do
name=$(docker inspect --format='{{.Name}}' "$container" | sed 's/\///')
health_status=$(docker inspect --format='{{.State.Health.Status}}' "$container")

# If health status is empty, container doesn't have a health check defined
if [ -z "$health_status" ]; then
health_status="no health check"
fi

echo "$name: $health_status"

# Check if the container is not healthy
if [ "$health_status" != "healthy" ]; then
all_healthy=false
fi
done

# Return whether all containers are healthy
$all_healthy && return 0 || return 1
}

# Main loop to retry until all containers are healthy or retries run out
for (( i=1; i<=$max_retries; i++ )); do
echo "Attempt $i of $max_retries: Checking container health..."

if check_containers_health; then
echo "All containers are healthy!"
exit 0
else
echo "Some containers are not healthy yet. Retrying in $retry_interval seconds..."
sleep $retry_interval
fi
done

# If we reach this point, some containers did not become healthy within the retry limit
echo "Some containers did not become healthy after $max_retries retries."
exit 1

0 comments on commit b8db285

Please sign in to comment.