From 62d8aa775a1067a9a7bbf048580ac69cb573a721 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 6 Jan 2025 16:09:00 +0100
Subject: [PATCH] wip

---
 config/docker-files/7.2-Dockerfile          |  1 +
 config/docker-files/7.3-Dockerfile          |  1 +
 config/docker-files/7.4-Dockerfile          |  1 +
 config/docker-files/8.0-Dockerfile          |  1 +
 config/docker-files/8.1-Dockerfile          |  1 +
 config/docker-files/8.2-Dockerfile          |  1 +
 config/docker-files/8.3-Dockerfile          |  1 +
 config/docker-files/8.4-Dockerfile          |  8 ++++++--
 lib/Commands/Compile.php                    | 15 +++++++++++++--
 lib/Creators/DockerComposeConfiguration.php |  2 +-
 web/LogParser.php                           |  8 ++++++++
 web/assets/style.css                        |  4 ++--
 web/index.php                               |  4 +++-
 13 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/config/docker-files/7.2-Dockerfile b/config/docker-files/7.2-Dockerfile
index b9d267a..18405ca 100644
--- a/config/docker-files/7.2-Dockerfile
+++ b/config/docker-files/7.2-Dockerfile
@@ -2,6 +2,7 @@ FROM php:7.2-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/7.3-Dockerfile b/config/docker-files/7.3-Dockerfile
index 905c3a0..91cd748 100644
--- a/config/docker-files/7.3-Dockerfile
+++ b/config/docker-files/7.3-Dockerfile
@@ -2,6 +2,7 @@ FROM php:7.3-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/7.4-Dockerfile b/config/docker-files/7.4-Dockerfile
index be4b2e1..13a1619 100644
--- a/config/docker-files/7.4-Dockerfile
+++ b/config/docker-files/7.4-Dockerfile
@@ -2,6 +2,7 @@ FROM php:7.4-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/8.0-Dockerfile b/config/docker-files/8.0-Dockerfile
index d90fa8d..689d852 100644
--- a/config/docker-files/8.0-Dockerfile
+++ b/config/docker-files/8.0-Dockerfile
@@ -2,6 +2,7 @@ FROM php:8.0-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/8.1-Dockerfile b/config/docker-files/8.1-Dockerfile
index ba576ed..f131e36 100644
--- a/config/docker-files/8.1-Dockerfile
+++ b/config/docker-files/8.1-Dockerfile
@@ -2,6 +2,7 @@ FROM php:8.1-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/8.2-Dockerfile b/config/docker-files/8.2-Dockerfile
index ed87ae9..423e804 100644
--- a/config/docker-files/8.2-Dockerfile
+++ b/config/docker-files/8.2-Dockerfile
@@ -2,6 +2,7 @@ FROM php:8.2-fpm
 
 # Install system requirements
 RUN apt update && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         imagemagick ghostscript \
diff --git a/config/docker-files/8.3-Dockerfile b/config/docker-files/8.3-Dockerfile
index f430b68..60e0c0c 100644
--- a/config/docker-files/8.3-Dockerfile
+++ b/config/docker-files/8.3-Dockerfile
@@ -3,6 +3,7 @@ FROM php:8.3-fpm
 # Install system requirements
 RUN apt update \
     && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         git \
diff --git a/config/docker-files/8.4-Dockerfile b/config/docker-files/8.4-Dockerfile
index a19bbd3..43d30d2 100644
--- a/config/docker-files/8.4-Dockerfile
+++ b/config/docker-files/8.4-Dockerfile
@@ -2,7 +2,9 @@ FROM php:8.4-fpm
 
 # Install system requirements
 RUN apt update \
+    && apt upgrade -y \
     && apt install -y --no-install-recommends \
+        ca-certificates \
         default-mysql-client \
         default-libmysqlclient-dev \
         git \
@@ -30,8 +32,10 @@ RUN apt update \
 # Install php extensions
     && docker-php-ext-configure gd --with-jpeg --with-freetype --with-webp \
     && docker-php-ext-install -j$(nproc) gd gettext intl mysqli opcache pdo_mysql pdo_pgsql soap xsl zip \
