tests - refactoring on the road, still needs some work

This commit is contained in:
florian 2022-07-24 18:23:20 +02:00
parent 8fb03a3171
commit 87c57c67c7
40 changed files with 727 additions and 134 deletions

View File

@ -74,7 +74,8 @@ class Config(ApiCaller, ConfigCaller) :
server_names = []
for service in self.__services :
first_server = service["SERVER_NAME"].split(" ")[0]
server_names.append(first_server)
if not first_server in server_names :
server_names.append(first_server)
for variable, value in service.items() :
config[first_server + "_" + variable] = value
config["SERVER_NAME"] = " ".join(server_names)

View File

@ -23,10 +23,10 @@ services:
- MAGENTO_DATABASE_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD)
- ELASTICSEARCH_HOST=myelasticsearch
labels:
- SERVER_NAME=www.example.com
- USE_REVERSE_PROXY=yes
- REVERSE_PROXY_URL=/
- REVERSE_PROXY_HOST=http://mymagento:8080
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mymagento:8080
myelasticsearch:
image: bitnami/elasticsearch:7
@ -56,4 +56,4 @@ services:
networks:
bw-services:
external:
name: bw-services
name: bw-services

View File

@ -0,0 +1,42 @@
version: '3'
services:
myredmine:
image: redmine
restart: always
volumes:
- ./redmine-data:/usr/src/redmine/files
networks:
bw-services:
aliases:
- myredmine
environment:
- REDMINE_DB_MYSQL=mydb
- REDMINE_DB_DATABASE=redminedb
- REDMINE_DB_USERNAME=user
- REDMINE_DB_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD)
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://myredmine:3000
mydb:
image: mysql
volumes:
- ./db-data:/var/lib/mysql
networks:
bw-services:
aliases:
- mydb
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=redminedb
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match REDMINE_DB_PASSWORD)
networks:
bw-services:
external:
name: bw-services

View File

@ -5,5 +5,4 @@ if [ $(id -u) -ne 0 ] ; then
exit 1
fi
chown -R root:101 bw-data
chmod -R 770 bw-data
helm delete redmine

View File

@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
bunkerweb.io/AUTO_LETS_ENCRYPT: "yes"
spec:
rules:
- host: www.example.com
http:
paths:
path: /
pathType: Prefix
backend:
service:
name: redmine
port:
number: 80

View File

@ -0,0 +1,4 @@
redmineUsername: "user"
redminePassword: "changeme42"
redmineEmail: "user@example.com"
redmineLanguage: "en"

View File

@ -0,0 +1,9 @@
#!/bin/bash
if [ $(id -u) -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install -f redmine-chart-values.yml redmine bitnami/redmine

View File

@ -0,0 +1,50 @@
version: '3'
services:
myredmine:
image: redmine
restart: always
volumes:
- redmine_data:/usr/src/redmine/files
networks:
- bw-services
environment:
- REDMINE_DB_MYSQL=mydb
- REDMINE_DB_DATABASE=redminedb
- REDMINE_DB_USERNAME=user
- REDMINE_DB_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD)
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://myredmine:3000
mydb:
image: mysql
volumes:
- db_data:/var/lib/mysql
networks:
- bw-services
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=redminedb
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match REDMINE_DB_PASSWORD)
deploy:
placement:
constraints:
- "node.role==worker"
networks:
bw-services:
external:
name: bw-services
volumes:
redmine_data:
db_data:

View File

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

View File

@ -0,0 +1,32 @@
version: '3'
services:
app1:
image: tutum/hello-world
networks:
bw-services:
aliases:
- app1
labels:
- bunkerweb.SERVER_NAME=app1.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://app1
app2:
image: tutum/hello-world
networks:
bw-services:
aliases:
- app2
labels:
- bunkerweb.SERVER_NAME=app2.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://app2
networks:
bw-services:
external:
name: bw-services

View File

@ -33,13 +33,7 @@ services:
- net_app2
app1:
image: node
working_dir: /home/node/app
volumes:
- ./js-app:/home/node/app
environment:
- NODE_ENV=production
command: bash -c "npm install express && node index.js"
image: tutum/hello-world
networks:
- net_app1

View File

@ -1,13 +0,0 @@
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World from app1!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})

View File

