Skip to content
Snippets Groups Projects

Resolve "Data ingress for context information for tiki-wiki"

2 files
+ 253
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 200
0
#!/bin/bash
# Functions used by script
# Function to wait for a Docker Compose container to finish
wait_for_container() {
local SERVICE_NAME=$1
if [ -z "$SERVICE_NAME" ]; then
echo "Please provide a Docker Compose service name."
return 1
fi
echo "Waiting for container $SERVICE_NAME to finish..."
# Loop until the container is finished running
while true; do
# Get the state of the container
STATUS=$(docker compose ps -q "$SERVICE_NAME" | xargs docker inspect -f '{{.State.Status}}')
if [ "$STATUS" == "exited" ]; then
echo "Container $SERVICE_NAME has finished running."
break
elif [ -z "$STATUS" ]; then
echo "Container $SERVICE_NAME does not exist or is not running."
return 1
fi
# Wait for 5 seconds before checking again
sleep 5
done
echo "Function finished. Container $SERVICE_NAME has exited."
}
# Configures to use the tikiwiki test db for the CI/CD
replace_tikiwiki_config() {
local env_file="variables.env"
# Check if the file exists
if [[ ! -f $env_file ]]; then
echo "File $env_file not found!"
return 1
fi
# Replace TIKIWIKIDB_HOST with tikiwikidb-test
sed -i 's/^TIKIWIKIDB_HOST=.*/TIKIWIKIDB_HOST=tikiwikidb-test/' $env_file
# Replace TIKIWIKIDB_PORT with 3306
sed -i 's/^TIKIWIKIDB_PORT=.*/TIKIWIKIDB_PORT=3306/' $env_file
echo "TIKIWIKIDB_HOST and TIKIWIKIDB_PORT have been updated in $env_file."
}
# Function to check service health
check_health() {
local retry_count=0
while [ $retry_count -lt $MAX_RETRIES ]; do
echo "Attempting health check (Attempt $((retry_count + 1)) of $MAX_RETRIES)..."
# Run the health check script
$HEALTH_CHECK_SCRIPT
# Capture the exit status
exit_status=$?
# Check if the health check was successful
if [ $exit_status -eq 0 ]; then
echo "All services are healthy or running."
return 0 # Success
else
echo "Some services are not healthy or not running. Retrying in $RETRY_INTERVAL seconds..."
fi
# Increment the retry count
retry_count=$((retry_count + 1))
# Wait for the specified interval before retrying
sleep $RETRY_INTERVAL
done
echo "Health check failed after $((MAX_RETRIES * RETRY_INTERVAL / 60)) minutes."
return 1 # Failure
}
# Restarts the environment
echo ### Cleaning the environment...
cd ..
docker compose --profile test down -v
docker system prune -a -f
docker compose --profile test up --build -d web mariadb cassandra cassandra-setup mongo minio tikiwikidb-test smartdata-context-api
cd docker
# Path to the health check script
HEALTH_CHECK_SCRIPT="./health-check.sh"
# Define the maximum number of retries (3 minutes / 30 seconds = 6 retries)
MAX_RETRIES=6
RETRY_INTERVAL=30 # Interval in seconds
# Call the health check function
echo ### Waiting basic environment...
check_health
# Capture the result of the health check function
health_check_result=$?
# Check the result of the health check
if [ $health_check_result -ne 0 ]; then
echo "Exiting due to failed health check."
exit 1 # Exit with an error level indicating failure
fi
cd ..
wait_for_container cassandra-setup
# Now that the base structure is up, we can create the certificates to configure the ingress process
echo ### Generating and installing certificates...
rm dev-certificates/*.pem
rm dev-certificates/*.key
CERTID=`./gen-dev-certificate.sh test test | tail -n 1 | sed -n 's/.*id //p'`
echo Adding user for certificate $CERTID
docker exec -t web /usr/local/bin/command.sh create domain test -c $CERTID
cp dev-certificates/*.pem docker/ingress/config/test.crt
cp dev-certificates/*.key docker/ingress/config/test.key
echo ### Adjusting configuration for the tests...
# Disable cron for ingress - run manually
cd docker
cp ingress/config/jobs.json ingress/config/jobs.json.old
echo "{}" > ingress/config/jobs.json
# Adjusts config for test tikiwiki
cp variables.env variables.env.old
replace_tikiwiki_config
# Starts the ingress process
echo ### Starting the ingress process...
cd ..
docker compose --profile test up -d smartdata-context-ingress
# Call the health check function
cd docker
check_health
# Capture the result of the health check function
health_check_result=$?
# Check the result of the health check
if [ $health_check_result -ne 0 ]; then
echo "Exiting due to failed health check."
exit 1 # Exit with an error level indicating failure
fi
# Now lets import the SmartDataContext from the TikiWiki
echo ### Executing ingress process
cd ..
docker compose --profile test exec -t smartdata-context-ingress php /app/ingress.php tikiwiki-import test
## Check if the ingress was processed correctly
cp docker/ingress/config/test.crt docker/smartdatacontext-test/test.pem
cp docker/ingress/config/test.key docker/smartdatacontext-test/test.key
cp sample-clients/python/client.py docker/smartdatacontext-test/
cp sample-clients/python/main.py docker/smartdatacontext-test/
sed -i 's|API_URL="https://localhost/"|API_URL="https://web/"|' docker/smartdatacontext-test/main.py
output=$(docker compose --profile test run --build smartdatacontext-test python /app/test-ingress.py 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
output=$(docker compose --profile test run --build smartdatacontext-test python /app/main.py 2>&1)
exit_code=$?
fi
# Reverts configuration to original values
echo ### Reverting configuration to default
cd docker
cp ingress/config/jobs.json.old ingress/config/jobs.json
rm ingress/config/jobs.json.old
cp variables.env.old variables.env
rm variables.env.old
# End of the script
cd ..
docker compose --profile test down -v
docker system prune -a -f
if [ $exit_code -ne 0 ]; then
echo "Script failed."
echo "$output"
exit $exit_code
else
echo "Script completed successfully."
exit 0
fi
Loading