diff --git a/examples/drupal/cleanup-kubernetes.sh b/examples/drupal/cleanup-kubernetes.sh new file mode 100755 index 000000000..eef800d92 --- /dev/null +++ b/examples/drupal/cleanup-kubernetes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $(id -u) -ne 0 ] ; then + echo "❌ Run me as root" + exit 1 +fi + +helm delete drupal \ No newline at end of file diff --git a/examples/drupal/drupal-chart-values.yml b/examples/drupal/drupal-chart-values.yml new file mode 100644 index 000000000..13bab1258 --- /dev/null +++ b/examples/drupal/drupal-chart-values.yml @@ -0,0 +1,3 @@ +drupalUsername: "user" +drupalPassword: "changeme42" +drupalEmail: "contact@example.com" diff --git a/examples/drupal/kubernetes.yml b/examples/drupal/kubernetes.yml index 2d2c17474..950145409 100644 --- a/examples/drupal/kubernetes.yml +++ b/examples/drupal/kubernetes.yml @@ -15,96 +15,6 @@ spec: pathType: Prefix backend: service: - name: svc-drupal + name: 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 \ No newline at end of file + number: 80 \ No newline at end of file diff --git a/examples/drupal/setup-kubernetes.sh b/examples/drupal/setup-kubernetes.sh new file mode 100755 index 000000000..22c9dd441 --- /dev/null +++ b/examples/drupal/setup-kubernetes.sh @@ -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 drupal-chart-values.yml drupal bitnami/drupal \ No newline at end of file diff --git a/examples/ghost/cleanup-kubernetes.sh b/examples/ghost/cleanup-kubernetes.sh new file mode 100755 index 000000000..df6542c76 --- /dev/null +++ b/examples/ghost/cleanup-kubernetes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $(id -u) -ne 0 ] ; then + echo "❌ Run me as root" + exit 1 +fi + +helm delete ghost \ No newline at end of file diff --git a/examples/ghost/ghost-chart-values.yml b/examples/ghost/ghost-chart-values.yml new file mode 100644 index 000000000..bb60a06ae --- /dev/null +++ b/examples/ghost/ghost-chart-values.yml @@ -0,0 +1,4 @@ +ghostUsername: "user" +ghostPassword: "changeme42" +ghostHost: "www.example.com" +ghostEnableHttps: true \ No newline at end of file diff --git a/examples/ghost/kubernetes.yml b/examples/ghost/kubernetes.yml index b07a5535e..d0fa772e1 100644 --- a/examples/ghost/kubernetes.yml +++ b/examples/ghost/kubernetes.yml @@ -4,7 +4,6 @@ metadata: name: ingress annotations: bunkerweb.io/AUTO_LETS_ENCRYPT: "yes" - bunkerweb.io/USE_GZIP: "yes" spec: rules: - host: www.example.com @@ -14,41 +13,6 @@ spec: pathType: Prefix backend: service: - name: svc-ghost + name: ghost port: - number: 2368 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ghost - labels: - app: ghost -spec: - replicas: 1 - selector: - matchLabels: - app: ghost - template: - metadata: - labels: - app: ghost - spec: - containers: - - name: ghost - image: ghost:alpine - env: - - name: URL - value: "https://www.example.com" ---- -apiVersion: v1 -kind: Service -metadata: - name: svc-ghost -spec: - selector: - app: ghost - ports: - - protocol: TCP - port: 2368 - targetPort: 2368 \ No newline at end of file + number: 80 \ No newline at end of file diff --git a/examples/ghost/setup-kubernetes.sh b/examples/ghost/setup-kubernetes.sh new file mode 100755 index 000000000..16817b845 --- /dev/null +++ b/examples/ghost/setup-kubernetes.sh @@ -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 ghost-chart-values.yml ghost bitnami/ghost \ No newline at end of file diff --git a/examples/gogs/swarm.yml b/examples/gogs/swarm.yml index 7fc3aa635..249f929f0 100644 --- a/examples/gogs/swarm.yml +++ b/examples/gogs/swarm.yml @@ -30,6 +30,9 @@ networks: external: name: bw-services +volumes: + gogs_data: + configs: config_gogs_app: file: ./gogs-data/gogs/conf/app.ini \ No newline at end of file diff --git a/examples/joomla/cleanup-kubernetes.sh b/examples/joomla/cleanup-kubernetes.sh new file mode 100755 index 000000000..467cbccd4 --- /dev/null +++ b/examples/joomla/cleanup-kubernetes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $(id -u) -ne 0 ] ; then + echo "❌ Run me as root" + exit 1 +fi + +helm delete joomla \ No newline at end of file diff --git a/examples/joomla/joomla-chart-values.yml b/examples/joomla/joomla-chart-values.yml new file mode 100644 index 000000000..5710e6491 --- /dev/null +++ b/examples/joomla/joomla-chart-values.yml @@ -0,0 +1,3 @@ +joomlaUsername: "user" +joomlaPassword: "changeme42" +joomlaEmail: "contact@example.com" \ No newline at end of file diff --git a/examples/joomla/kubernetes.yml b/examples/joomla/kubernetes.yml index 6c9e9ddc8..48c2bc3aa 100644 --- a/examples/joomla/kubernetes.yml +++ b/examples/joomla/kubernetes.yml @@ -17,88 +17,6 @@ spec: pathType: Prefix backend: service: - name: svc-joomla + name: joomla port: - number: 80 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: joomla - labels: - app: joomla -spec: - replicas: 1 - selector: - matchLabels: - app: joomla - template: - metadata: - labels: - app: joomla - spec: - containers: - - name: joomla - image: joomla:4-apache - env: - - name: JOOMLA_DB_HOST - value: "svc-db" - - name: JOOMLA_DB_NAME - value: "joomla_db" - - name: JOOMLA_DB_USER - value: "user" - - name: JOOMLA_DB_PASSWORD - value: "db-user-pwd" ---- -apiVersion: v1 -kind: Service -metadata: - name: svc-joomla -spec: - selector: - app: svc-joomla - 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-password" - - name: MYSQL_DATABASE - value: "joomla_db" - - 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 \ No newline at end of file + number: 80 \ No newline at end of file diff --git a/examples/joomla/setup-kubernetes.sh b/examples/joomla/setup-kubernetes.sh new file mode 100755 index 000000000..dff6ed86c --- /dev/null +++ b/examples/joomla/setup-kubernetes.sh @@ -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 joomla-chart-values.yml joomla bitnami/joomla \ No newline at end of file diff --git a/examples/magento/autoconf.yml b/examples/magento/autoconf.yml new file mode 100644 index 000000000..a7487c44a --- /dev/null +++ b/examples/magento/autoconf.yml @@ -0,0 +1,59 @@ +version: '3' + +services: + + mymagento: + image: bitnami/magento:2 + networks: + bw-services: + aliases: + - mymagento + volumes: + - ./magento-data:/bitnami/magento + environment: + - MAGENTO_USERNAME=admin # replace with admin username + - MAGENTO_PASSWORD=changeme42 # replace with a stronger password + - MAGENTO_EMAIL=contact@example.com # replace with admin email + - MAGENTO_HOST=www.example.com # replace with your domain + - MAGENTO_ENABLE_HTTPS=yes + - MAGENTO_ENABLE_ADMIN_HTTPS=yes + - MAGENTO_DATABASE_HOST=mydb + - MAGENTO_DATABASE_NAME=magentodb + - MAGENTO_DATABASE_USER=user + - 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 + + myelasticsearch: + image: bitnami/elasticsearch:7 + networks: + bw-services: + aliases: + - myelasticsearch + # ⚠️ you need to create the directory and fix permissions ⚠️ + # see setup-autoconf.sh + volumes: + - ./elasticsearch-data:/bitnami/elasticsearch/data + + mydb: + image: mariadb:10.2 + 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=magentodb + - MYSQL_USER=user + - MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match MAGENTO_DATABASE_PASSWORD) + +networks: + bw-services: + external: + name: bw-services \ No newline at end of file diff --git a/examples/magento/cleanup-kubernetes.sh b/examples/magento/cleanup-kubernetes.sh new file mode 100755 index 000000000..866926155 --- /dev/null +++ b/examples/magento/cleanup-kubernetes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $(id -u) -ne 0 ] ; then + echo "❌ Run me as root" + exit 1 +fi + +helm delete magento \ No newline at end of file diff --git a/examples/magento/docker-compose.yml b/examples/magento/docker-compose.yml index f9ac096c5..c11647b6f 100644 --- a/examples/magento/docker-compose.yml +++ b/examples/magento/docker-compose.yml @@ -46,7 +46,7 @@ services: myelasticsearch: image: bitnami/elasticsearch:7 # ⚠️ you need to create the directory and fix permissions ⚠️ - # see setup.sh + # see setup-docker.sh volumes: - ./elasticsearch-data:/bitnami/elasticsearch/data diff --git a/examples/magento/kubernetes.yml b/examples/magento/kubernetes.yml new file mode 100644 index 000000000..f388ab990 --- /dev/null +++ b/examples/magento/kubernetes.yml @@ -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: magento + port: + number: 8080 \ No newline at end of file diff --git a/examples/magento/magento-chart-values.yml b/examples/magento/magento-chart-values.yml new file mode 100644 index 000000000..4fc34677a --- /dev/null +++ b/examples/magento/magento-chart-values.yml @@ -0,0 +1,7 @@ +magentoHost: "https://www.example.com" +magentoUsername: "user" +magentoPassword: "changeme42" +magentoEmail: "contact@example.com" +magentoFirstName: "John" +magentoLastName: "Doe" +magentoAdminUri: "/admin" diff --git a/examples/magento/setup.sh b/examples/magento/setup-docker.sh similarity index 100% rename from examples/magento/setup.sh rename to examples/magento/setup-docker.sh diff --git a/examples/magento/setup-kubernetes.sh b/examples/magento/setup-kubernetes.sh new file mode 100755 index 000000000..047e69651 --- /dev/null +++ b/examples/magento/setup-kubernetes.sh @@ -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 magento-chart-values.yml magento bitnami/magento \ No newline at end of file diff --git a/examples/magento/swarm.yml b/examples/magento/swarm.yml new file mode 100644 index 000000000..91937a679 --- /dev/null +++ b/examples/magento/swarm.yml @@ -0,0 +1,69 @@ +version: '3' + +services: + + mymagento: + image: bitnami/magento:2 + networks: + - bw-services + volumes: + - magento_data:/bitnami/magento + environment: + - MAGENTO_USERNAME=admin # replace with admin username + - MAGENTO_PASSWORD=changeme42 # replace with a stronger password + - MAGENTO_EMAIL=contact@example.com # replace with admin email + - MAGENTO_HOST=www.example.com # replace with your domain + - MAGENTO_ENABLE_HTTPS=yes + - MAGENTO_ENABLE_ADMIN_HTTPS=yes + - MAGENTO_DATABASE_HOST=mydb + - MAGENTO_DATABASE_NAME=magentodb + - MAGENTO_DATABASE_USER=user + - MAGENTO_DATABASE_PASSWORD=db-user-pwd # replace with a stronger password (must match MYSQL_PASSWORD) + - ELASTICSEARCH_HOST=myelasticsearch + deploy: + placement: + constraints: + - "node.role==worker" + labels: + - SERVER_NAME=www.example.com + - USE_REVERSE_PROXY=yes + - REVERSE_PROXY_URL=/ + - REVERSE_PROXY_HOST=http://mymagento:8080 + + myelasticsearch: + image: bitnami/elasticsearch:7 + networks: + - bw-services + volumes: + - elasticsearch_data:/bitnami/elasticsearch/data + deploy: + placement: + constraints: + - "node.role==worker" + + mydb: + image: mariadb:10.2 + networks: + - bw-services + volumes: + - db_data:/var/lib/mysql + environment: + - MYSQL_ROOT_PASSWORD=db-root-pwd # replace with a stronger password + - MYSQL_DATABASE=magentodb + - MYSQL_USER=user + - MYSQL_PASSWORD=db-user-pwd # replace with a stronger password (must match MAGENTO_DATABASE_PASSWORD) + deploy: + placement: + constraints: + - "node.role==worker" + +networks: + bw-services: + external: + name: bw-services + +volumes: + db_data: + elasticsearch_data: + magento_data: + \ No newline at end of file diff --git a/examples/magento/tests.json b/examples/magento/tests.json new file mode 100644 index 000000000..b0ef522c1 --- /dev/null +++ b/examples/magento/tests.json @@ -0,0 +1,17 @@ +{ + "name": "load-balancer", + "kinds": [ + "docker", + "autoconf", + "swarm", + "kubernetes" + ], + "timeout": 180, + "tests": [ + { + "type": "string", + "url": "https://www.example.com", + "string": "hello" + } + ] +} \ No newline at end of file diff --git a/tests/KubernetesTest.py b/tests/KubernetesTest.py index 20ae91f5d..a52b52b91 100644 --- a/tests/KubernetesTest.py +++ b/tests/KubernetesTest.py @@ -109,7 +109,13 @@ class KubernetesTest(Test) : def _cleanup_test(self) : try : - proc = run("sudo kubectl delete -f kubernetes.yml", shell=True, cwd="/tmp/tests/" + self._name) + test = "/tmp/tests/" + self._name + cleanup = test + "/cleanup-kubernetes.sh" + if isfile(cleanup) : + proc = run("sudo ./cleanup-kubernetes.sh", cwd=test, shell=True) + if proc.returncode != 0 : + raise(Exception("cleanup-kubernetes failed")) + proc = run("sudo kubectl delete -f kubernetes.yml", shell=True, cwd=test) if proc.returncode != 0 : raise(Exception("kubectl delete failed")) super()._cleanup_test()