From 45069dfc0000480497c0a8d8117a54e2b7d293bb Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:41:47 -0300 Subject: [PATCH 01/18] Production Docker with Apache --- Prod.Dockerfile | 15 +++++++++++++++ app/.htaccess | 3 +++ app/public/.htaccess | 4 ++++ install.sh | 13 +++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 Prod.Dockerfile create mode 100644 app/.htaccess create mode 100644 app/public/.htaccess create mode 100644 install.sh diff --git a/Prod.Dockerfile b/Prod.Dockerfile new file mode 100644 index 0000000..f6d29e1 --- /dev/null +++ b/Prod.Dockerfile @@ -0,0 +1,15 @@ +FROM php:8-fpm + +ENV LOGVIEW_INSTALLATION_PATH /app +ENV COMPOSER_ALLOW_SUPERUSER 1 +ENV APACHE_DOCUMENT_ROOT "${LOGVIEW_INSTALLATION_PATH}/app" +ENV APACHE_PUBLIC_ROOT "${LOGVIEW_INSTALLATION_PATH}/app/public" + +COPY --from=composer /usr/bin/composer /usr/bin/composer +WORKDIR "${LOGVIEW_INSTALLATION_PATH}" + +RUN apt-get update \ + && apt-get install -yq --no-install-recommends git \ + && rm -r /var/lib/apt/lists/* \ + && git clone http://git.provm.cl/ProVM/logview.git /app \ + && ${LOGVIEW_INSTALLATION_PATH}/install.sh diff --git a/app/.htaccess b/app/.htaccess new file mode 100644 index 0000000..659993e --- /dev/null +++ b/app/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on +RewriteRule ^$ public/ [L] +RewriteRule (.*) public/$1 [L] diff --git a/app/public/.htaccess b/app/public/.htaccess new file mode 100644 index 0000000..66ef8f6 --- /dev/null +++ b/app/public/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8350b12 --- /dev/null +++ b/install.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +apt-get update +apt-get -yq --no-install-recommends zip unzip libzip-dev +rm -r /var/lib/apt/lists/* +docker-php-ext-install zip + +composer -d "${LOGVIEW_INSTALLATION_PATH}/app" install +mkdir "${LOGVIEW_INSTALLATION_PATH}/app/cache" +chmod -R 777 "${LOGVIEW_INSTALLATION_PATH}/app/cache" + +sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf +sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf From 40598221a124de9bc96bea82f0212eb929867b42 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:48:24 -0300 Subject: [PATCH 02/18] Install script enable mod_rewrite --- install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.sh b/install.sh index 8350b12..bda2e84 100644 --- a/install.sh +++ b/install.sh @@ -11,3 +11,5 @@ chmod -R 777 "${LOGVIEW_INSTALLATION_PATH}/app/cache" sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +a2enmod rewrite From 85be48b794c045cd940c3037d454e1c53d60fd02 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:49:51 -0300 Subject: [PATCH 03/18] FIX: missing install from apt-get command --- install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index bda2e84..4f0e9f3 100644 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash apt-get update -apt-get -yq --no-install-recommends zip unzip libzip-dev +apt-get install -yq --no-install-recommends zip unzip libzip-dev rm -r /var/lib/apt/lists/* docker-php-ext-install zip @@ -13,3 +13,4 @@ sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-availabl sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf a2enmod rewrite +systectl reload apache From 6ea469d5a99b3d6415f814fa2dfc0cf6969d6908 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:50:32 -0300 Subject: [PATCH 04/18] FIX: m missing --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4f0e9f3..4c27318 100644 --- a/install.sh +++ b/install.sh @@ -13,4 +13,4 @@ sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-availabl sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf a2enmod rewrite -systectl reload apache +systemctl reload apache From 05de20cb4beb948306bdafc7191e8ab6671cc1b9 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:51:14 -0300 Subject: [PATCH 05/18] FIX: reload apache correctly --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4c27318..4513c6f 100644 --- a/install.sh +++ b/install.sh @@ -13,4 +13,4 @@ sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-availabl sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf a2enmod rewrite -systemctl reload apache +service apache2 restart From b5065ecea05ffb5596807e5a337cdee2493ff368 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 18:53:33 -0300 Subject: [PATCH 06/18] Added mod_actions and changed way installation path is read --- install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 4513c6f..b188877 100644 --- a/install.sh +++ b/install.sh @@ -5,12 +5,13 @@ apt-get install -yq --no-install-recommends zip unzip libzip-dev rm -r /var/lib/apt/lists/* docker-php-ext-install zip -composer -d "${LOGVIEW_INSTALLATION_PATH}/app" install -mkdir "${LOGVIEW_INSTALLATION_PATH}/app/cache" -chmod -R 777 "${LOGVIEW_INSTALLATION_PATH}/app/cache" +composer -d "$LOGVIEW_INSTALLATION_PATH/app" install +mkdir "$LOGVIEW_INSTALLATION_PATH/app/cache" +chmod -R 777 "$LOGVIEW_INSTALLATION_PATH/app/cache" sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf a2enmod rewrite +a2enmod actions service apache2 restart From b9ba960c798ad190ab8772b56f8fb0ecc75444e7 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 19:03:42 -0300 Subject: [PATCH 07/18] FIX: env vars in install script --- install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index b188877..efa109f 100644 --- a/install.sh +++ b/install.sh @@ -5,12 +5,12 @@ apt-get install -yq --no-install-recommends zip unzip libzip-dev rm -r /var/lib/apt/lists/* docker-php-ext-install zip -composer -d "$LOGVIEW_INSTALLATION_PATH/app" install -mkdir "$LOGVIEW_INSTALLATION_PATH/app/cache" -chmod -R 777 "$LOGVIEW_INSTALLATION_PATH/app/cache" +composer -d $LOGVIEW_INSTALLATION_PATH/app install +mkdir $LOGVIEW_INSTALLATION_PATH/app/cache +chmod -R 777 $LOGVIEW_INSTALLATION_PATH/app/cache -sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf -sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf +sed -ri -e 's!/var/www/html!$APACHE_PUBLIC_ROOT!g' /etc/apache2/sites-available/*.conf +sed -ri -e 's!/var/www/!$APACHE_DOCUMENT_ROOT!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf a2enmod rewrite a2enmod actions From 024a6de924d4c0009ccaf0b78db02248db72560f Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 19:12:23 -0300 Subject: [PATCH 08/18] install script not working, passed to docker file --- Prod.Dockerfile | 14 +++++++++++--- install.sh | 17 ----------------- 2 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 install.sh diff --git a/Prod.Dockerfile b/Prod.Dockerfile index f6d29e1..a741706 100644 --- a/Prod.Dockerfile +++ b/Prod.Dockerfile @@ -9,7 +9,15 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer WORKDIR "${LOGVIEW_INSTALLATION_PATH}" RUN apt-get update \ - && apt-get install -yq --no-install-recommends git \ + && apt-get install -yq --no-install-recommends git zip unzip libzip-dev \ && rm -r /var/lib/apt/lists/* \ - && git clone http://git.provm.cl/ProVM/logview.git /app \ - && ${LOGVIEW_INSTALLATION_PATH}/install.sh + && git clone --branch develop http://git.provm.cl/ProVM/logview.git "${LOGVIEW_INSTALLATION_PATH}" \ + && docker-php-ext-install zip \ + && composer -d "${LOGVIEW_INSTALLATION_PATH}/app" install \ + && mkdir "${LOGVIEW_INSTALLATION_PATH}/app/cache" \ + && chmod -R 777 "${LOGVIEW_INSTALLATION_PATH}/app/cache" \ + && sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf \ + && sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \ + && a2enmod rewrite \ + && a2enmod actions \ + && service apache2 restart diff --git a/install.sh b/install.sh deleted file mode 100644 index efa109f..0000000 --- a/install.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -apt-get update -apt-get install -yq --no-install-recommends zip unzip libzip-dev -rm -r /var/lib/apt/lists/* -docker-php-ext-install zip - -composer -d $LOGVIEW_INSTALLATION_PATH/app install -mkdir $LOGVIEW_INSTALLATION_PATH/app/cache -chmod -R 777 $LOGVIEW_INSTALLATION_PATH/app/cache - -sed -ri -e 's!/var/www/html!$APACHE_PUBLIC_ROOT!g' /etc/apache2/sites-available/*.conf -sed -ri -e 's!/var/www/!$APACHE_DOCUMENT_ROOT!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf - -a2enmod rewrite -a2enmod actions -service apache2 restart From 376b72bacb8b3e94b9b8a261356c05050d745160 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 20:21:47 -0300 Subject: [PATCH 09/18] Working version of Production Dockerfile --- Prod.Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Prod.Dockerfile b/Prod.Dockerfile index a741706..92c0fd1 100644 --- a/Prod.Dockerfile +++ b/Prod.Dockerfile @@ -1,9 +1,9 @@ FROM php:8-fpm -ENV LOGVIEW_INSTALLATION_PATH /app -ENV COMPOSER_ALLOW_SUPERUSER 1 -ENV APACHE_DOCUMENT_ROOT "${LOGVIEW_INSTALLATION_PATH}/app" -ENV APACHE_PUBLIC_ROOT "${LOGVIEW_INSTALLATION_PATH}/app/public" +ENV LOGVIEW_INSTALLATION_PATH=/app +ENV COMPOSER_ALLOW_SUPERUSER=1 +ENV APACHE_DOCUMENT_ROOT="${LOGVIEW_INSTALLATION_PATH}/app" +ENV APACHE_PUBLIC_ROOT="${APACHE_DOCUMENT_ROOT}/public" COPY --from=composer /usr/bin/composer /usr/bin/composer WORKDIR "${LOGVIEW_INSTALLATION_PATH}" @@ -11,13 +11,13 @@ WORKDIR "${LOGVIEW_INSTALLATION_PATH}" RUN apt-get update \ && apt-get install -yq --no-install-recommends git zip unzip libzip-dev \ && rm -r /var/lib/apt/lists/* \ - && git clone --branch develop http://git.provm.cl/ProVM/logview.git "${LOGVIEW_INSTALLATION_PATH}" \ + && git clone http://git.provm.cl/ProVM/logview.git "${LOGVIEW_INSTALLATION_PATH}" \ && docker-php-ext-install zip \ && composer -d "${LOGVIEW_INSTALLATION_PATH}/app" install \ && mkdir "${LOGVIEW_INSTALLATION_PATH}/app/cache" \ && chmod -R 777 "${LOGVIEW_INSTALLATION_PATH}/app/cache" \ - && sed -ri -e 's!/var/www/html!${APACHE_PUBLIC_ROOT}!g' /etc/apache2/sites-available/*.conf \ - && sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \ + && sed -ri -e "s!/var/www/html!${APACHE_PUBLIC_ROOT}!g" /etc/apache2/sites-available/*.conf \ + && sed -ri -e "s!/var/www/!${APACHE_DOCUMENT_ROOT}!g" /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \ && a2enmod rewrite \ && a2enmod actions \ && service apache2 restart From a576f3b0d0a07c20cc8083b158289e34ed005f68 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 20:26:31 -0300 Subject: [PATCH 10/18] Missing logs template files --- app/resources/views/logs/base.blade.php | 5 ++ app/resources/views/logs/show.blade.php | 63 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 app/resources/views/logs/base.blade.php create mode 100644 app/resources/views/logs/show.blade.php diff --git a/app/resources/views/logs/base.blade.php b/app/resources/views/logs/base.blade.php new file mode 100644 index 0000000..532a8bb --- /dev/null +++ b/app/resources/views/logs/base.blade.php @@ -0,0 +1,5 @@ +@extends('layout.base') + +@section('page_title') + File {{$log->getFilename()}} +@endsection diff --git a/app/resources/views/logs/show.blade.php b/app/resources/views/logs/show.blade.php new file mode 100644 index 0000000..cd1183d --- /dev/null +++ b/app/resources/views/logs/show.blade.php @@ -0,0 +1,63 @@ +@extends('logs.base') + +@section('page_content') +
+

Logs

+
+
+ @foreach($log->getLogs() as $line) +
+ + {{$line->getDate()->format('Y-m-d H:i:s.u')}} - {{$line->getSeverity()}} +
+
+
+
+
+ + + {{$line->getChannel()}}.{{$line->getSeverity()}} + +
+
+
+
+ {{$line->getMessage()}} +
+ @if ($line->hasStack()) +
+ @foreach ($line->getStack() as $stack) +
+
+ {{$stack}} +
+
+ @endforeach +
+ @endif +
+ @if ($line->hasContext()) +
+ {{$line->getContext()}} +
{{$line->getExtra()}}
+
+ @endif +
+
+ @endforeach +
+@endsection + +@push('page_styles') + +@endpush + +@push('page_scripts') + +@endpush From b9d5c6c3f54109501047f7009421dff782223522 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 20:40:27 -0300 Subject: [PATCH 11/18] FIX: forgot to change src to app in docker-compose --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4d4cd33..250ad73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - "${WEB_PORT:-8030}:80" volumes: - "./nginx.conf:/etc/nginx/conf.d/default.conf" - - "./src:/app" + - "./app:/app" - "./logs:/logs" php: @@ -19,5 +19,5 @@ services: - app build: . volumes: - - "./src:/app" + - "./app:/app" - "./logs:/logs" From f8dbb1390e32b379e8661dc49d292888eba0ae27 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 20:41:42 -0300 Subject: [PATCH 12/18] FIX: gitignore was ignoring all logs folders --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a8a0611..57618a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ **/*.env **/.idea/ -**/logs/ +/logs/ **/cache/ **/vendor/ **/*.lock From 3718c1e0aacf8091a3470448072216e49f3845b6 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 14 Feb 2023 22:50:35 -0300 Subject: [PATCH 13/18] Improve looks --- app/common/Controller/Base.php | 6 +- app/common/Service/Logs.php | 8 ++- app/resources/views/home.blade.php | 2 +- app/resources/views/logs/base.blade.php | 2 +- app/resources/views/logs/show.blade.php | 79 +++++++++++++------------ app/src/Log.php | 6 +- app/src/Log/File.php | 12 +++- 7 files changed, 70 insertions(+), 45 deletions(-) diff --git a/app/common/Controller/Base.php b/app/common/Controller/Base.php index 1f9e35c..a5b3693 100644 --- a/app/common/Controller/Base.php +++ b/app/common/Controller/Base.php @@ -1,16 +1,20 @@ getFiles(); + usort($files, function(SplFileInfo $a, SplFileInfo $b) { + return $b->getCTime() - $a->getCTime(); + }); return $view->render($response, 'home', compact('files')); } } diff --git a/app/common/Service/Logs.php b/app/common/Service/Logs.php index 24d65f4..d389197 100644 --- a/app/common/Service/Logs.php +++ b/app/common/Service/Logs.php @@ -1,6 +1,8 @@ getFolder(), $log_file])); - return (new File())->setFilename($log_file)->setContent($content); + $filename = implode(DIRECTORY_SEPARATOR, [$this->getFolder(), $log_file]); + $file_info = new SplFileInfo($filename); + $content = \Safe\file_get_contents($filename); + return (new File())->setFilename($log_file)->setDate((new DateTimeImmutable())->setTimestamp($file_info->getCTime()))->setContent($content); } } diff --git a/app/resources/views/home.blade.php b/app/resources/views/home.blade.php index fe56fd2..fde4321 100644 --- a/app/resources/views/home.blade.php +++ b/app/resources/views/home.blade.php @@ -4,7 +4,7 @@ diff --git a/app/resources/views/logs/base.blade.php b/app/resources/views/logs/base.blade.php index 532a8bb..6993900 100644 --- a/app/resources/views/logs/base.blade.php +++ b/app/resources/views/logs/base.blade.php @@ -1,5 +1,5 @@ @extends('layout.base') @section('page_title') - File {{$log->getFilename()}} + Log File @endsection diff --git a/app/resources/views/logs/show.blade.php b/app/resources/views/logs/show.blade.php index cd1183d..15daf0e 100644 --- a/app/resources/views/logs/show.blade.php +++ b/app/resources/views/logs/show.blade.php @@ -2,54 +2,58 @@ @section('page_content')
-

Logs

-
-
- @foreach($log->getLogs() as $line) -
- - {{$line->getDate()->format('Y-m-d H:i:s.u')}} - {{$line->getSeverity()}} -
-
-
-
-
- - - {{$line->getChannel()}}.{{$line->getSeverity()}} - +

Log File: {{$log->getFilename()}}

+
{{$log->getDate()->format('Y-m-d H:i:s')}}
+
+ @foreach($log->getLogs() as $line) +
+ + + {{$line->getDate()->format('Y-m-d H:i:s.u')}} - {{$line->getSeverity()}} + +
+
+
+
+
+ + + {{$line->getChannel()}}.{{$line->getSeverity()}} + +
-
-
-
- {{$line->getMessage()}} -
- @if ($line->hasStack()) -
- @foreach ($line->getStack() as $stack) -
-
- {{$stack}} +
+
+ {{$line->getMessage()}} +
+ @if ($line->hasStack()) +
+ @foreach ($line->getStack() as $stack) +
+
+ {{$stack}} +
-
- @endforeach + @endforeach +
+ @endif +
+ @if ($line->hasContext()) +
+ {{$line->getContext()}} +
{{$line->getExtra()}}
@endif
- @if ($line->hasContext()) -
- {{$line->getContext()}} -
{{$line->getExtra()}}
-
- @endif
-
- @endforeach + @endforeach +
@endsection @push('page_styles')