From 1ec745169c23c2a6ddad7453282db95641617100 Mon Sep 17 00:00:00 2001 From: Pulsebright Date: Mon, 26 Apr 2021 09:33:11 -0400 Subject: [PATCH] Fixed https (CachetHQ/Docker#383) and app startup (CachetHQ/Docker#379) --- Dockerfile | 32 +++++++++++++++++++++++++++++++- entrypoint.sh | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d13af0be..dab6b5c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ CMD ["/sbin/entrypoint.sh"] ARG cachet_ver ARG archive_url -ENV cachet_ver ${cachet_ver:-v2.3.18} +ENV cachet_ver ${cachet_ver:-2.4} ENV archive_url ${archive_url:-https://github.com/cachethq/Cachet/archive/${cachet_ver}.tar.gz} ENV COMPOSER_VERSION 1.9.0 @@ -104,3 +104,33 @@ USER root RUN chmod g+rwx /var/run/nginx.pid && \ chmod -R g+rw /var/www /usr/share/nginx/cache /var/cache/nginx /var/lib/nginx/ /etc/php7/php-fpm.d storage USER 1001 + +RUN set -e; \ + # HOTFIX 1: force root URL and schema + # We locate the boot() method in AppServiceProvider.php + #ls /var/www/html/app/Foundation/Providers/AppServiceProvider.php \ + line=$(grep -n 'public function boot(Dispatcher $dispatcher)$' /var/www/html/app/Providers/AppServiceProvider.php | tail -n1 | cut -f1 -d:); \ +\ + # We insert the code 2 lines after because there is a "{" on a separate line + insertAtLine=$((line+2)); \ +\ + # We insert the hotfix + sed -i "$insertAtLine i \\ \ + if (getenv('APP_URL')) { \n \ + if (strpos(getenv('APP_URL'), 'https') === 0) { \n \ + \\\URL::forceScheme('https'); \n \ + } \n \ + \\\URL::forceRootUrl(getenv('APP_URL')); \n \ + } \n \ + " /var/www/html/app/Providers/AppServiceProvider.php; \ +\ + # We forward the APP_URL environment variable to FPM + echo '[www]' > /etc/php7/php-fpm.d/app-url-fix.conf; \ + echo 'env[APP_URL] = $APP_URL' >> /etc/php7/php-fpm.d/app-url-fix.conf; \ +\ + # HOTFIX 2: fix login redirection to dashboard + # Normally it redirects to the last URL, but since Laravel is not able to detect URLs right, we force a redirection to dashboard + sed -i "s/Redirect::intended(cachet_route('dashboard'));/cachet_redirect('dashboard');/g" \ + /var/www/html/app/Http/Controllers/AuthController.php; \ + sed -i "s/Redirect::intended('dashboard');/cachet_redirect('dashboard');/g" \ + /var/www/html/app/Http/Controllers/AuthController.php \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 0ed4a593..2471d37b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -210,7 +210,7 @@ initialize_system() { init_db() { echo "Initializing Cachet database ..." - php artisan cachet:install --no-interaction + php artisan app:install --no-interaction check_configured }