def init():
     try:
         if not Test.init():
             return False
         proc = run("sudo chown -R 101:101 /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (autoconf stack)"))
     except:
         log("DOCKER", "❌",
             "exception while running DockerTest.init()\n" + format_exc())
         return False
     return True
Exemple #2
0
 def init():
     try:
         if not Test.init():
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (autoconf stack)"))
         if isdir("/tmp/autoconf"):
             rmtree("/tmp/autoconf")
         copytree("./integrations/autoconf", "/tmp/autoconf")
         compose = "/tmp/autoconf/docker-compose.yml"
         Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$",
                              "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(compose, r"bunkerity/bunkerweb-autoconf:.*$",
                              "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(compose, r"\./bw\-data:/", "/tmp/bw-data:/")
         proc = run("docker-compose pull", cwd="/tmp/autoconf", shell=True)
         if proc.returncode != 0:
             raise (
                 Exception("docker-compose pull failed (autoconf stack)"))
         proc = run("docker-compose up -d", cwd="/tmp/autoconf", shell=True)
         if proc.returncode != 0:
             raise (Exception("docker-compose up failed (autoconf stack)"))
         i = 0
         healthy = False
         while i < 30:
             proc = run(
                 'docker inspect --format "{{json .State.Health }}" autoconf_mybunker_1',
                 cwd="/tmp/autoconf",
                 shell=True,
                 capture_output=True)
             if proc.returncode != 0:
                 raise (Exception(
                     "docker-compose inspect failed (autoconf stack)"))
             if "healthy" in proc.stdout.decode():
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy:
             raise (Exception("autoconf stack is not healthy"))
     except:
         log("AUTOCONF", "❌",
             "exception while running AutoconfTest.init()\n" + format_exc())
         return False
     return True
Exemple #3
0
 def init():
     try:
         if not Test.init():
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (swarm stack)"))
         if isdir("/tmp/swarm"):
             rmtree("/tmp/swarm")
         copytree("./integrations/swarm", "/tmp/swarm")
         compose = "/tmp/swarm/stack.yml"
         Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$",
                              "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(compose, r"bunkerity/bunkerweb-autoconf:.*$",
                              "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(compose, r"bw\-data:/", "/tmp/bw-data:/")
         proc = run("docker stack deploy -c stack.yml bunkerweb",
                    cwd="/tmp/swarm",
                    shell=True)
         if proc.returncode != 0:
             raise (Exception("docker stack deploy failed (swarm stack)"))
         i = 0
         healthy = False
         while i < 45:
             proc = run(
                 'docker stack ps --no-trunc --format "{{ .CurrentState }}" bunkerweb | grep -v "Running"',
                 cwd="/tmp/swarm",
                 shell=True,
                 capture_output=True)
             if "" == proc.stdout.decode():
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy:
             raise (Exception("swarm stack is not healthy"))
         sleep(60)
     except:
         log("SWARM", "❌",
             "exception while running SwarmTest.init()\n" + format_exc())
         return False
     return True
Exemple #4
0
 def init() :
     try :
         if not Test.init() :
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0 :
             raise(Exception("chown failed (k8s stack)"))
         if isdir("/tmp/kubernetes") :
             rmtree("/tmp/kubernetes")
         copytree("./integrations/kubernetes", "/tmp/kubernetes")
         copy("./tests/utils/k8s.yml", "/tmp/kubernetes")
         deploy = "/tmp/kubernetes/bunkerweb.yml"
         Test.replace_in_file(deploy, r"bunkerity/bunkerweb:.*$", "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(deploy, r"bunkerity/bunkerweb-autoconf:.*$", "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(deploy, r"ifNotPresent", "Always")
         proc = run("sudo kubectl apply -f k8s.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply k8s failed (k8s stack)"))
         proc = run("sudo kubectl apply -f rbac.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply rbac failed (k8s stack)"))
         proc = run("sudo kubectl apply -f bunkerweb.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply bunkerweb failed (k8s stack)"))
         healthy = False
         i = 0
         while i < 30 :
             proc = run('sudo kubectl get pods | grep bunkerweb | grep -v Running', shell=True, capture_output=True)
             if "" == proc.stdout.decode() :
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy :
             raise(Exception("k8s stack is not healthy"))
         sleep(60)
     except :
         log("KUBERNETES", "❌", "exception while running KubernetesTest.init()\n" + format_exc())
         return False
     return True
