Merge branch 'dev' of https://github.com/bunkerity/bunkerweb into dev
This commit is contained in:
commit
72965e230e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -56,7 +56,7 @@ include /etc/nginx/init-lua.conf;
|
|||
include /etc/nginx/healthcheck.conf;
|
||||
|
||||
# default server
|
||||
{% if MULTISITE == "yes" or DISABLE_DEFAULT_SERVER == "yes" +%}
|
||||
{% if MULTISITE == "yes" or DISABLE_DEFAULT_SERVER == "yes" or TEMP_NGINX == "yes" +%}
|
||||
include /etc/nginx/default-server-http.conf;
|
||||
{% endif +%}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ def request(method, url, _id=None) :
|
|||
if _id is not None :
|
||||
data["id"] = _id
|
||||
try :
|
||||
resp = requests.request(method, getenv("BUNKERNET_SERVER") + url, json=data, headers=headers, timeout=5)
|
||||
resp = requests.request(method, getenv("BUNKERNET_SERVER", "https://api.bunkerweb.io") + url, json=data, headers=headers, timeout=5)
|
||||
status = resp.status_code
|
||||
if status == 429 :
|
||||
return True, 429, "rate limited"
|
||||
|
|
|
@ -12,6 +12,9 @@ mv /tmp/authelia.service /etc/systemd/system
|
|||
mkdir /etc/authelia
|
||||
cp ./authelia/* /etc/authelia
|
||||
sed -i "s@/config/@/etc/authelia/@g" /etc/authelia/configuration.yml
|
||||
sed -i "s@redis:@@g" /etc/authelia/configuration.yml
|
||||
sed -i "s@host: redis@@g" /etc/authelia/configuration.yml
|
||||
sed -i "s@port: 6379@@g" /etc/authelia/configuration.yml
|
||||
systemctl daemon-reload
|
||||
systemctl start authelia
|
||||
cp variables.env /opt/bunkerweb/variables.env
|
|
@ -2,7 +2,8 @@ HTTP_PORT=80
|
|||
HTTPS_PORT=443
|
||||
DNS_RESOLVERS=8.8.8.8 8.8.4.4
|
||||
MULTISITE=yes
|
||||
SERVER_NAME=auth.example.com app1.example.com app2.example.com # replace with your domains
|
||||
# Replace with your domains
|
||||
SERVER_NAME=auth.example.com app1.example.com app2.example.com
|
||||
SERVE_FILES=no
|
||||
DISABLE_DEFAULT_SERVER=yes
|
||||
AUTO_LETS_ENCRYPT=yes
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "autoconf-configs",
|
||||
"kinds": [
|
||||
"autoconf"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app1.example.com/hello",
|
||||
"string": "app1"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app2.example.com/hello",
|
||||
"string": "app2"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app3.example.com/hello",
|
||||
"string": "app3"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "autoconf-php",
|
||||
"kinds": [
|
||||
"autoconf"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app1.example.com",
|
||||
"string": "app1"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app2.example.com",
|
||||
"string": "app2"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app3.example.com",
|
||||
"string": "app3"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "autoconf-reverse-proxy",
|
||||
"kinds": [
|
||||
"autoconf"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app1.example.com",
|
||||
"string": "hello"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app2.example.com",
|
||||
"string": "hello"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app3.example.com",
|
||||
"string": "hello"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "behind-reverse-proxy",
|
||||
"kinds": [
|
||||
"docker"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "http://www.example.com",
|
||||
"string": "hello"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ $(id -u) -ne 0 ] ; then
|
||||
echo "❌ Run me as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chown -R root:101 bw-data
|
||||
chmod -R 770 bw-data
|
||||
chown -R 33:101 ./bw-data/www
|
||||
find ./bw-data/www -type f -exec chmod 0640 {} \;
|
||||
find ./bw-data/www -type d -exec chmod 0750 {} \;
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ $(id -u) -ne 0 ] ; then
|
||||
echo "❌ Run me as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chown -R www-data:nginx ./bw-data/www
|
||||
find ./bw-data/www -type f -exec chmod 0640 {} \;
|
||||
find ./bw-data/www -type d -exec chmod 0750 {} \;
|
||||
cp -rp ./bw-data/www/* /opt/bunkerweb/www
|
||||
cp variables.env /opt/bunkerweb/variables.env
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "cors",
|
||||
"kinds": [
|
||||
"docker",
|
||||
"autoconf",
|
||||
"linux"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app1.example.com",
|
||||
"string": "app1"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app2.example.com",
|
||||
"string": "app2"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://app3.example.com",
|
||||
"string": "app3"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
HTTP_PORT=80
|
||||
HTTPS_PORT=443
|
||||
DNS_RESOLVERS=8.8.8.8 8.8.4.4
|
||||
MULTISITE=yes
|
||||
# Replace with your domains
|
||||
SERVER_NAME=app1.example.com app2.example.com app3.example.com
|
||||
AUTO_LETS_ENCRYPT=yes
|
||||
DISABLE_DEFAULT_SERVER=yes
|
||||
USE_CLIENT_CACHE=yes
|
||||
USE_GZIP=yes
|
||||
app1.example.com_USE_CORS=yes
|
||||
app1.example.com_CORS_ALLOW_ORIGIN=https://app2.example.com
|
||||
app1.example.com_ALLOWED_METHODS=GET|POST|HEAD|OPTIONS
|
||||
app1.example.com_REMOTE_PHP=myapp1
|
||||
app1.example.com_REMOTE_PHP_PATH=/app
|
||||
app2.example.com_REMOTE_PHP=myapp2
|
||||
app2.example.com_REMOTE_PHP_PATH=/app
|
||||
app3.example.com_REMOTE_PHP=myapp3
|
||||
app3.example.com_REMOTE_PHP_PATH=/app
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
cp variables.env /opt/bunkerweb/variables.env
|
|
@ -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
|
|
@ -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:
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "drupal",
|
||||
"kinds": [
|
||||
"docker",
|
||||
"autoconf",
|
||||
"swarm",
|
||||
"kubernetes",
|
||||
"linux"
|
||||
],
|
||||
"timeout": 60,
|
||||
"tests": [
|
||||
{
|
||||
"type": "string",
|
||||
"url": "https://www.example.com",
|
||||
"string": "drupal"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
HTTP_PORT=80
|
||||
HTTPS_PORT=443
|
||||
DNS_RESOLVERS=8.8.8.8 8.8.4.4
|
||||
# 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
|
|
@ -93,7 +93,7 @@ function start() {
|
|||
# STEP4 #
|
||||
# Run jobs script #
|
||||
#############################################
|
||||
/opt/bunkerweb/job/main.py --variables /etc/nginx/variables.env --run
|
||||
/opt/bunkerweb/job/main.py --variables /opt/bunkerweb/variables.env --run
|
||||
# Test if command worked
|
||||
check_ok
|
||||
# Exit if failed
|
||||
|
|
|
@ -76,7 +76,7 @@ class AutoconfTest(Test) :
|
|||
super()._setup_test()
|
||||
test = "/tmp/tests/" + self._name
|
||||
compose = "/tmp/tests/" + self._name + "/autoconf.yml"
|
||||
example_data = "./examples/" + self._name + "/bw-data"
|
||||
example_data = "/tmp/tests/" + self._name + "/bw-data"
|
||||
Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$", "10.20.1.1:5000/bw-tests:latest")
|
||||
Test.replace_in_file(compose, r"\./bw\-data:/", "/tmp/bw-data:/")
|
||||
Test.replace_in_file(compose, r"\- bw_data:/", "- /tmp/bw-data:/")
|
||||
|
@ -92,6 +92,8 @@ class AutoconfTest(Test) :
|
|||
if isdir(example_data) :
|
||||
for cp_dir in listdir(example_data) :
|
||||
if isdir(join(example_data, cp_dir)) :
|
||||
if isdir(join("/tmp/bw-data", cp_dir)) :
|
||||
run("sudo rm -rf " + join("/tmp/bw-data", cp_dir), shell=True)
|
||||
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
proc = run("docker-compose -f autoconf.yml pull", shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
|
|
|
@ -51,6 +51,8 @@ class DockerTest(Test) :
|
|||
if isdir(example_data) :
|
||||
for cp_dir in listdir(example_data) :
|
||||
if isdir(join(example_data, cp_dir)) :
|
||||
if isdir(join("/tmp/bw-data", cp_dir)) :
|
||||
run("sudo rm -rf " + join("/tmp/bw-data", cp_dir), shell=True)
|
||||
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
proc = run("docker-compose pull", shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 && \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 && \
|
||||
|
|
|
@ -94,10 +94,10 @@ class KubernetesTest(Test) :
|
|||
proc = run("sudo ./setup-kubernetes.sh", cwd=test, shell=True)
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("setup-kubernetes failed"))
|
||||
if isdir(example_data) :
|
||||
for cp_dir in listdir(example_data) :
|
||||
if isdir(join(example_data, cp_dir)) :
|
||||
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
# if isdir(example_data) :
|
||||
# for cp_dir in listdir(example_data) :
|
||||
# if isdir(join(example_data, cp_dir)) :
|
||||
# copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
proc = run("sudo kubectl apply -f kubernetes.yml", shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("kubectl apply failed"))
|
||||
|
|
|
@ -88,10 +88,10 @@ class LinuxTest(Test) :
|
|||
Test.replace_in_files(test, "example.com", getenv("ROOT_DOMAIN"))
|
||||
setup = test + "/setup-linux.sh"
|
||||
if isfile(setup) :
|
||||
proc = LinuxTest.docker_cp(self.__distro, test, "/opt/tests")
|
||||
proc = LinuxTest.docker_cp(self.__distro, test, "/opt/" + self._name)
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("docker cp failed (linux stack)"))
|
||||
proc = LinuxTest.docker_exec(self.__distro, "cd /opt/tests/ && ./setup-linux.sh")
|
||||
proc = LinuxTest.docker_exec(self.__distro, "cd /opt/" + self._name + " && ./setup-linux.sh")
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("docker exec setup failed (linux stack)"))
|
||||
proc = LinuxTest.docker_exec(self.__distro, "systemctl restart bunkerweb")
|
||||
|
@ -118,4 +118,4 @@ class LinuxTest(Test) :
|
|||
return run("docker exec linux-" + distro + " /bin/bash -c \"" + cmd_linux + "\"", shell=True)
|
||||
|
||||
def docker_cp(distro, src, dst) :
|
||||
return run("docker cp " + src + " linux-" + distro + ":" + dst, shell=True)
|
||||
return run("sudo docker cp " + src + " linux-" + distro + ":" + dst, shell=True)
|
54
tests/README
54
tests/README
|
@ -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
|
||||
#______________________________________________________________________________________________________________________#
|
|
@ -82,10 +82,12 @@ class SwarmTest(Test) :
|
|||
proc = run("sudo ./setup-swarm.sh", cwd=test, shell=True)
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("setup-swarm failed"))
|
||||
if isdir(example_data) :
|
||||
for cp_dir in listdir(example_data) :
|
||||
if isdir(join(example_data, cp_dir)) :
|
||||
copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
# if isdir(example_data) :
|
||||
# for cp_dir in listdir(example_data) :
|
||||
# if isdir(join(example_data, cp_dir)) :
|
||||
# if isdir(join("/tmp/bw-data", cp_dir)) :
|
||||
# run("sudo rm -rf " + join("/tmp/bw-data", cp_dir), shell=True)
|
||||
# copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
|
||||
proc = run('docker stack deploy -c swarm.yml "' + self._name + '"', shell=True, cwd=test)
|
||||
if proc.returncode != 0 :
|
||||
raise(Exception("docker stack deploy failed"))
|
||||
|
|
|
@ -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
|
130
tests/docker.sh
130
tests/docker.sh
|
@ -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
|
|
@ -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
|
|
@ -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"
|
||||
|
|
125
tests/swarm.sh
125
tests/swarm.sh
|
@ -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
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue