1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-11-19 05:40:10 +01:00
Stirling-PDF/test.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
4.1 KiB
Bash
Raw Normal View History

2023-12-30 19:56:07 +01:00
#!/bin/bash
# Function to check the health of the service with a timeout of 80 seconds
check_health() {
local service_name=$1
local compose_file=$2
local end=$((SECONDS+60))
2023-12-30 22:32:04 +01:00
echo -n "Waiting for $service_name to become healthy..."
until [ "$(docker inspect --format='{{json .State.Health.Status}}' "$service_name")" == '"healthy"' ] || [ $SECONDS -ge $end ]; do
sleep 3
echo -n "."
if [ $SECONDS -ge $end ]; then
echo -e "\n$service_name health check timed out after 80 seconds."
2023-12-31 20:13:24 +01:00
echo "Printing logs for $service_name:"
docker logs "$service_name"
2023-12-30 22:32:04 +01:00
return 1
fi
done
echo -e "\n$service_name is healthy!"
2023-12-30 19:56:07 +01:00
return 0
}
# Function to test a Docker Compose configuration
test_compose() {
local compose_file=$1
local service_name=$2
local status=0
echo "Testing $compose_file configuration..."
# Start up the Docker Compose service
docker-compose -f "$compose_file" up -d
# Wait for the service to become healthy
if check_health "$service_name" "$compose_file"; then
echo "$service_name test passed."
else
echo "$service_name test failed."
status=1
fi
# Perform additional tests if needed
# Tear down the service
docker-compose -f "$compose_file" down
return $status
}
# Keep track of which tests passed and failed
declare -a passed_tests
declare -a failed_tests
run_tests() {
local test_name=$1
local compose_file=$2
if test_compose "$compose_file" "$test_name"; then
passed_tests+=("$test_name")
else
failed_tests+=("$test_name")
fi
}
# Main testing routine
main() {
2023-12-30 22:32:04 +01:00
SECONDS=0
2023-12-30 19:56:07 +01:00
export DOCKER_ENABLE_SECURITY=false
2024-01-02 22:17:25 +01:00
# Run the gradlew build command and check if it fails
if ! ./gradlew clean build; then
echo "Gradle build failed with security disabled, exiting script."
exit 1
fi
2023-12-30 19:56:07 +01:00
# Building Docker images
2024-01-01 15:57:52 +01:00
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest -f ./Dockerfile .
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-lite -f ./Dockerfile-lite .
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-ultra-lite -f ./Dockerfile-ultra-lite .
2023-12-30 19:56:07 +01:00
# Test each configuration
run_tests "Stirling-PDF-Ultra-Lite" "./exampleYmlFiles/docker-compose-latest-ultra-lite.yml"
run_tests "Stirling-PDF-Lite" "./exampleYmlFiles/docker-compose-latest-lite.yml"
run_tests "Stirling-PDF" "./exampleYmlFiles/docker-compose-latest.yml"
export DOCKER_ENABLE_SECURITY=true
2024-01-02 22:17:25 +01:00
# Run the gradlew build command and check if it fails
if ! ./gradlew clean build; then
echo "Gradle build failed with security enabled, exiting script."
exit 1
fi
2023-12-30 19:56:07 +01:00
# Building Docker images with security enabled
2024-01-01 15:57:52 +01:00
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest -f ./Dockerfile .
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-lite -f ./Dockerfile-lite .
docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-ultra-lite -f ./Dockerfile-ultra-lite .
2023-12-30 19:56:07 +01:00
# Test each configuration with security
run_tests "Stirling-PDF-Ultra-Lite-Security" "./exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml"
run_tests "Stirling-PDF-Lite-Security" "./exampleYmlFiles/docker-compose-latest-lite-security.yml"
run_tests "Stirling-PDF-Security" "./exampleYmlFiles/docker-compose-latest-security.yml"
# Report results
2023-12-30 22:32:04 +01:00
echo "All tests completed in $SECONDS seconds."
2023-12-30 19:56:07 +01:00
if [ ${#passed_tests[@]} -ne 0 ]; then
echo "Passed tests:"
fi
for test in "${passed_tests[@]}"; do
echo -e "\e[32m$test\e[0m" # Green color for passed tests
done
if [ ${#failed_tests[@]} -ne 0 ]; then
echo "Failed tests:"
fi
for test in "${failed_tests[@]}"; do
echo -e "\e[31m$test\e[0m" # Red color for failed tests
done
2023-12-30 22:32:04 +01:00
2023-12-30 19:56:07 +01:00
# Check if there are any failed tests and exit with an error code if so
if [ ${#failed_tests[@]} -ne 0 ]; then
echo "Some tests failed."
exit 1
else
echo "All tests passed successfully."
exit 0
fi
}
main