Exemple #5
0
 def init(distro):
     try:
         if not Test.init():
             return False
         # TODO : find the nginx uid/gid on Docker images
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (autoconf stack)"))
         if isdir("/tmp/linux"):
             rmtree("/tmp/linux")
         mkdir("/tmp/linux")
         chmod("/tmp/linux", 0o0777)
         cmd = "docker run -p 80:80 -p 443:443 --rm --name linux-" + distro + " -d --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro bw-" + distro
         proc = run(cmd, shell=True)
         if proc.returncode != 0:
             raise (Exception("docker run failed (linux stack)"))
         if distro in ["ubuntu", "debian"]:
             cmd = "apt install -y /opt/\$(ls /opt | grep deb)"
         elif distro in ["centos", "fedora"]:
             cmd = "dnf install -y /opt/\$(ls /opt | grep rpm)"
         proc = LinuxTest.docker_exec(distro, cmd)
         if proc.returncode != 0:
             raise (
                 Exception("docker exec apt install failed (linux stack)"))
         proc = LinuxTest.docker_exec(distro, "systemctl start bunkerweb")
         if proc.returncode != 0:
             raise (Exception(
                 "docker exec systemctl start failed (linux stack)"))
         cp_dirs = {
             "/tmp/bw-data/letsencrypt": "/etc/letsencrypt",
             "/tmp/bw-data/cache": "/opt/bunkerweb/cache"
         }
         for src, dst in cp_dirs.items():
             proc = LinuxTest.docker_cp(distro, src, dst)
             if proc.returncode != 0:
                 raise (Exception("docker cp failed for " + src +
                                  " (linux stack)"))
             proc = LinuxTest.docker_exec(
                 distro, "chown -R nginx:nginx " + dst + "/*")
             if proc.returncode != 0:
                 raise (Exception("docker exec failed for directory " +
                                  src + " (linux stack)"))
         if distro in ["ubuntu", "debian"]:
             LinuxTest.docker_exec(
                 distro,
                 "DEBIAN_FRONTEND=noninteractive apt-get install -y php-fpm unzip"
             )
             if distro == "ubuntu":
                 LinuxTest.docker_cp(distro, "./tests/www-deb.conf",
                                     "/etc/php/8.1/fpm/pool.d/www.conf")
                 LinuxTest.docker_exec(
                     distro,
                     "systemctl stop php8.1-fpm ; systemctl start php8.1-fpm"
                 )
             elif distro == "debian":
                 LinuxTest.docker_cp(distro, "./tests/www-deb.conf",
                                     "/etc/php/7.4/fpm/pool.d/www.conf")
                 LinuxTest.docker_exec(
                     distro,
                     "systemctl stop php7.4-fpm ; systemctl start php7.4-fpm"
                 )
         elif distro in ["centos", "fedora"]:
             LinuxTest.docker_exec(distro, "dnf install -y php-fpm unzip")
             LinuxTest.docker_cp(distro, "./tests/www-rpm.conf",
                                 "/etc/php-fpm.d/www.conf")
             LinuxTest.docker_exec(
                 distro,
                 "mkdir /run/php ; chmod 777 /run/php ; systemctl stop php-fpm ; systemctl start php-fpm"
             )
         sleep(60)
     except:
         log("LINUX", "❌",
             "exception while running LinuxTest.init()\n" + format_exc())
         return False
     return True