@ -1,15 +0,0 @@
{
"name": "js-app",
"version": "1.0.0",
"description": "demo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}

View File

@ -0,0 +1,92 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
bunkerweb.io/AUTO_LETS_ENCRYPT: "yes"
spec:
rules:
- host: app1.example.com
http:
paths:
path: /
pathType: Prefix
backend:
service:
name: svc-app1
port:
number: 80
- host: app2.example.com
http:
paths:
path: /
pathType: Prefix
backend:
service:
name: svc-app2
port:
number: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1
labels:
app: app1
spec:
replicas: 1
selector:
matchLabels:
app: app1
template:
metadata:
labels:
app: app1
spec:
containers:
- name: app1
image: tutum/hello-world
---
apiVersion: v1
kind: Service
metadata:
name: svc-app1
spec:
selector:
app: app1
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app2
labels:
app: app2
spec:
replicas: 1
selector:
matchLabels:
app: app2
template:
metadata:
labels:
app: app2
spec:
containers:
- name: app2
image: tutum/hello-world
---
apiVersion: v1
kind: Service
metadata:
name: svc-app2
spec:
selector:
app: app2
ports:
- protocol: TCP
port: 80
targetPort: 80

View File

@ -0,0 +1,36 @@
version: '3'
services:
app1:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=app1.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://app1
app2:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=app2.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://app2
networks:
bw-services:
external:
name: bw-services

View File

@ -0,0 +1,22 @@
{
"name": "reverse-proxy-multisite",
"kinds": [
"docker",
"autoconf",
"swarm",
"kubernetes"
],
"timeout": 60,
"tests": [
{
"type": "string",
"url": "https://app1.example.com",
"string": "hello"
},
{
"type": "string",
"url": "https://app2.example.com",
"string": "hello"
},
]
}

View File

@ -0,0 +1,32 @@
version: '3'
services:
app1:
image: tutum/hello-world
networks:
bw-services:
aliases:
- app1
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL_1=~ ^/app1/(.+)$$
- bunkerweb.REVERSE_PROXY_HOST_1=http://app1/$$1
app2:
image: tutum/hello-world
networks:
bw-services:
aliases:
- app2
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL_2=~ ^/app2/(.+)$$
- bunkerweb.REVERSE_PROXY_HOST_2=http://app2/$$1
networks:
bw-services:
external:
name: bw-services

View File

@ -23,19 +23,13 @@ services:
- USE_CLIENT_CACHE=yes
- USE_GZIP=yes
- USE_REVERSE_PROXY=yes
- REVERSE_PROXY_URL_1=/app1/
- REVERSE_PROXY_HOST_1=http://app1:3000/
- REVERSE_PROXY_URL_2=/app2/
- REVERSE_PROXY_HOST_2=http://app2/
- REVERSE_PROXY_URL_1=~ ^/app1/(.+)$$
- REVERSE_PROXY_HOST_1=http://app1/$$1
- REVERSE_PROXY_URL_2=~ ^/app2/(.+)$$
- REVERSE_PROXY_HOST_2=http://app2/$$1
app1:
image: node
working_dir: /home/node/app
volumes:
- ./js-app:/home/node/app
environment:
- NODE_ENV=production
command: bash -c "npm install express && node index.js"
image: tutum/hello-world
app2:
image: tutum/hello-world

View File

@ -1,13 +0,0 @@
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello from app1 !')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})

View File

@ -1,15 +0,0 @@
{
"name": "js-app",
"version": "1.0.0",
"description": "demo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}

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_reverse_server_http
# create configs
docker config create -l bunkerweb.CONFIG_TYPE=server-http cfg_reverse_server_http -l bunkerweb.CONFIG_SITE=www.example.com ./bw-data/configs/server-http/redirects.conf

View File

@ -0,0 +1,36 @@
version: '3'
services:
app1:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL_1=~ ^/app1/(.+)$$
- bunkerweb.REVERSE_PROXY_HOST_1=http://app1/$$1
app2:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL_2=~ ^/app2/(.+)$$
- bunkerweb.REVERSE_PROXY_HOST_2=http://app2/$$1
networks:
bw-services:
external:
name: bw-services

View File

@ -0,0 +1,21 @@
{
"name": "reverse-proxy-singlesite",
"kinds": [
"docker",
"autoconf",
"swarm"
],
"timeout": 60,
"tests": [
{
"type": "string",
"url": "https://www.example.com/app1",
"string": "hello"
},
{
"type": "string",
"url": "https://www.example.com/app2",
"string": "hello"
},
]
}

View File

@ -0,0 +1,19 @@
{
"name": "reverse-proxy-websocket",
"kinds": [
"docker"
],
"timeout": 60,
"tests": [
{
"type": "string-ws",
"url": "https://www.example.com/app1",
"string": "hello"
},
{
"type": "string",
"url": "https://www.example.com/app2",
"string": "hello"
},
]
}

View File

@ -0,0 +1,39 @@
{
"name": "swarm-configs",
"kinds": [
"swarm"
],
"timeout": 120,
"tests": [
{
"type": "string",
"url": "https://app1.example.com/app1",
"string": "app1"
},
{
"type": "string",
"url": "https://app2.example.com/app2",
"string": "app2"
},
{
"type": "string",
"url": "https://app3.example.com/app3",
"string": "app3"
},
{
"type": "string",
"url": "https://app1.example.com/hello",
"string": "hello"
},
{
"type": "string",
"url": "https://app2.example.com/hello",
"string": "hello"
},
{
"type": "string",
"url": "https://app3.example.com/hello",
"string": "hello"
}
]
}

View File

@ -1,50 +0,0 @@
version: "3"
services:
myapp1:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- "bunkerweb.SERVER_NAME=app1.example.com"
- "bunkerweb.USE_REVERSE_PROXY=yes"
- "bunkerweb.REVERSE_PROXY_URL=/"
- "bunkerweb.REVERSE_PROXY_HOST=http://myapp1"
myapp2:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- "bunkerweb.SERVER_NAME=app2.example.com"
- "bunkerweb.USE_REVERSE_PROXY=yes"
- "bunkerweb.REVERSE_PROXY_URL=/"
- "bunkerweb.REVERSE_PROXY_HOST=http://myapp2"
myapp3:
image: tutum/hello-world
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- "bunkerweb.SERVER_NAME=app3.example.com"
- "bunkerweb.USE_REVERSE_PROXY=yes"
- "bunkerweb.REVERSE_PROXY_URL=/"
- "bunkerweb.REVERSE_PROXY_HOST=http://myapp3"
networks:
bw-services:
external:
name: bw-services

View File

@ -0,0 +1,22 @@
version: '3'
services:
mytomcat:
image: tomcat
volumes:
- ./app:/usr/local/tomcat/webapps/ # folder containing war files
networks:
bw-services:
aliases:
- mytomcat
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mytomcat:8080/sample/
networks:
bw-services:
external:
name: bw-services

32
examples/tomcat/swarm.yml Normal file
View File

@ -0,0 +1,32 @@
version: '3.3'
services:
mytomcat:
image: tomcat
configs:
- source: tomcat_app_war
target: /usr/local/tomcat/webapps/sample.war
uid: "0"
gid: "0"
mode: 0444
networks:
- bw-services
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mytomcat:8080/sample/
networks:
bw-services:
external:
name: bw-services
configs:
tomcat_app_war:
file: ./app/sample.war

View File

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

View File

@ -0,0 +1,43 @@
version: '3'
services:
mywp:
image: wordpress:5-apache
volumes:
- ./wp-data:/var/www/html
networks:
bw-services:
aliases:
- mywp
environment:
- WORDPRESS_DB_HOST=mydb
- WORDPRESS_DB_NAME=wp
- WORDPRESS_DB_USER=user
- WORDPRESS_DB_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD)
- WORDPRESS_TABLE_PREFIX=prefix_ # best practice : replace with a random prefix
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.MAX_CLIENT_SIZE=50m
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mywp
mydb:
image: mariadb
volumes:
- ./db-data:/var/lib/mysql
networks:
bw-services:
aliases:
- mydb
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=wp
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match WORDPRESS_DB_PASSWORD)
networks:
bw-services:
external:
name: bw-services

