cleanup tests directory and init tests refactoring for drupal

This commit is contained in:
bunkerity 2022-07-20 11:03:14 +02:00
parent c14b08faa7
commit d1d2e51a31
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
21 changed files with 294 additions and 784 deletions

View File

@ -374,14 +374,14 @@ jobs:
run: cat /opt/.runner_env >> $GITHUB_ENV
# Run tests
# - name: Run Docker tests
# run: ./tests/main.py "docker"
# - name: Run Autoconf tests
# run: ./tests/main.py "autoconf"
# - name: Run Swarm tests
# run: ./tests/main.py "swarm"
# - name: Run Kubernetes tests
# run: ./tests/main.py "kubernetes"
- name: Run Docker tests
run: ./tests/main.py "docker"
- name: Run Autoconf tests
run: ./tests/main.py "autoconf"
- name: Run Swarm tests
run: ./tests/main.py "swarm"
- name: Run Kubernetes tests
run: ./tests/main.py "kubernetes"
- name: Generate Linux packages and build test images
run: ./tests/linux.sh ${{ env.BUILD_MODE }}
- name: Run Linux Ubuntu tests

View File

@ -4,8 +4,11 @@
- Fix various documentation errors/typos and add various enhancements
- Fix ui.env not read when using Linux integration
- Fix wrong variables.env path when using Linux integration
- Fix missing default server when TEMP_NGINX=yes
- Fix check if BunkerNet is activated on default server
- Fix request crash when mmdb lookup fails
- Add Ansible integration in beta
- Add \*_CUSTOM_CONF_\* setting to automatically add custom config files from setting value
- Add DENY_HTTP_STATUS setting to choose standard 403 error page (default) or 444 to close connection when access is denied
- Add CORS (Cross-Origin Resource Sharing) core plugin

View File

@ -0,0 +1,42 @@
version: '3'
services:
mydrupal:
image: drupal:9-apache
networks:
bw-services:
aliases:
- mydrupal
volumes:
- ./drupal-modules:/var/www/html/modules
- ./drupal-profiles:/var/www/html/profiles
- ./drupal-themes:/var/www/html/themes
- ./drupal-sites:/var/www/html/sites
labels:
- bunkerweb.SERVER_NAME=www.example.com # replace with your domain
- bunkerweb.AUTO_LETS_ENCRYPT=yes
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mydrupal
- bunkerweb.LIMIT_REQ_URL_1=/core/install.php
- bunkerweb.LIMIT_REQ_RATE_1=5r/s
mydb:
image: mariadb
networks:
bw-services:
aliases:
- mydb
volumes:
- ./db-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=drupaldb
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password
networks:
bw-services:
external:
name: bw-services

View File

@ -0,0 +1,110 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
bunkerweb.io/AUTO_LETS_ENCRYPT: "yes"
bunkerweb.io/LIMIT_REQ_URL_1: "/core/install.php"
bunkerweb.io/LIMIT_REQ_RATE_1: "5r/s"
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: svc-drupal
port:
number: 80
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cfg-bunkerweb-drupal-modsec-crs
annotations:
bunkerweb.io/CONFIG_TYPE: "modsec-crs"
bunkerweb.io/CONFIG_SITE: "www.example.com"
data:
drupal: |
SecAction \
"id:900130,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.crs_exclusions_drupal=1"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: drupal
labels:
app: drupal
spec:
replicas: 1
selector:
matchLabels:
app: drupal
template:
metadata:
labels:
app: drupal
spec:
containers:
- name: drupal
image: drupal:9-apache
---
apiVersion: v1
kind: Service
metadata:
name: svc-drupal
spec:
selector:
app: drupal
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: db
labels:
app: db
spec:
replicas: 1
selector:
matchLabels:
app: db
template:
metadata:
labels:
app: db
spec:
containers:
- name: db
image: mariadb
env:
- name: MYSQL_ROOT_PASSWORD
value: db-root-pwd
- name: MYSQL_DATABASE
value: drupaldb
- name: MYSQL_USER
value: user
- name: MYSQL_PASSWORD
value: db-user-pwd
---
apiVersion: v1
kind: Service
metadata:
name: svc-db
spec:
selector:
app: db
ports:
- protocol: TCP
port: 3306
targetPort: 3306