-    && pecl install memcached redis xdebug \
-    && docker-php-ext-enable memcached redis xdebug \
+#    && pecl install memcached redis xdebug \
+#    && docker-php-ext-enable memcached redis xdebug \
+    && pecl install memcached redis \
+    && docker-php-ext-enable memcached redis \
 
 # Cleanup
     && docker-php-source delete \
diff --git a/lib/Commands/Compile.php b/lib/Commands/Compile.php
index ab7701d..c203ff6 100644
--- a/lib/Commands/Compile.php
+++ b/lib/Commands/Compile.php
@@ -168,6 +168,7 @@ final class Compile extends Command
             'container_name' => 'db',
             'ports'          => ['3306:3306'],
             'restart'        => 'unless-stopped',
+            'volumes'        => ['db-data:/var/lib/mysql'],
             'environment'    => [
                 'MARIADB_ROOT_PASSWORD' => 'rootpwd',
                 'MARIADB_USER' => 'studip',
@@ -175,7 +176,13 @@ final class Compile extends Command
                 'MARIADB_MYSQL_LOCALHOST_USER' => 'root',
                 'MARIADB_AUTO_UPGRADE'  => true,
             ],
-            'volumes'        => ['db-data:/var/lib/mysql'],
+            'healthcheck'    => [
+                'test'         => ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"],
+                'start_period' => '10s',
+                'interval'     => '10s',
+                'timeout'      => '10s',
+                'retries'      => 3,
+            ]
         ]);
         $creator->addVolume('db-data');
 
@@ -211,7 +218,11 @@ final class Compile extends Command
                 'environment' => [
                     'MYSQL_HOST' => 'db',
                 ],
-                'depends_on' => ['db'],
+                'depends_on' => [
+                    'db' => [
+                        'condition' => 'service_healthy',
+                    ]
+                ],
             ]);
 
             $creator->addServiceVolume(
diff --git a/lib/Creators/DockerComposeConfiguration.php b/lib/Creators/DockerComposeConfiguration.php
index 9b6438c..4beb0c4 100644
--- a/lib/Creators/DockerComposeConfiguration.php
+++ b/lib/Creators/DockerComposeConfiguration.php
@@ -63,6 +63,6 @@ final class DockerComposeConfiguration extends ConfigurationCreator
 
     public function dump(): string
     {
-        return Yaml::dump($this->getConfiguration(), 128);
+        return Yaml::dump($this->getConfiguration(), 4);
     }
 }
diff --git a/web/LogParser.php b/web/LogParser.php
index 48fad38..8ac4c4a 100644
--- a/web/LogParser.php
+++ b/web/LogParser.php
@@ -26,6 +26,14 @@ final class LogParser
                 continue;
             }
 
+            $line = str_replace(
+                [
+                    '/usr/share/nginx/'
+                ],
+                '',
+                $line
+            );
+
             if ($index === -1 || preg_match('/^\[.+]/', $line)) {
                 $index += 1;
             }
diff --git a/web/assets/style.css b/web/assets/style.css
index 395d483..0a34cd0 100644
--- a/web/assets/style.css
+++ b/web/assets/style.css
@@ -78,11 +78,11 @@ tr:hover td {
     padding-top: var(--nav-font-size);
 }
 #logs-nav {
-    background-color: inherit;
+    background-color: black;
     border-bottom: 1px solid #ccc;
     padding: 0 0.5em;
     position: fixed;
-    top: calc(var(--nav-height) + var(--nav-font-size));
+    top: calc(var(--nav-height) + 1em + 1px);
     left: 0;
     right: 0;
 
diff --git a/web/index.php b/web/index.php
index 82ff48a..ccb4685 100644
--- a/web/index.php
+++ b/web/index.php
@@ -101,7 +101,9 @@ $log = new LogParser(__DIR__ . '/../logs/php/error.log');
     <?php if ($log->hasData()): ?>
         <ul>
         <?php foreach ($log->entries() as $entry): ?>
-            <li><?= nl2br(htmlentities($entry)) ?></li>
+            <li>
+                <?= nl2br(htmlentities($entry)) ?>
+            </li>
         <?php endforeach; ?>
         </ul>
     <?php endif; ?>
-- 
GitLab