2023-05-15 00:57:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2023-09-20 14:41:33 +00:00
|
|
|
integration=$1
|
2023-05-15 00:57:58 +00:00
|
|
|
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ -z "$integration" ] ; then
|
|
|
|
|
echo "⭕ Please provide an integration name as argument ❌"
|
2023-05-15 00:57:58 +00:00
|
|
|
exit 1
|
2023-09-20 14:41:33 +00:00
|
|
|
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
|
|
|
|
|
echo "⭕ Integration \"$integration\" is not supported ❌"
|
2023-05-15 00:57:58 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-09-20 14:41:33 +00:00
|
|
|
echo "⭕ Building errors stack for integration \"$integration\" ..."
|
|
|
|
|
|
|
|
|
|
# Starting stack
|
2023-09-26 12:11:30 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
2023-09-20 14:41:33 +00:00
|
|
|
docker compose -f docker-compose.test.yml build
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
|
echo "⭕ Build failed ❌"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
sudo systemctl stop bunkerweb
|
|
|
|
|
echo "ERRORS=" | sudo tee -a /etc/bunkerweb/variables.env
|
|
|
|
|
echo "INTERCEPTED_ERROR_CODES=400 401 403 404 405 413 429 500 501 502 503 504" | sudo tee -a /etc/bunkerweb/variables.env
|
|
|
|
|
sudo touch /var/www/html/index.html
|
2023-09-22 08:17:31 +00:00
|
|
|
sudo mkdir -p /var/www/html/errors
|
2023-09-20 14:41:33 +00:00
|
|
|
sudo cp "403.html" "/var/www/html/errors/403.html"
|
2023-10-26 13:23:02 +00:00
|
|
|
sudo cp ready.conf /etc/bunkerweb/configs/server-http
|
2023-09-20 14:41:33 +00:00
|
|
|
fi
|
|
|
|
|
|
2023-05-15 00:57:58 +00:00
|
|
|
manual=0
|
|
|
|
|
end=0
|
|
|
|
|
cleanup_stack () {
|
|
|
|
|
exit_code=$?
|
|
|
|
|
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@ERRORS: "403=/errors/403.html"@ERRORS: ""@' {} \;
|
|
|
|
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@INTERCEPTED_ERROR_CODES: "400 401 403 404 405 413 429 500 501 502 503 504"@INTERCEPTED_ERROR_CODES: "400 401 403 404 405 413 429 500 501 502 503 504"@' {} \;
|
|
|
|
|
else
|
|
|
|
|
sudo sed -i 's@ERRORS=.*$@ERRORS=@' /etc/bunkerweb/variables.env
|
|
|
|
|
sudo sed -i 's@INTERCEPTED_ERROR_CODES=.*$@INTERCEPTED_ERROR_CODES=400 401 403 404 405 413 429 500 501 502 503 504@' /etc/bunkerweb/variables.env
|
|
|
|
|
unset ERRORS
|
|
|
|
|
unset INTERCEPTED_ERROR_CODES
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "⭕ Cleaning up current stack ..."
|
|
|
|
|
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
docker compose down -v --remove-orphans
|
|
|
|
|
else
|
|
|
|
|
sudo systemctl stop bunkerweb
|
|
|
|
|
sudo truncate -s 0 /var/log/bunkerweb/error.log
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-05-15 00:57:58 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
2023-09-20 14:41:33 +00:00
|
|
|
echo "⭕ Cleanup failed ❌"
|
2023-05-15 00:57:58 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "⭕ Cleaning up current stack done ✅"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Cleanup stack on exit
|
|
|
|
|
trap cleanup_stack EXIT
|
|
|
|
|
|
|
|
|
|
for test in "default" "custom_403" "without_403"
|
|
|
|
|
do
|
|
|
|
|
if [ "$test" = "default" ] ; then
|
|
|
|
|
echo "⭕ Running tests with default configuration ..."
|
|
|
|
|
elif [ "$test" = "custom_403" ] ; then
|
|
|
|
|
echo "⭕ Running tests with a custom 403 page ..."
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@ERRORS: ""@ERRORS: "403=/errors/403.html"@' {} \;
|
|
|
|
|
else
|
|
|
|
|
sudo sed -i 's@ERRORS=@ERRORS=403=/errors/403.html@' /etc/bunkerweb/variables.env
|
|
|
|
|
export ERRORS="403=/errors/403.html"
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
elif [ "$test" = "without_403" ] ; then
|
|
|
|
|
echo "⭕ Running tests without a 403 being intercepted ..."
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@ERRORS: "403=/errors/403.html"@ERRORS: ""@' {} \;
|
|
|
|
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@INTERCEPTED_ERROR_CODES: "400 401 403 404 405 413 429 500 501 502 503 504"@INTERCEPTED_ERROR_CODES: "400 401 404 405 413 429 500 501 502 503 504"@' {} \;
|
|
|
|
|
else
|
|
|
|
|
sudo sed -i 's@ERRORS=.*$@ERRORS=@' /etc/bunkerweb/variables.env
|
|
|
|
|
sudo sed -i 's@INTERCEPTED_ERROR_CODES=.*$@INTERCEPTED_ERROR_CODES=400 401 404 405 413 429 500 501 502 503 504@' /etc/bunkerweb/variables.env
|
|
|
|
|
unset ERRORS
|
|
|
|
|
export INTERCEPTED_ERROR_CODES="400 401 404 405 413 429 500 501 502 503 504"
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "⭕ Starting stack ..."
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
2023-07-04 19:59:16 +00:00
|
|
|
docker compose up -d
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-05-15 12:47:52 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
2023-09-20 14:41:33 +00:00
|
|
|
echo "⭕ Up failed, retrying ... ⚠️"
|
|
|
|
|
manual=1
|
|
|
|
|
cleanup_stack
|
|
|
|
|
manual=0
|
|
|
|
|
docker compose up -d
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
|
echo "⭕ Up failed ❌"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
sudo systemctl start bunkerweb
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
|
echo "⭕ Start failed ❌"
|
2023-05-15 12:47:52 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if stack is healthy
|
|
|
|
|
echo "⭕ Waiting for stack to be healthy ..."
|
|
|
|
|
i=0
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
while [ $i -lt 120 ] ; do
|
|
|
|
|
containers=("errors-bw-1" "errors-bw-scheduler-1")
|
|
|
|
|
healthy="true"
|
|
|
|
|
for container in "${containers[@]}" ; do
|
2023-10-02 10:05:15 +00:00
|
|
|
check="$(docker inspect --format "{{json .State.Health }}" "$container" | grep "healthy")"
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$check" = "" ] ; then
|
|
|
|
|
healthy="false"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if [ "$healthy" = "true" ] ; then
|
|
|
|
|
echo "⭕ Docker stack is healthy ✅"
|
2023-05-15 00:57:58 +00:00
|
|
|
break
|
|
|
|
|
fi
|
2023-09-20 14:41:33 +00:00
|
|
|
sleep 1
|
|
|
|
|
i=$((i+1))
|
2023-05-15 00:57:58 +00:00
|
|
|
done
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ $i -ge 120 ] ; then
|
|
|
|
|
docker compose logs
|
|
|
|
|
echo "⭕ Docker stack is not healthy ❌"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
2023-09-23 11:13:42 +00:00
|
|
|
healthy="false"
|
|
|
|
|
retries=0
|
|
|
|
|
while [[ $healthy = "false" && $retries -lt 5 ]] ; do
|
|
|
|
|
while [ $i -lt 120 ] ; do
|
2023-09-23 12:22:20 +00:00
|
|
|
if sudo grep -q "BunkerWeb is ready" "/var/log/bunkerweb/error.log" ; then
|
2023-09-23 11:13:42 +00:00
|
|
|
echo "⭕ Linux stack is healthy ✅"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
sleep 1
|
|
|
|
|
i=$((i+1))
|
|
|
|
|
done
|
|
|
|
|
if [ $i -ge 120 ] ; then
|
|
|
|
|
sudo journalctl -u bunkerweb --no-pager
|
|
|
|
|
echo "🛡️ Showing BunkerWeb error logs ..."
|
|
|
|
|
sudo cat /var/log/bunkerweb/error.log
|
|
|
|
|
echo "🛡️ Showing BunkerWeb access logs ..."
|
|
|
|
|
sudo cat /var/log/bunkerweb/access.log
|
|
|
|
|
echo "⭕ Linux stack is not healthy ❌"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-10-02 10:05:15 +00:00
|
|
|
if sudo journalctl -u bunkerweb --no-pager | grep -q "SYSTEMCTL - ❌ " ; then
|
2023-09-23 11:13:42 +00:00
|
|
|
echo "⭕ ⚠ Linux stack got an issue, restarting ..."
|
2023-09-23 14:05:21 +00:00
|
|
|
sudo journalctl --rotate
|
|
|
|
|
sudo journalctl --vacuum-time=1s
|
2023-09-23 12:22:20 +00:00
|
|
|
manual=1
|
|
|
|
|
cleanup_stack
|
|
|
|
|
manual=0
|
2023-09-23 11:13:42 +00:00
|
|
|
sudo systemctl start bunkerweb
|
|
|
|
|
retries=$((retries+1))
|
|
|
|
|
else
|
|
|
|
|
healthy="true"
|
2023-09-20 14:41:33 +00:00
|
|
|
fi
|
|
|
|
|
done
|
2023-10-02 10:05:15 +00:00
|
|
|
if [ "$retries" -ge 5 ] ; then
|
2023-09-23 11:13:42 +00:00
|
|
|
echo "⭕ Linux stack could not be healthy ❌"
|
2023-09-20 14:41:33 +00:00
|
|
|
exit 1
|
2023-05-15 00:57:58 +00:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Start tests
|
|
|
|
|
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
|
|
|
|
else
|
|
|
|
|
python3 main.py
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
|
2023-10-02 10:05:15 +00:00
|
|
|
# shellcheck disable=SC2181
|
2023-05-15 00:57:58 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
|
echo "⭕ Test \"$test\" failed ❌"
|
|
|
|
|
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
|
2023-09-20 14:41:33 +00:00
|
|
|
if [ "$integration" == "docker" ] ; then
|
|
|
|
|
docker compose logs bw bw-scheduler
|
|
|
|
|
else
|
|
|
|
|
sudo journalctl -u bunkerweb --no-pager
|
|
|
|
|
echo "🛡️ Showing BunkerWeb error logs ..."
|
|
|
|
|
sudo cat /var/log/bunkerweb/error.log
|
|
|
|
|
echo "🛡️ Showing BunkerWeb access logs ..."
|
|
|
|
|
sudo cat /var/log/bunkerweb/access.log
|
|
|
|
|
echo "🛡️ Showing Geckodriver logs ..."
|
|
|
|
|
sudo cat geckodriver.log
|
|
|
|
|
fi
|
2023-05-15 00:57:58 +00:00
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "⭕ Test \"$test\" succeeded ✅"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
manual=1
|
|
|
|
|
cleanup_stack
|
|
|
|
|
manual=0
|
|
|
|
|
|
|
|
|
|
echo " "
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
end=1
|
|
|
|
|
echo "⭕ Tests are done ! ✅"
|