15
examples/drupal/linux-setup.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
if [ $(id -u) -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
curl https://ftp.drupal.org/files/projects/drupal-9.4.2.tar.gz -Lo /tmp/drupal.tar.gz
tar -xvzf /tmp/drupal.tar.gz -C /tmp
cp -r /tmp/drupal-9.4.2/* /opt/bunkerweb/www
chown -R www-data:nginx /opt/bunkerweb/www
find /opt/bunkerweb/www -type d -exec chmod 750 /opt/bunkerweb/www {} \;
find /opt/bunkerweb/www -type f -exec chmod 640 /opt/bunkerweb/www {} \;
systemctl start php-fpm

13
examples/drupal/swarm-setup.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# docker-compose doesn't support assigning labels to configs
# so we need to create the configs with the CLI
# bunkerweb.CONFIG_TYPE accepted values are http, stream, server-http, server-stream, default-server-http, modsec and modsec-crs
# bunkerweb.CONFIG_SITE lets you choose on which web service the config should be applied (MULTISITE mode) and if it's not set, the config will be applied for all services
# more info at https://docs.bunkerweb.io
# remove configs if existing
docker config rm cfg_drupal_modsec_crs
# create configs
docker config create -l bunkerweb.CONFIG_TYPE=modsec-crs cfg_drupal_modsec_crs -l bunkerweb.CONFIG_SITE=www.example.com ./bw-data/configs/modsec-crs/drupal.conf

53
examples/drupal/swarm.yml Normal file
View File

@ -0,0 +1,53 @@
version: '3.3'
services:
mydrupal:
image: drupal:9-apache
networks:
- bw-services
volumes:
- drupal-modules:/var/www/html/modules
- drupal-profiles:/var/www/html/profiles
- drupal-themes:/var/www/html/themes
- drupal-sites:/var/www/html/sites
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com # replace with your domain
- bunkerweb.AUTO_LETS_ENCRYPT=yes
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mydrupal
- bunkerweb.LIMIT_REQ_URL_1=/core/install.php
- bunkerweb.LIMIT_REQ_RATE_1=5r/s
mydb:
image: mariadb
networks:
- bw-services
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=drupaldb
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password
deploy:
placement:
constraints:
- "node.role==worker"
networks:
bw-services:
external:
name: bw-services
volumes:
drupal-modules:
drupal-profiles:
drupal-themes:
drupal-sites:
db-data:

View File

@ -0,0 +1,18 @@
{
"name": "drupal",
"kinds": [
"docker",
"autoconf",
"swarm",
"kubernetes",
"linux"
],
"timeout": 60,
"tests": [
{
"type": "string",
"url": "https://www.example.com",
"string": "drupal"
}
]
}

View File

@ -0,0 +1,14 @@
HTTP_PORT=80
HTTPS_PORT=443
DNS_RESOLVERS=8.8.8.8 8.8.4.4
MULTISITE=yes
# Replace with your domain
SERVER_NAME=www.example.com
DISABLE_DEFAULT_SERVER=yes
AUTO_LETS_ENCRYPT=yes
USE_CLIENT_CACHE=yes
USE_GZIP=yes
LIMIT_REQ_URL_1=/core/install.php
LIMIT_REQ_RATE_1=5r/s
LOCAL_PHP=/run/php/php-fpm.sock
LOCAL_PHP_PATH=/opt/bunkerweb/www

View File

@ -15,7 +15,7 @@ rm -f /lib/systemd/system/anaconda.target.wants/*;
COPY linux/nginx.repo /etc/yum.repos.d/nginx.repo
RUN dnf install curl yum-utils epel-release -y && \
RUN dnf install php-fpm curl yum-utils epel-release -y && \
dnf install nginx-1.20.2 -y
COPY ./packages/centos/*.rpm /opt

View File

@ -24,7 +24,7 @@ RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/lib/systemd/system/systemd-update-utmp*
RUN apt update && \
apt-get install curl gnupg2 ca-certificates python3-pip -y && \
apt-get install php-fpm curl gnupg2 ca-certificates python3-pip -y && \
echo "deb https://nginx.org/packages/debian/ bullseye nginx" > /etc/apt/sources.list.d/nginx.list && \
echo "deb-src https://nginx.org/packages/debian/ bullseye nginx" >> /etc/apt/sources.list.d/nginx.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 && \

View File

@ -19,7 +19,7 @@ RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
# Nginx
RUN dnf update -y && \
dnf install -y curl gnupg2 ca-certificates redhat-lsb-core python3-pip && \
dnf install -y php-fpm curl gnupg2 ca-certificates redhat-lsb-core python3-pip && \
dnf install nginx-1.20.2 -y
COPY ./packages/fedora/*.rpm /opt

View File

@ -24,7 +24,7 @@ RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
/lib/systemd/system/systemd-update-utmp*
RUN apt update && \
apt-get install curl gnupg2 ca-certificates lsb-release ubuntu-keyring software-properties-common python3-pip -y && \
apt-get install php-fpm curl gnupg2 ca-certificates lsb-release ubuntu-keyring software-properties-common python3-pip -y && \
echo "deb https://nginx.org/packages/ubuntu/ jammy nginx" > /etc/apt/sources.list.d/nginx.list && \
echo "deb-src https://nginx.org/packages/ubuntu/ jammy nginx" >> /etc/apt/sources.list.d/nginx.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 && \

View File

@ -1,54 +0,0 @@
###############################################################
# HOW TO USE UBUNTU #
###############################################################
# 1. Build the Dockerfile for Ubuntu
sudo docker build -t ubuntu -f Container/Ubuntu/Dockerfile .
# 2. Run it as daemon
sudo docker run -d --name ubuntu --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -v "Deb_Folder":/data ubuntu
# 3. Execute
sudo docker exec -it ubuntu bash
#______________________________________________________________________________________________________________________#
###############################################################
# HOW TO USE DEBIAN #
###############################################################
# 1. Build the Dockerfile for Debian
sudo docker build -t debian -f Container/Debian/Dockerfile .
# 2. Run it as daemon
sudo docker run -d --name debian --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -v "Deb_Folder":/data debian
# 3. Execute
sudo docker exec -it debian bash
#______________________________________________________________________________________________________________________#
###############################################################
# HOW TO USE FEDORA #
###############################################################
# Build the Dockerfile for Debian
sudo docker build -t fedora -f Container/Fedora/Dockerfile .
# Run it as daemon
sudo docker run -d --name fedora --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -v "Deb_Folder":/data fedora
# Execute
sudo docker exec -it fedora bash
#______________________________________________________________________________________________________________________#
###############################################################
# HOW TO USE CENTOS #
###############################################################
# Build the Dockerfile for Debian
sudo docker build -t centos -f Container/Centos8/Dockerfile .
# Run it as daemon
sudo docker run -d --name centos --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -v "Deb_Folder":/data centos
# Execute
sudo docker exec -it centos bash
#______________________________________________________________________________________________________________________#

View File

@ -1,114 +0,0 @@
#!/bin/bash
. ./tests/utils/utils.sh
. /opt/.runner_env
function single_autoconf_test() {
example="$1"
wait_time="$2"
shift
shift
asserts=("$@")
echo "Testing $example ..."
exec_docker_example "$example"
if [ $? -ne 0 ] ; then
cd /tmp/autoconf
docker-compose logs
docker-compose down -v > /dev/null 2>&1
echo "$example failed (exec) ..."
exit 1
fi
for assert in "${asserts[@]}" ; do
url="$(echo "$assert" | cut -d ' ' -f 1)"
str="$(echo "$assert" | cut -d ' ' -f 2)"
if [ "$(echo "$example" | grep websocket)" = "" ] ; then
curl_assert "$url" "$str" "$wait_time"
else
curl_assert "$url" "$str" "$wait_time" "ws"
fi
ret=$?
if [ $ret -ne 0 ] ; then
current_dir="$(pwd)"
cd /tmp/autoconf
docker-compose logs
docker-compose down -v > /dev/null 2>&1
cd "/tmp/tests/$example"
docker-compose logs
cd "$current_dir"
rm_example "$example"
echo "$example failed (assert) ..."
exit 1
fi
done
rm_example "$example"
echo "$example success !"
}
# Setup data folder if not present
if [ ! -d "/tmp/bw-data" ] ; then
mkdir /tmp/bw-data
sudo chown root:101 /tmp/bw-data
sudo chmod 770 /tmp/bw-data
fi
for folder in $(echo "configs plugins www") ; do
sudo rm -rf "/tmp/bw-data/${folder}" > /dev/null 2>&1
done
echo "Running autoconf tests ..."
# Start autoconf
if [ ! -d "/tmp/autoconf" ] ; then
mkdir /tmp/autoconf
fi
rm -rf /tmp/autoconf/*
cp -r ./integrations/autoconf/* /tmp/autoconf
sed -i 's@bunkerity/bunkerweb:.*$@10.20.1.1:5000/bw-tests:latest@g' /tmp/autoconf/docker-compose.yml
sed -i 's@bunkerity/bunkerweb-autoconf:.*$@10.20.1.1:5000/bw-autoconf-tests:latest@g' /tmp/autoconf/docker-compose.yml
sed -i 's@\./bw\-data:/@/tmp/bw\-data:/@g' /tmp/autoconf/docker-compose.yml
current_dir="$(pwd)"
cd "/tmp/autoconf"
echo "starting autoconf ..."
docker-compose down -v > /dev/null 2>&1
docker-compose pull > /dev/null 2>&1
ret="$(docker-compose up -d 2>&1)"
if [ $? -ne 0 ] ; then
echo "$ret"
echo "autoconf failed (up)"
fi
current_wait=0
healthy="no"
while [ $current_wait -lt 30 ] ; do
check="$(docker inspect --format "{{json .State.Health }}" autoconf_mybunker_1 | grep healthy)"
if [ "$check" != "" ] ; then
healthy="yes"
break
fi
current_wait=$((current_wait+1))
sleep 1
done
if [ "$healthy" = "no" ] ; then
echo "$ret"
docker-compose logs
docker-compose down -v > /dev/null 2>&1
echo "autoconf failed (not healthy)"
exit 1
fi
cd "$current_dir"
# reverse
single_autoconf_test "autoconf-reverse-proxy" "60" "https://$TEST_DOMAIN1_1 hello" "https://$TEST_DOMAIN1_2 hello" "https://$TEST_DOMAIN1_3 hello"
# php
single_autoconf_test "autoconf-php" "60" "https://$TEST_DOMAIN1_1 app1" "https://$TEST_DOMAIN1_2 app2" "https://$TEST_DOMAIN1_3 app3"
# configs
single_docker_test "autoconf-configs" "60" "https://$TEST_DOMAIN1/hello app1" "https://$TEST_DOMAIN2/hello app2" "https://$TEST_DOMAIN3/hello app3"
# cleanup
current_dir="$(pwd)"
cd "/tmp/autoconf"
docker-compose down -v > /dev/null 2>&1
cd "$current_dir"
exit 0

View File

@ -1,130 +0,0 @@
#!/bin/bash
. ./tests/utils/utils.sh
. /opt/.runner_env
function single_docker_test() {
example="$1"
wait_time="$2"
shift
shift
asserts=("$@")
echo "Testing $example ..."
exec_docker_example "$example"
if [ $? -ne 0 ] ; then
echo "$example failed (exec) ..."
exit 1
fi
for assert in "${asserts[@]}" ; do
url="$(echo "$assert" | cut -d ' ' -f 1)"
str="$(echo "$assert" | cut -d ' ' -f 2)"
if [ "$(echo "$example" | grep websocket)" = "" ] ; then
curl_assert "$url" "$str" "$wait_time"
else
curl_assert "$url" "$str" "$wait_time" "ws"
fi
ret=$?
if [ $ret -ne 0 ] ; then
current_dir="$(pwd)"
cd "/tmp/tests/$example"
docker-compose logs
cd "$current_dir"
rm_example "$example"
echo "$example failed (assert) ..."
exit 1
fi
done
rm_example "$example"
echo "$example success !"
}
# Setup data folder if not present
if [ ! -d "/tmp/bw-data" ] ; then
mkdir /tmp/bw-data
fi
sudo chown 101:101 /tmp/bw-data
sudo chmod 777 /tmp/bw-data
if [ -d "/tmp/bw-data/configs" ] ; then
sudo chown -R 101:101 /tmp/bw-data/configs
sudo chmod -R 777 /tmp/bw-data/configs
fi
echo "Running Docker tests ..."
# authelia
single_docker_test "authelia" "60" "https://$TEST_DOMAIN1_1 authelia" "https://$TEST_DOMAIN1_2 authelia"
# authentik
# TODO : find a way to load a basic configuration for automatic tests
# single_docker_test "authentik" "60" "https://$TEST_DOMAIN1_1 authentik" "https://$TEST_DOMAIN1_2 authentik"
# drupal
single_docker_test "drupal" "60" "https://$TEST_DOMAIN1 drupal"
# docker configs
single_docker_test "docker-configs" "30" "https://$TEST_DOMAIN1_1/hello world" "https://$TEST_DOMAIN1_2/hello world" "https://$TEST_DOMAIN1_1/app1 app1" "https://$TEST_DOMAIN1_2/app2 app2"
# ghost
single_docker_test "ghost" "30" "https://$TEST_DOMAIN1 ghost"
# gogs
single_docker_test "gogs" "30" "https://$TEST_DOMAIN1 gogs"
# hardened
single_docker_test "hardened" "30" "https://$TEST_DOMAIN1 hello"
# joomla
single_docker_test "joomla" "60" "https://$TEST_DOMAIN1 joomla"
# load-balancer
single_docker_test "load-balancer" "30" "https://$TEST_DOMAIN1 hello"
# magento
single_docker_test "magento" "300" "https://$TEST_DOMAIN1 magento"
# mattermost
single_docker_test "mattermost" "60" "https://$TEST_DOMAIN1 mattermost"
# moodle
single_docker_test "moodle" "300" "https://$TEST_DOMAIN1 moodle"
# nextcloud
single_docker_test "nextcloud" "120" "https://$TEST_DOMAIN1 nextcloud"
# passbolt
single_docker_test "passbolt" "120" "https://$TEST_DOMAIN1 passbolt"
# php-multisite
single_docker_test "php-multisite" "30" "https://$TEST_DOMAIN1_1 app1" "https://$TEST_DOMAIN1_2 app2"
# php-singlesite
single_docker_test "php-singlesite" "30" "https://$TEST_DOMAIN1 hello"
# prestashop
single_docker_test "prestashop" "120" "https://$TEST_DOMAIN1 prestashop"
# radarr
single_docker_test "radarr" "60" "https://$TEST_DOMAIN1 radarr"
# redmine
single_docker_test "redmine" "60" "https://$TEST_DOMAIN1 redmine"
# reverse-proxy-multisite
single_docker_test "reverse-proxy-multisite" "30" "https://$TEST_DOMAIN1_1 app1" "https://$TEST_DOMAIN1_2 hello"
# reverse-proxy-singlesite
single_docker_test "reverse-proxy-singlesite" "30" "https://$TEST_DOMAIN1/app1/ app1" "https://$TEST_DOMAIN1/app2/ hello"
# reverse-proxy-websocket
cp ./tests/utils/websocat_amd64-linux /tmp/
chmod +x ./tests/utils/websocat_amd64-linux
# todo
# tomcat
single_docker_test "tomcat" "30" "https://$TEST_DOMAIN1 tomcat"
# wordpress
single_docker_test "wordpress" "30" "https://$TEST_DOMAIN1 wordpress"
exit 0

View File

@ -1,147 +0,0 @@
#!/bin/bash
. ./tests/utils/utils.sh
. /opt/.runner_env
function single_k8s_test() {
example="$1"
wait_time="$2"
shift
shift
asserts=("$@")
echo "Testing $example ..."
exec_k8s_example "$example"
if [ $? -ne 0 ] ; then
for pod in $(sudo kubectl get pods | cut -d ' ' -f 1 | grep -v NAME) ; do
sudo kubectl logs $pod
done
cd "/tmp/k8s"
sudo kubectl delete -f bunkerweb.yml > /dev/null 2>&1
sudo kubectl delete -f rbac.yml > /dev/null 2>&1
sudo kubectl delete -f k8s.yml > /dev/null 2>&1
echo "$example failed (exec) ..."
exit 1
fi
for assert in "${asserts[@]}" ; do
url="$(echo "$assert" | cut -d ' ' -f 1)"
str="$(echo "$assert" | cut -d ' ' -f 2)"
if [ "$(echo "$example" | grep websocket)" = "" ] ; then
curl_assert "$url" "$str" "$wait_time"
else
curl_assert "$url" "$str" "$wait_time" "ws"
fi
ret=$?
if [ $ret -ne 0 ] ; then
for pod in $(sudo kubectl get pods | cut -d ' ' -f 1 | grep -v NAME) ; do
sudo kubectl logs $pod
done
cd "/tmp/k8s"
sudo kubectl delete -f bunkerweb.yml > /dev/null 2>&1
sudo kubectl delete -f rbac.yml > /dev/null 2>&1
sudo kubectl delete -f k8s.yml > /dev/null 2>&1
cd "/tmp/tests/$example"
for yml in $(ls *.yml) ; do
sudo kubectl delete -f "$yml"
done
echo "$example failed (curl) ..."
exit 1
fi
done
current_dir="$(pwd)"
cd "/tmp/tests/$example"
for yml in $(ls *.yml) ; do
sudo kubectl delete -f "$yml"
done
cd "$current_dir"
echo "$example success !"
}
echo "Running k8s tests ..."
# Start k8s
if [ ! -d "/tmp/k8s" ] ; then
mkdir /tmp/k8s
fi
rm -rf /tmp/k8s/*
cp -r ./integrations/kubernetes/* /tmp/k8s
cp ./tests/utils/k8s.yml /tmp/k8s
sed -i 's@bunkerity/bunkerweb:.*$@10.20.1.1:5000/bw-tests:latest@g' /tmp/k8s/bunkerweb.yml
sed -i 's@bunkerity/bunkerweb-autoconf:.*$@10.20.1.1:5000/bw-autoconf-tests:latest@g' /tmp/k8s/bunkerweb.yml
sed -i 's@ifNotPresent@Always@g' /tmp/k8s/bunkerweb.yml
current_dir="$(pwd)"
cd "/tmp/k8s"
# delete old objects
sudo kubectl delete -f bunkerweb.yml > /dev/null 2>&1
sudo kubectl delete -f rbac.yml > /dev/null 2>&1
sudo kubectl delete -f k8s.yml > /dev/null 2>&1
current_wait=0
while [ 1 ] ; do
if [ $current_wait -gt 30 ] ; then
echo "can't remove old k8s objects"
exit 1
fi
if [ "$(sudo kubectl get pods | grep "bunkerweb")" = "" ] ; then
break
fi
current_wait=$((current_wait+1))
sleep 1
done
# start the controller and instances
sudo kubectl apply -f k8s.yml
if [ $? -ne 0 ] ; then
echo "k8s failed (deploy k8s.yml)"
exit 1
fi
sudo kubectl apply -f rbac.yml
if [ $? -ne 0 ] ; then
sudo kubectl delete -f k8s.yml
echo "k8s failed (deploy rbac.yml)"
exit 1
fi
sudo kubectl apply -f bunkerweb.yml
if [ $? -ne 0 ] ; then
sudo kubectl delete -f rbac.yml
sudo kubectl delete -f k8s.yml
echo "k8s failed (deploy bunkerweb.yml)"
exit 1
fi
current_wait=0
healthy="no"
while [ $current_wait -lt 30 ] ; do
check="$(sudo kubectl get pods | grep bunkerweb | grep -v Running)"
if [ "$check" = "" ] ; then
healthy="yes"
break
fi
current_wait=$((current_wait+1))
sleep 1
done
if [ "$healthy" = "no" ] ; then
sudo kubectl get pods
sudo kubectl delete -f bunkerweb.yml > /dev/null 2>&1
sudo kubectl delete -f rbac.yml > /dev/null 2>&1
sudo kubectl delete -f k8s.yml > /dev/null 2>&1
echo "k8s failed (not healthy)"
exit 1
fi
cd "$current_dir"
sleep 60
# reverse
single_k8s_test "kubernetes-ingress" "120" "https://$TEST_DOMAIN1 hello" "https://$TEST_DOMAIN2 hello" "https://$TEST_DOMAIN3 hello"
# configs
single_k8s_test "kubernetes-configs" "120" "https://$TEST_DOMAIN1/app1 app1" "https://$TEST_DOMAIN2/app2 app2" "https://$TEST_DOMAIN3/app3 app3" "https://$TEST_DOMAIN1/hello hello" "https://$TEST_DOMAIN2/hello hello" "https://$TEST_DOMAIN3/hello hello"
# cleanup
current_dir="$(pwd)"
cd "/tmp/k8s"
sudo kubectl delete -f bunkerweb.yml > /dev/null 2>&1
sudo kubectl delete -f rbac.yml > /dev/null 2>&1
sudo kubectl delete -f k8s.yml > /dev/null 2>&1
cd "$current_dir"
exit 0

View File

@ -1,6 +1,19 @@
#!/bin/bash
. ./tests/utils/utils.sh
function do_and_check_cmd() {
if [ "$CHANGE_DIR" != "" ] ; then
cd "$CHANGE_DIR"
fi
output=$("$@" 2>&1)
ret="$?"
if [ $ret -ne 0 ] ; then
echo "❌ Error from command : $*"
echo "$output"
exit $ret
fi
#echo $output
return 0
}
function gen_package() {
mode="$1"

View File

@ -1,125 +0,0 @@
#!/bin/bash
. ./tests/utils/utils.sh
. /opt/.runner_env
function single_swarm_test() {
example="$1"
wait_time="$2"
shift
shift
asserts=("$@")
echo "Testing $example ..."
exec_swarm_example "$example"
if [ $? -ne 0 ] ; then
docker service logs bunkerweb_mybunker
docker service logs bunkerweb_myautoconf
docker stack rm bunkerweb > /dev/null 2>&1
for config in $(docker config ls --format "{{ .ID }}") ; do
docker config rm $config
done
echo "$example failed (exec) ..."
exit 1
fi
for assert in "${asserts[@]}" ; do
url="$(echo "$assert" | cut -d ' ' -f 1)"
str="$(echo "$assert" | cut -d ' ' -f 2)"
if [ "$(echo "$example" | grep websocket)" = "" ] ; then
curl_assert "$url" "$str" "$wait_time"
else
curl_assert "$url" "$str" "$wait_time" "ws"
fi
ret=$?
if [ $ret -ne 0 ] ; then
docker service logs bunkerweb_mybunker
docker service logs bunkerweb_myautoconf
for service in $(docker stack services --format "{{ .Name }}" "$example") ; do
docker service logs "$service"
done
docker config ls
docker stack rm bunkerweb > /dev/null 2>&1
docker stack rm "$example" > /dev/null 2>&1
docker network rm services_net autoconf_net > /dev/null 2>&1
for config in $(docker config ls --format "{{ .ID }}") ; do
docker config rm $config
done
echo "$example failed (curl) ..."
exit 1
fi
done
docker stack rm "$example"
for config in $(docker config ls --format "{{ .ID }}") ; do
docker config rm $config
done
echo "$example success !"
}
echo "Running swarm tests ..."
# Start swarm
if [ ! -d "/tmp/swarm" ] ; then
mkdir /tmp/swarm
fi
rm -rf /tmp/swarm/*
cp -r ./integrations/swarm/* /tmp/swarm
sed -i 's@bunkerity/bunkerweb:.*$@10.20.1.1:5000/bw-tests:latest@g' /tmp/swarm/stack.yml
sed -i 's@bunkerity/bunkerweb-autoconf:.*$@10.20.1.1:5000/bw-autoconf-tests:latest@g' /tmp/swarm/stack.yml
current_dir="$(pwd)"
cd "/tmp/swarm"
echo "starting swarm stack ..."
docker stack rm bunkerweb > /dev/null 2>&1
current_wait=0
while [ 1 ] ; do
if [ $current_wait -gt 30 ] ; then
echo "can't remove old swarm stack"
exit 1
fi
if [ "$(docker stack ls | grep bunkerweb)" = "" ] ; then
break
fi
current_wait=$((current_wait+1))
sleep 1
done
docker network rm services_net autoconf_net > /dev/null 2>&1
ret="$(docker stack deploy -c stack.yml bunkerweb 2>&1)"
if [ $? -ne 0 ] ; then
echo "$ret"
echo "swarm failed (deploy)"
exit 1
fi
current_wait=0
healthy="no"
while [ $current_wait -lt 30 ] ; do
check="$(docker stack ps --no-trunc --format "{{ .CurrentState }}" bunkerweb | grep -v "Running" 2>&1)"
if [ "$check" = "" ] ; then
healthy="yes"
break
fi
current_wait=$((current_wait+1))
sleep 1
done
if [ "$healthy" = "no" ] ; then
echo "$ret"
docker service logs bunkerweb_mybunker
docker service logs bunkerweb_myautoconf
docker stack rm bunkerweb > /dev/null 2>&1
echo "swarm failed (not healthy)"
exit 1
fi
cd "$current_dir"
sleep 60
# reverse
single_swarm_test "swarm-reverse-proxy" "120" "https://$TEST_DOMAIN1 hello" "https://$TEST_DOMAIN2 hello" "https://$TEST_DOMAIN3 hello"
# configs
single_swarm_test "swarm-configs" "120" "https://$TEST_DOMAIN1/app1 app1" "https://$TEST_DOMAIN2/app2 app2" "https://$TEST_DOMAIN3/app3 app3" "https://$TEST_DOMAIN1/hello hello" "https://$TEST_DOMAIN2/hello hello" "https://$TEST_DOMAIN3/hello hello"
# cleanup
current_dir="$(pwd)"
cd "/tmp/swarm"
docker stack rm bunkerweb > /dev/null 2>&1
cd "$current_dir"
exit 0

View File

@ -1,201 +0,0 @@
#!/bin/bash
function exec_docker_example() {
if [ -d "/tmp/tests/$1" ] ; then
sudo rm -rf "/tmp/tests/$1"
if [ $? -ne 0 ] ; then
return 1
fi
fi
if [ ! -d "/tmp/tests" ] ; then
mkdir /tmp/tests
if [ $? -ne 0 ] ; then
return 1
fi
fi
cp -r "examples/$1" "/tmp/tests"
if [ $? -ne 0 ] ; then
return 1
fi
current_dir="$(pwd)"
cd "/tmp/tests/$1"
sed -i 's@bunkerity/bunkerweb:.*$@10.20.1.1:5000/bw-tests:latest@g' docker-compose.yml
sed -i 's@\./bw\-data:/@/tmp/bw\-data:/@g' docker-compose.yml
sed -i 's@- bw_data:/@- /tmp/bw\-data:/@g' docker-compose.yml
find . -type f -exec sed -i "s@www.example.com@${TEST_DOMAIN1}@g" {} \;
find . -type f -exec sed -i "s@auth.example.com@${TEST_DOMAIN1}@g" {} \;
find . -type f -exec sed -i "s@app1.example.com@${TEST_DOMAIN1_1}@g" {} \;
find . -type f -exec sed -i "s@app2.example.com@${TEST_DOMAIN1_2}@g" {} \;
find . -type f -exec sed -i "s@app3.example.com@${TEST_DOMAIN1_3}@g" {} \;
find "/tmp/tests/$1" -name "www.example.com" -exec /usr/bin/rename "s/www.example.com/${TEST_DOMAIN1}/" {} \+
find "/tmp/tests/$1" -name "app1.example.com" -exec /usr/bin/rename "s/app1.example.com/${TEST_DOMAIN1_1}/" {} \+
find "/tmp/tests/$1" -name "app2.example.com" -exec /usr/bin/rename "s/app2.example.com/${TEST_DOMAIN1_2}/" {} \+
find "/tmp/tests/$1" -name "app3.example.com" -exec /usr/bin/rename "s/app3.example.com/${TEST_DOMAIN1_3}/" {} \+
if [ -f setup.sh ] ; then
sudo ./setup.sh
fi
for folder in $(echo "configs plugins www") ; do
sudo bash -c "find /tmp/bw-data/$folder -type f -exec rm -f {} \;"
done
if [ -d ./bw-data ] ; then
sudo bash -c "cp -a ./bw-data/* /tmp/bw-data"
fi
docker-compose pull > /dev/null 2>&1
ret=$(docker-compose up -d 2>&1)
if [ "$?" -ne 0 ] ; then
sudo docker-compose down -v > /dev/null 2>&1
cd "$current_dir"
sudo rm -rf "/tmp/tests/$1"
echo "$ret"
return 1
fi
cd "$current_dir"
}
function exec_swarm_example() {
if [ -d "/tmp/tests/$1" ] ; then
sudo rm -rf "/tmp/tests/$1"
if [ $? -ne 0 ] ; then
return 1
fi
fi
if [ ! -d "/tmp/tests" ] ; then
mkdir /tmp/tests
if [ $? -ne 0 ] ; then
return 1
fi
fi
cp -r "examples/$1" "/tmp/tests"
if [ $? -ne 0 ] ; then
return 1
fi
current_dir="$(pwd)"
cd "/tmp/tests/$1"
sed -i "s@www.example.com@${TEST_DOMAIN1}@g" stack.yml
sed -i "s@app1.example.com@${TEST_DOMAIN1}@g" stack.yml
sed -i "s@app2.example.com@${TEST_DOMAIN2}@g" stack.yml
sed -i "s@app3.example.com@${TEST_DOMAIN3}@g" stack.yml
sed -i "s@www.example.com@${TEST_DOMAIN1}@g" setup.sh
sed -i "s@app1.example.com@${TEST_DOMAIN1}@g" setup.sh
sed -i "s@app2.example.com@${TEST_DOMAIN2}@g" setup.sh
sed -i "s@app3.example.com@${TEST_DOMAIN3}@g" setup.sh
find "/tmp/tests/$1" -name "www.example.com" -exec /usr/bin/rename "s/www.example.com/${TEST_DOMAIN1}/" {} \+
find "/tmp/tests/$1" -name "app1.example.com" -exec /usr/bin/rename "s/app1.example.com/${TEST_DOMAIN1}/" {} \+
find "/tmp/tests/$1" -name "app2.example.com" -exec /usr/bin/rename "s/app2.example.com/${TEST_DOMAIN2}/" {} \+
find "/tmp/tests/$1" -name "app3.example.com" -exec /usr/bin/rename "s/app3.example.com/${TEST_DOMAIN3}/" {} \+
if [ -f setup.sh ] ; then
sudo ./setup.sh
fi
docker stack rm "$1" > /dev/null 2>&1
docker stack deploy -c stack.yml "$1"
if [ "$?" -ne 0 ] ; then
cd "$current_dir"
sudo rm -rf "/tmp/tests/$1"
return 1
fi
cd "$current_dir"
}
function exec_k8s_example() {
if [ -d "/tmp/tests/$1" ] ; then
sudo rm -rf "/tmp/tests/$1"
if [ $? -ne 0 ] ; then
return 1
fi
fi
if [ ! -d "/tmp/tests" ] ; then
mkdir /tmp/tests
if [ $? -ne 0 ] ; then
return 1
fi
fi
cp -r "examples/$1" "/tmp/tests"
if [ $? -ne 0 ] ; then
return 1
fi
current_dir="$(pwd)"
cd "/tmp/tests/$1"
sed -i "s@www.example.com@${TEST_DOMAIN1}@g" *.yml
sed -i "s@app1.example.com@${TEST_DOMAIN1}@g" *.yml
sed -i "s@app2.example.com@${TEST_DOMAIN2}@g" *.yml
sed -i "s@app3.example.com@${TEST_DOMAIN3}@g" *.yml
find "/tmp/tests/$1" -name "www.example.com" -exec /usr/bin/rename "s/www.example.com/${TEST_DOMAIN1}/" {} \+
find "/tmp/tests/$1" -name "app1.example.com" -exec /usr/bin/rename "s/app1.example.com/${TEST_DOMAIN1}/" {} \+
find "/tmp/tests/$1" -name "app2.example.com" -exec /usr/bin/rename "s/app2.example.com/${TEST_DOMAIN2}/" {} \+
find "/tmp/tests/$1" -name "app3.example.com" -exec /usr/bin/rename "s/app3.example.com/${TEST_DOMAIN3}/" {} \+
if [ -f setup.sh ] ; then
sudo ./setup.sh
fi
for yml in $(ls *.yml) ; do
if [ "$yml" != "ingress.yml" ] ; then
sudo kubectl delete -f "$yml" > /dev/null 2> /dev/null
sudo kubectl apply -f "$yml"
if [ $? -ne 0 ] ; then
cd "$current_dir"
sudo kubectl delete -f "/tmp/tests/$1" > /dev/null 2>&1
rm -rf "/tmp/tests/$1"
return 1
fi
fi
done
sudo kubectl delete -f "ingress.yml" > /dev/null 2> /dev/null
sudo kubectl apply -f "ingress.yml"
if [ "$?" -ne 0 ] ; then
cd "$current_dir"
sudo kubectl delete -f "/tmp/tests/$1" > /dev/null 2>&1
rm -rf "/tmp/tests/$1"
return 1
fi
cd "$current_dir"
}
function curl_assert() {
url="$1"
str="$2"
max_wait=$3
ws="$4"
if [ "$ws" != "" ] ; then
cp ./tests/utils/websocat_amd64-linux /tmp/
chmod +x /tmp/websocat_amd64-linux
fi
current_wait=0
while [ $current_wait -le $max_wait ] ; do
if [ "$ws" = "" ] ; then
data="$(curl -k -L -s --cookie /dev/null -H "User-Agent: LegitOne" "$url" | grep -i "$str")"
else
data="$(echo "test" | /tmp/websocat_amd64-linux - --text "$url" | grep -i "$str")"
fi
if [ "$data" != "" ] && [ $? -eq 0 ] ; then
return 0
fi
current_wait=$((current_wait+1))
sleep 1
done
return 1
}
function rm_example() {
if [ ! -d "/tmp/tests/$1" ] ; then
return 1
fi
current_dir="$(pwd)"
cd "/tmp/tests/$1"
sudo docker-compose down -v > /dev/null 2>&1
cd "$current_dir"
sudo rm -rf "/tmp/tests/$1"
}
function do_and_check_cmd() {
if [ "$CHANGE_DIR" != "" ] ; then
cd "$CHANGE_DIR"
fi
output=$("$@" 2>&1)
ret="$?"
if [ $ret -ne 0 ] ; then
echo "❌ Error from command : $*"
echo "$output"
exit $ret
fi
#echo $output
return 0
}