From 4e5261f4f06c439071fba8629f95e84c60f2bf8f Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Tue, 5 Sep 2023 09:29:14 -0400 Subject: [PATCH] [Feature] PHP 8.2 and performance improvements (#676) --- .dockerignore | 1 + .env.example | 7 ++- .env.production | 41 ++++--------- .github/pull_request_template.md | 4 ++ Dockerfile | 20 ++++--- config/app.php | 2 +- config/broadcasting.php | 2 +- config/cache.php | 2 +- config/logging.php | 2 +- config/session.php | 2 +- docker-compose.yml | 8 +-- docker/8.1/Dockerfile | 58 ------------------- docker/8.1/php.ini | 7 --- docker/8.1/start-container | 17 ------ docker/8.1/supervisord.conf | 21 ------- docker/8.2/Dockerfile | 2 +- .../s6-overlay/scripts/laravel-automations | 15 ++--- docker/mysql/create-testing-database.sh | 6 ++ docker/pgsql/create-testing-database.sql | 2 + 19 files changed, 55 insertions(+), 164 deletions(-) delete mode 100644 docker/8.1/Dockerfile delete mode 100644 docker/8.1/php.ini delete mode 100644 docker/8.1/start-container delete mode 100644 docker/8.1/supervisord.conf create mode 100644 docker/mysql/create-testing-database.sh create mode 100644 docker/pgsql/create-testing-database.sql diff --git a/.dockerignore b/.dockerignore index ea3808ae9..24c19c44a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,3 +23,4 @@ Homestead.json Homestead.yaml npm-debug.log yarn-error.log +*.postman_collection.json diff --git a/.env.example b/.env.example index 4b91461e7..4dcf954bc 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,11 @@ APP_KEY= APP_DEBUG=false APP_URL=http://localhost +FORCE_HTTPS=false +DASHBOARD_POLLING=60 +NOTIFICATION_POLLING=60 +RESULTS_POLLING=false + LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug @@ -37,4 +42,4 @@ AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false -TELEGRAM_BOT_TOKEN= +TELEGRAM_BOT_TOKEN=null diff --git a/.env.production b/.env.production index 99359c331..2ec9c2f44 100644 --- a/.env.production +++ b/.env.production @@ -1,29 +1,15 @@ -APP_NAME="Speedtest Tracker" -APP_ENV=production -APP_KEY= -APP_DEBUG=false -APP_URL=http://localhost - -FORCE_HTTPS=false - -LOG_CHANNEL=stderr -LOG_DEPRECATIONS_CHANNEL=null -LOG_LEVEL=error +# A full list of options can be found in the '.env.example' file. -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=speedtest_tracker -DB_USERNAME= -DB_PASSWORD= +# Application key +# Used for encryption where needed, if a key is not generated run: php artisan key:generate +APP_KEY= -BROADCAST_DRIVER=log -CACHE_DRIVER=database -FILESYSTEM_DISK=local -QUEUE_CONNECTION=database -SESSION_DRIVER=database -SESSION_LIFETIME=120 +# Application URL +# Not used in the URL but effects links in emails and notifications: https://docs.speedtest-tracker.dev/faqs#links-in-emails-dont-point-to-the-correct-url +APP_URL=http://localhost +# SMTP mail config +# Only SMTP protocol is supported at this time: https://docs.speedtest-tracker.dev/settings/notifications/mail MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 @@ -33,10 +19,5 @@ MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -TELEGRAM_BOT_TOKEN= +# Telegram bot config +TELEGRAM_BOT_TOKEN=null diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index cbc4fdad0..495ccbe81 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,18 +5,22 @@ A short description of the pull request changes should go here and the sections ## Changelog ### Added + - one - two ### Changed + - one - two ### Fixed + - one - two ### Removed + - one - two diff --git a/Dockerfile b/Dockerfile index 0efb98e81..e3f1bb7b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM serversideup/php:8.1-fpm-nginx +FROM serversideup/php:8.2-fpm-nginx # Add /config to allowed directory tree ENV PHP_OPEN_BASEDIR=$WEBUSER_HOME:/config/:/dev/stdout:/tmp @@ -11,7 +11,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ cron \ htop \ - php8.1-pgsql \ + php8.2-pgsql \ && echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel \ \ # Install Speedtest cli @@ -25,15 +25,17 @@ RUN apt-get update \ # Copy package configs COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/ -WORKDIR /var/www/html - # Copy app -COPY --chown=webuser:webgroup . /var/www/html +COPY --chown=webuser:webgroup . $WEBUSER_HOME + +WORKDIR $WEBUSER_HOME # Install app dependencies -RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev --no-cache \ - && mkdir -p storage/logs \ - && php artisan optimize:clear \ - && chown -R webuser:webgroup /var/www/html +RUN composer install \ + --no-interaction \ + --prefer-dist \ + --optimize-autoloader \ + --no-dev \ + --no-cache VOLUME /config diff --git a/config/app.php b/config/app.php index 5fbc360f0..8521377db 100644 --- a/config/app.php +++ b/config/app.php @@ -16,7 +16,7 @@ | */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => env('APP_NAME', 'Speedtest Tracker'), /* |-------------------------------------------------------------------------- diff --git a/config/broadcasting.php b/config/broadcasting.php index 9e4d4aa44..f386242fb 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -15,7 +15,7 @@ | */ - 'default' => env('BROADCAST_DRIVER', 'null'), + 'default' => env('BROADCAST_DRIVER', 'log'), /* |-------------------------------------------------------------------------- diff --git a/config/cache.php b/config/cache.php index 33bb29546..7e47bb015 100644 --- a/config/cache.php +++ b/config/cache.php @@ -15,7 +15,7 @@ | */ - 'default' => env('CACHE_DRIVER', 'file'), + 'default' => env('CACHE_DRIVER', 'database'), /* |-------------------------------------------------------------------------- diff --git a/config/logging.php b/config/logging.php index 8c9c82ba4..cf03a0930 100644 --- a/config/logging.php +++ b/config/logging.php @@ -18,7 +18,7 @@ | */ - 'default' => env('LOG_CHANNEL', 'stack'), + 'default' => env('LOG_CHANNEL', 'stderr'), /* |-------------------------------------------------------------------------- diff --git a/config/session.php b/config/session.php index 8fed97c01..cbcaf0b47 100644 --- a/config/session.php +++ b/config/session.php @@ -18,7 +18,7 @@ | */ - 'driver' => env('SESSION_DRIVER', 'file'), + 'driver' => env('SESSION_DRIVER', 'database'), /* |-------------------------------------------------------------------------- diff --git a/docker-compose.yml b/docker-compose.yml index 76a00ca5b..2ed018c1d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,11 +2,11 @@ version: '3' services: laravel.test: build: - context: ./docker/8.1 + context: ./docker/8.2 dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' - image: speedtest-tracker-8.1/app + image: speedtest-tracker-8.2/app extra_hosts: - 'host.docker.internal:host-gateway' ports: @@ -38,7 +38,7 @@ services: MYSQL_ALLOW_EMPTY_PASSWORD: 1 volumes: - 'sail-mysql:/var/lib/mysql' - - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' + - './docker/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' networks: - sail healthcheck: @@ -67,7 +67,7 @@ services: # POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}' # volumes: # - 'sail-pgsql:/var/lib/postgresql/data' - # - './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql' + # - './docker/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql' # networks: # - sail # healthcheck: diff --git a/docker/8.1/Dockerfile b/docker/8.1/Dockerfile deleted file mode 100644 index 7043534d4..000000000 --- a/docker/8.1/Dockerfile +++ /dev/null @@ -1,58 +0,0 @@ -FROM ubuntu:22.04 - -LABEL maintainer="Alex Justesen" - -ARG WWWGROUP -ARG NODE_VERSION=18 -ARG POSTGRES_VERSION=15 - -WORKDIR /var/www/html - -ENV DEBIAN_FRONTEND noninteractive -ENV TZ=UTC - -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -RUN apt-get update \ - && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin cron \ - && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null \ - && echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ - && apt-get update \ - && apt-get install -y php8.1-cli php8.1-dev \ - php8.1-pgsql php8.1-sqlite3 php8.1-gd \ - php8.1-curl \ - php8.1-mysql php8.1-mbstring \ - php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \ - php8.1-intl php8.1-readline \ - php8.1-msgpack php8.1-igbinary php8.1-redis \ - php8.1-memcached php8.1-pcov php8.1-xdebug \ - && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \ - && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ - && apt-get install -y nodejs \ - && npm install -g npm \ - && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null \ - && echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && apt-get update \ - && apt-get install -y mysql-client \ - && apt-get install -y postgresql-client-$POSTGRES_VERSION \ - && curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash \ - && apt-get update \ - && apt-get install -y speedtest \ - && apt-get -y autoremove \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - && echo "MAILTO=\"\"\n* * * * * sail /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel - -RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1 - -RUN groupadd --force -g $WWWGROUP sail -RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail - -COPY start-container /usr/local/bin/start-container -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini -RUN chmod +x /usr/local/bin/start-container - -EXPOSE 8000 - -ENTRYPOINT ["start-container"] diff --git a/docker/8.1/php.ini b/docker/8.1/php.ini deleted file mode 100644 index 39dcbcac9..000000000 --- a/docker/8.1/php.ini +++ /dev/null @@ -1,7 +0,0 @@ -[PHP] -post_max_size = 100M -upload_max_filesize = 100M -variables_order = EGPCS - -[opcache] -opcache.enable_cli=1 diff --git a/docker/8.1/start-container b/docker/8.1/start-container deleted file mode 100644 index b86439907..000000000 --- a/docker/8.1/start-container +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -if [ ! -z "$WWWUSER" ]; then - usermod -u $WWWUSER sail -fi - -if [ ! -d /.composer ]; then - mkdir /.composer -fi - -chmod -R ugo+rw /.composer - -if [ $# -gt 0 ]; then - exec gosu $WWWUSER "$@" -else - exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf -fi diff --git a/docker/8.1/supervisord.conf b/docker/8.1/supervisord.conf deleted file mode 100644 index 2067142ca..000000000 --- a/docker/8.1/supervisord.conf +++ /dev/null @@ -1,21 +0,0 @@ -[supervisord] -nodaemon=true -user=root -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - -[program:cron] -command=/usr/sbin/cron -f -l 8 -user=root -autostart=true -stdout_logfile=/var/log/cron.out.log -stderr_logfile=/var/log/cron.err.log - -[program:php] -command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80 -user=sail -environment=LARAVEL_SAIL="1" -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 diff --git a/docker/8.2/Dockerfile b/docker/8.2/Dockerfile index dbbda198c..d62530220 100644 --- a/docker/8.2/Dockerfile +++ b/docker/8.2/Dockerfile @@ -14,7 +14,7 @@ ENV TZ=UTC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update \ - && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin cron \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch cron \ && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \ && echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ && apt-get update \ diff --git a/docker/deploy/etc/s6-overlay/scripts/laravel-automations b/docker/deploy/etc/s6-overlay/scripts/laravel-automations index b5286cbdd..7d0c15a87 100644 --- a/docker/deploy/etc/s6-overlay/scripts/laravel-automations +++ b/docker/deploy/etc/s6-overlay/scripts/laravel-automations @@ -11,7 +11,8 @@ echo "" echo "🔒 Fixing app path file permissions..." chmod -R 755 /config chown -R webuser:webgroup /config -chown -R webuser:webgroup $WEBUSER_HOME +chmod -R 755 $WEBUSER_HOME/storage +chown -R webuser:webgroup $WEBUSER_HOME/storage echo "✅ Permissions fixed." echo "" @@ -51,7 +52,6 @@ echo "" echo "🔗 Creating symlinks for config and log files..." symlinks=( \ /var/www/html/.env \ -/var/www/html/storage/logs/laravel.log ) for i in "${symlinks[@]}" @@ -78,17 +78,10 @@ fi echo "" -# create storage symlink -echo "🔐 Linking the storage..." -s6-setuidgid webuser php $WEBUSER_HOME/artisan storage:link --no-ansi -q -echo "✅ Storage linked." -echo "" - # Build cache echo "💰 Building the cache..." -s6-setuidgid webuser php $WEBUSER_HOME/artisan config:cache --no-ansi -q -s6-setuidgid webuser php $WEBUSER_HOME/artisan route:cache --no-ansi -q -s6-setuidgid webuser php $WEBUSER_HOME/artisan view:cache --no-ansi -q +s6-setuidgid webuser php $WEBUSER_HOME/artisan view:clear --no-ansi -q +s6-setuidgid webuser php $WEBUSER_HOME/artisan optimize --no-ansi -q echo "✅ Cache set." echo "" diff --git a/docker/mysql/create-testing-database.sh b/docker/mysql/create-testing-database.sh new file mode 100644 index 000000000..aeb1826f1 --- /dev/null +++ b/docker/mysql/create-testing-database.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +mysql --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL + CREATE DATABASE IF NOT EXISTS testing; + GRANT ALL PRIVILEGES ON \`testing%\`.* TO '$MYSQL_USER'@'%'; +EOSQL diff --git a/docker/pgsql/create-testing-database.sql b/docker/pgsql/create-testing-database.sql new file mode 100644 index 000000000..d84dc07b8 --- /dev/null +++ b/docker/pgsql/create-testing-database.sql @@ -0,0 +1,2 @@ +SELECT 'CREATE DATABASE testing' +WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'testing')\gexec