Add linux ui tests

This commit is contained in:
Théophile Diot 2023-09-22 08:47:47 +01:00
parent 2ad8861788
commit 432d1587c7
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
3 changed files with 220 additions and 43 deletions

View file

@ -93,6 +93,11 @@ jobs:
uses: ./.github/workflows/tests-ui.yml
with:
RELEASE: dev
tests-ui-linux:
needs: [code-security, build-packages]
uses: ./.github/workflows/tests-ui-linux.yml
with:
RELEASE: dev
# Core tests
prepare-tests-core:
@ -171,7 +176,7 @@ jobs:
# Push Linux packages
push-packages:
needs: [tests-core-linux]
needs: [tests-ui-linux, tests-core-linux]
strategy:
matrix:
linux: [ubuntu, debian, fedora, el]

119
.github/workflows/test-ui-linux.yml vendored Normal file
View file

@ -0,0 +1,119 @@
name: Core test Linux (REUSABLE)
on:
workflow_call:
inputs:
TEST:
required: true
type: string
RELEASE:
required: true
type: string
jobs:
tests:
runs-on: ubuntu-latest
steps:
# Prepare
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
- name: Install Firefox manually and dependencies
run: |
sudo apt purge -y firefox
sudo apt update
sudo apt install --no-install-recommends -y zip nodejs tar bzip2 wget curl grep libx11-xcb1 libappindicator3-1 libasound2 libdbus-glib-1-2 libxtst6 libxt6
wget -O firefox-setup.tar.bz2 "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64"
tar -xjf firefox-setup.tar.bz2 -C /opt/
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
sudo chmod 755 /opt/firefox
sudo chmod 755 /opt/firefox/firefox
rm -f firefox-setup.tar.bz2
- name: Download geckodriver
uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 20
command: |
GECKODRIVER_VERSION=`curl -i https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+\.[0-9]+\.[0-9]+'` && \
wget -O geckodriver.tar.gz -w 5 https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz
sudo tar -xzf geckodriver.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/geckodriver
rm -f geckodriver.tar.gz
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull BW linux ubuntu test image
run: docker pull ghcr.io/bunkerity/ubuntu-tests:${{ inputs.RELEASE }}
- name: Copy deb file to host
run: |
container_id=$(docker create "ghcr.io/bunkerity/ubuntu-tests:${{ inputs.RELEASE }}")
docker cp "$container_id:/opt/bunkerweb_dev-1_amd64.deb" "/tmp/bunkerweb.deb"
docker rm "$container_id"
- name: Install BunkerWeb
run: |
sudo apt install -y gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt update
sudo apt install -y nginx=1.24.0-1~jammy
- name: Fix version without a starting number
if: inputs.RELEASE == 'testing' || inputs.RELEASE == 'dev'
run: echo "force-bad-version" | sudo tee -a /etc/dpkg/dpkg.cfg
- name: Install BunkerWeb
run: sudo apt install -fy /tmp/bunkerweb.deb
- name: Edit configuration files
run: |
# Misc
echo "127.0.0.1 www.example.com" | sudo tee -a /etc/hosts
echo "127.0.0.1 app1.example.com" | sudo tee -a /etc/hosts
# BunkerWeb
echo "SERVER_NAME=www.example.com" | sudo tee /etc/bunkerweb/variables.env
echo "HTTP_PORT=80" | sudo tee -a /etc/bunkerweb/variables.env
echo "HTTPS_PORT=443" | sudo tee -a /etc/bunkerweb/variables.env
echo 'DNS_RESOLVERS=9.9.9.9 8.8.8.8 8.8.4.4' | sudo tee -a /etc/bunkerweb/variables.env
echo "MULTISITE=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "LOG_LEVEL=info" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_BUNKERNET=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_BLACKLIST=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "DISABLE_DEFAULT_SERVER=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_CLIENT_CACHE=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_GZIP=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "DATASTORE_MEMORY_SIZE=384m" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_USE_UI=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_SERVE_FILES=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_USE_REVERSE_PROXY=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_REVERSE_PROXY_URL=/admin" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_REVERSE_PROXY_HOST=http://127.0.0.1:7000" | sudo tee -a /etc/bunkerweb/variables.env
echo "www.example.com_INTERCEPTED_ERROR_CODES=400 405 413 429 500 501 502 503 504" | sudo tee -a /etc/bunkerweb/variables.env
echo "ADMIN_USERNAME=admin" | sudo tee /etc/bunkerweb/ui.env
echo "ADMIN_PASSWORD=S\$cr3tP@ssw0rd" | sudo tee -a /etc/bunkerweb/ui.env
sudo chown nginx:nginx /etc/bunkerweb/*.env
sudo chmod 777 /etc/bunkerweb/*.env
- name: Run tests
run: |
cd ./tests/ui
MAKEFLAGS="-j $(nproc)" find . -name "requirements.txt" -exec pip install -r {} \;
touch test.txt
zip test.zip test.txt
rm test.txt
echo '{ \
"id": "discord", \
"name": "Discord", \
"description": "Send alerts to a Discord channel (using webhooks).", \
"version": "0.1", \
"stream": "no", \
"settings": {} \
}' | tee plugin.json
zip discord.zip plugin.json
rm plugin.json
./test.sh "linux"

View file

@ -1,61 +1,114 @@
#!/bin/bash
# Go to env
cd ./tests/ui
integration=$1
if [ -z "$integration" ] ; then
echo "Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "Integration \"$integration\" is not supported ❌"
exit 1
fi
# Prepare environment
sed -i "s@bunkerity/bunkerweb:.*@bunkerweb-tests@" docker-compose.yml
sed -i "s@bunkerity/bunkerweb-scheduler:.*@scheduler-tests@" docker-compose.yml
sed -i "s@bunkerity/bunkerweb-ui:.*@ui-tests@" docker-compose.yml
if [ "$integration" = "docker" ] ; then
sed -i "s@bunkerity/bunkerweb:.*@bunkerweb-tests@" docker-compose.yml
sed -i "s@bunkerity/bunkerweb-scheduler:.*@scheduler-tests@" docker-compose.yml
sed -i "s@bunkerity/bunkerweb-ui:.*@ui-tests@" docker-compose.yml
# Start stack
docker-compose pull bw-docker-proxy app1
if [ $? -ne 0 ] ; then
echo "❌ Pull failed"
exit 1
fi
docker-compose up -d
if [ $? -ne 0 ] ; then
echo "❌ Up failed"
exit 1
# Start stack
docker-compose pull bw-docker-proxy app1
if [ $? -ne 0 ] ; then
echo "❌ Pull failed"
exit 1
fi
echo "🤖 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🤖 Up failed, retrying ... ⚠️"
docker compose down -v --remove-orphans
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🤖 Up failed ❌"
exit 1
fi
fi
fi
i=0
while [ $i -lt 120 ] ; do
containers=("ui_bw_1" "ui_bw-scheduler_1" "ui_bw-ui_1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
echo "⚠️ Container $container is not healthy yet ..."
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("ui_bw_1" "ui_bw-scheduler_1" "ui_bw-ui_1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
echo "⚠️ Container $container is not healthy yet ..."
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
break
if [ $i -ge 120 ] ; then
docker-compose logs
echo "❌ Docker stack is not healthy"
exit 1
fi
else
while [ $i -lt 120 ] ; do
check="$(sudo cat /var/log/bunkerweb/error.log | grep "BunkerWeb is ready")"
if ! [ -z "$check" ] ; then
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker-compose logs
echo "❌ Docker stack is not healthy"
exit 1
fi
# Start tests
docker-compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "❌ Build failed"
exit 1
if [ "$integration" == "docker" ] ; then
docker-compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "❌ Build failed"
exit 1
fi
docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from ui-tests
else
python3 main.py
fi
docker-compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from ui-tests
ret=$?
if [ $ret -ne 0 ] ; then
docker-compose logs
echo "❌ Up failed"
if [ $? -ne 0 ] ; then
if [ "$integration" == "docker" ] ; then
docker compose logs
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
echo "❌ Tests failed"
exit 1
fi
# Exit
exit $?
exit 0