View File

@ -5,5 +5,4 @@ if [ $(id -u) -ne 0 ] ; then
exit 1
fi
chown -R root:101 bw-data
chmod -R 770 bw-data
helm delete wordpress

View File

@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
bunkerweb.io/AUTO_LETS_ENCRYPT: "yes"
bunkerweb.io/www.example.com_MAX_CLIENT_SIZE: "50m"
spec:
rules:
- host: www.example.com
http:
paths:
path: /
pathType: Prefix
backend:
service:
name: wordpress
port:
number: 80

View File

@ -0,0 +1,9 @@
#!/bin/bash
if [ $(id -u) -ne 0 ] ; then
echo "❌ Run me as root"
exit 1
fi
helm repo add wordpress https://charts.bitnami.com/bitnami
helm install -f wordpress-chart-values.yml wordpress bitnami/wordpress

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_wordpress_modsec_crs
# create configs
docker config create -l bunkerweb.CONFIG_TYPE=modsec-crs cfg_wordpress_modsec_crs -l bunkerweb.CONFIG_SITE=www.example.com ./bw-data/configs/modsec-crs/wordpress.conf

View File

@ -0,0 +1,51 @@
version: '3'
services:
mywp:
image: wordpress:5-apache
volumes:
- wp_data:/var/www/html
networks:
- bw-services
environment:
- WORDPRESS_DB_HOST=mydb
- WORDPRESS_DB_NAME=wp
- WORDPRESS_DB_USER=user
- WORDPRESS_DB_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD)
- WORDPRESS_TABLE_PREFIX=prefix_ # best practice : replace with a random prefix
deploy:
placement:
constraints:
- "node.role==worker"
labels:
- bunkerweb.SERVER_NAME=www.example.com
- bunkerweb.MAX_CLIENT_SIZE=50m
- bunkerweb.USE_REVERSE_PROXY=yes
- bunkerweb.REVERSE_PROXY_URL=/
- bunkerweb.REVERSE_PROXY_HOST=http://mywp
mydb:
image: mariadb
volumes:
- db_data:/var/lib/mysql
networks:
- bw-services
environment:
- MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password
- MYSQL_DATABASE=wp
- MYSQL_USER=user
- MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match WORDPRESS_DB_PASSWORD)
deploy:
placement:
constraints:
- "node.role==worker"
networks:
bw-services:
external:
name: bw-services
volumes:
wp_data:
db_data:

View File

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

View File

@ -0,0 +1,8 @@
wordpressUsername: "user"
wordpressPassword: "changeme42"
wordpressEmail: "user@example.com"
wordpressFirstName: "FirstName"
wordpressLastName: "LastName"
wordpressBlogName: "User's Blog!"
wordpressTablePrefix: "changeme_"
wordpressScheme: "https"