From 3bc7eca958035849083e093241867b15683b057b Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Tue, 25 Jun 2024 18:42:40 +0200 Subject: [PATCH] Moved from swoole to frankenphp --- .env.production | 2 +- .github/workflows/build-private.yml | 4 +- .github/workflows/build-public.yml | 2 + .gitignore | 6 + config/octane.php | 5 +- docker-compose.yml | 4 +- docker/prod/Dockerfile | 200 +++++++++++------- docker/prod/README.md | 128 ----------- .../FrankenPHP/supervisord.frankenphp.conf | 51 +++++ .../octane/RoadRunner/.rr.prod.yaml | 25 +++ .../RoadRunner/supervisord.roadrunner.conf | 50 +++++ .../octane/Swoole/supervisord.swoole.conf | 50 +++++ docker/prod/deployment/php.ini | 1 + docker/prod/deployment/start-container | 17 +- docker/prod/deployment/supervisord.conf | 14 ++ .../prod/deployment/supervisord.horizon.conf | 9 +- .../deployment/supervisord.scheduler.conf | 13 +- .../prod/deployment/supervisord.worker.conf | 9 +- 18 files changed, 364 insertions(+), 226 deletions(-) delete mode 100644 docker/prod/README.md create mode 100644 docker/prod/deployment/octane/FrankenPHP/supervisord.frankenphp.conf create mode 100644 docker/prod/deployment/octane/RoadRunner/.rr.prod.yaml create mode 100644 docker/prod/deployment/octane/RoadRunner/supervisord.roadrunner.conf create mode 100644 docker/prod/deployment/octane/Swoole/supervisord.swoole.conf create mode 100644 docker/prod/deployment/supervisord.conf diff --git a/.env.production b/.env.production index a6dea9f8..6ec63f81 100644 --- a/.env.production +++ b/.env.production @@ -4,7 +4,7 @@ APP_ENV=production APP_DEBUG=false APP_FORCE_HTTPS=true SESSION_SECURE_COOKIE=true -OCTANE_SERVER=swoole +OCTANE_SERVER=frankenphp PAGINATION_PER_PAGE_DEFAULT=500 LOG_CHANNEL=stack diff --git a/.github/workflows/build-private.yml b/.github/workflows/build-private.yml index eb4f8ecf..e766a219 100644 --- a/.github/workflows/build-private.yml +++ b/.github/workflows/build-private.yml @@ -69,7 +69,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.3' - extensions: mbstring, dom, fileinfo, pgsql, swoole + extensions: mbstring, dom, fileinfo, pgsql - name: "Install dependencies" uses: php-actions/composer@v6 @@ -119,6 +119,8 @@ jobs: uses: docker/build-push-action@v6 with: context: . + build-args: | + DOCKER_FILES_BASE_PATH=docker/prod/ file: docker/prod/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/build-public.yml b/.github/workflows/build-public.yml index 78172053..daf55a77 100644 --- a/.github/workflows/build-public.yml +++ b/.github/workflows/build-public.yml @@ -66,6 +66,8 @@ jobs: with: context: . file: docker/prod/Dockerfile + build-args: | + DOCKER_FILES_BASE_PATH=docker/prod/ platforms: linux/amd64 push: true tags: ${{ steps.meta.outputs.tags }} diff --git a/.gitignore b/.gitignore index e9d56a37..7dd40c6d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,9 @@ yarn-error.log /_ide_helper.php /.phpstorm.meta.php /.rnd + +/caddy +/frankenphp +/public/frankenphp-worker.php +/data +/confif/caddy diff --git a/config/octane.php b/config/octane.php index a25814b1..b0ef4ff8 100644 --- a/config/octane.php +++ b/config/octane.php @@ -14,10 +14,13 @@ use Laravel\Octane\Events\WorkerStarting; use Laravel\Octane\Events\WorkerStopping; use Laravel\Octane\Listeners\CloseMonologHandlers; +use Laravel\Octane\Listeners\CollectGarbage; +use Laravel\Octane\Listeners\DisconnectFromDatabases; use Laravel\Octane\Listeners\EnsureUploadedFilesAreValid; use Laravel\Octane\Listeners\EnsureUploadedFilesCanBeMoved; use Laravel\Octane\Listeners\FlushOnce; use Laravel\Octane\Listeners\FlushTemporaryContainerInstances; +use Laravel\Octane\Listeners\FlushUploadedFiles; use Laravel\Octane\Listeners\ReportException; use Laravel\Octane\Listeners\StopWorkerIfNecessary; use Laravel\Octane\Octane; @@ -37,7 +40,7 @@ | */ - 'server' => env('OCTANE_SERVER', 'swoole'), + 'server' => env('OCTANE_SERVER', 'frankenphp'), /* |-------------------------------------------------------------------------- diff --git a/docker-compose.yml b/docker-compose.yml index 3c0bb5b5..bad1a13c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,9 @@ services: extra_hosts: - 'host.docker.internal:host-gateway' environment: - SUPERVISOR_PHP_COMMAND: "/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --watch --host=0.0.0.0 --port=80" + SUPERVISOR_PHP_COMMAND: "/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=frankenphp --host=0.0.0.0 --admin-port=2019 --port=80 --watch" + XDG_CONFIG_HOME: /var/www/html/config + XDG_DATA_HOME: /var/www/html/data WWWUSER: '${WWWUSER}' LARAVEL_SAIL: 1 XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 09aec9bb..f9294643 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -1,120 +1,178 @@ # Accepted values: 8.3 - 8.2 ARG PHP_VERSION=8.3 -ARG DOCKER_FILES_BASE_PATH="docker/prod" +ARG FRANKENPHP_VERSION=latest ARG COMPOSER_VERSION=latest +ARG DOCKER_FILES_BASE_PATH="docker/prod/" + +########################################### +# Build frontend assets with NPM +########################################### + +#ARG NODE_VERSION=20-alpine +# +#FROM node:${NODE_VERSION} AS build +# +#ENV ROOT=/var/www/html +# +#WORKDIR ${ROOT} +# +#RUN npm config set update-notifier false && npm set progress=false +# +#COPY package*.json ./ +# +#RUN if [ -f $ROOT/package-lock.json ]; \ +# then \ +# npm ci --loglevel=error --no-audit; \ +# else \ +# npm install --loglevel=error --no-audit; \ +# fi +# +#COPY . . +# +#RUN npm run build + ########################################### FROM composer:${COMPOSER_VERSION} AS vendor -FROM php:${PHP_VERSION}-cli-bookworm AS base +FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION} + +ARG DOCKER_FILES_BASE_PATH LABEL maintainer="solidtime " LABEL org.opencontainers.image.title="solidtime" -LABEL org.opencontainers.image.description="solidtime is a modern open source timetracker for Freelancers and Agencies" +LABEL org.opencontainers.image.description="solidtime is a modern open source timetracker for freelancers and agencies" LABEL org.opencontainers.image.source="https://github.com/solidtime-io/solidtime" LABEL org.opencontainers.image.licenses="AGPL" ARG WWWUSER=1000 ARG WWWGROUP=1000 ARG TZ=UTC +ARG APP_DIR=/var/www/html ENV DEBIAN_FRONTEND=noninteractive \ - TERM=xterm-color \ - WITH_HORIZON=false \ - WITH_SCHEDULER=false \ - OCTANE_SERVER=swoole \ - USER=octane \ - ROOT=/var/www/html \ - COMPOSER_FUND=0 \ - COMPOSER_MAX_PARALLEL_HTTP=24 + TERM=xterm-color \ + WITH_HORIZON=false \ + WITH_SCHEDULER=false \ + OCTANE_SERVER=frankenphp \ + USER=octane \ + ROOT=${APP_DIR} \ + COMPOSER_FUND=0 \ + COMPOSER_MAX_PARALLEL_HTTP=24 \ + XDG_CONFIG_HOME=${APP_DIR}/.config \ + XDG_DATA_HOME=${APP_DIR}/.data WORKDIR ${ROOT} SHELL ["/bin/bash", "-eou", "pipefail", "-c"] RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \ - && echo ${TZ} > /etc/timezone - -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + && echo ${TZ} > /etc/timezone RUN apt-get update; \ - apt-get upgrade -yqq; \ - apt-get install -yqq --no-install-recommends --show-progress \ - apt-utils \ - curl \ - wget \ - nano \ - ncdu \ - ca-certificates \ - supervisor \ - libsodium-dev \ - # Install PHP extensions - && install-php-extensions \ - bz2 \ - pcntl \ - mbstring \ - bcmath \ - sockets \ - pgsql \ - pdo_pgsql \ - opcache \ - exif \ - pdo_mysql \ - zip \ - intl \ - gd \ - redis \ - rdkafka \ - memcached \ - igbinary \ - ldap \ - swoole \ - && apt-get -y autoremove \ - && apt-get clean \ - && docker-php-source delete \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - && rm /var/log/lastlog /var/log/faillog - -RUN wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64" \ - -O /usr/bin/supercronic \ - && chmod +x /usr/bin/supercronic \ - && mkdir -p /etc/supercronic \ - && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel + apt-get upgrade -yqq; \ + apt-get install -yqq --no-install-recommends --show-progress \ + apt-utils \ + curl \ + wget \ + nano \ + ncdu \ + procps \ + ca-certificates \ + supervisor \ + libsodium-dev \ + # Install PHP extensions (included with dunglas/frankenphp) + && install-php-extensions \ + bz2 \ + pcntl \ + mbstring \ + bcmath \ + sockets \ + pgsql \ + pdo_pgsql \ + opcache \ + exif \ + pdo_mysql \ + zip \ + intl \ + gd \ + redis \ + rdkafka \ + memcached \ + igbinary \ + ldap \ + && apt-get -y autoremove \ + && apt-get clean \ + && docker-php-source delete \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ + && rm /var/log/lastlog /var/log/faillog + +RUN arch="$(uname -m)" \ + && case "$arch" in \ + armhf) _cronic_fname='supercronic-linux-arm' ;; \ + aarch64) _cronic_fname='supercronic-linux-arm64' ;; \ + x86_64) _cronic_fname='supercronic-linux-amd64' ;; \ + x86) _cronic_fname='supercronic-linux-386' ;; \ + *) echo >&2 "error: unsupported architecture: $arch"; exit 1 ;; \ + esac \ + && wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/${_cronic_fname}" \ + -O /usr/bin/supercronic \ + && chmod +x /usr/bin/supercronic \ + && mkdir -p /etc/supercronic \ + && echo "*/1 * * * * php ${ROOT}/artisan schedule:run --no-interaction" > /etc/supercronic/laravel RUN userdel --remove --force www-data \ - && groupadd --force -g ${WWWGROUP} ${USER} \ - && useradd -ms /bin/bash --no-log-init --no-user-group -g ${WWWGROUP} -u ${WWWUSER} ${USER} + && groupadd --force -g ${WWWGROUP} ${USER} \ + && useradd -ms /bin/bash --no-log-init --no-user-group -g ${WWWGROUP} -u ${WWWUSER} ${USER} RUN chown -R ${USER}:${USER} ${ROOT} /var/{log,run} \ - && chmod -R a+rw /var/{log,run} + && chmod -R a+rw ${ROOT} /var/{log,run} RUN cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini USER ${USER} COPY --chown=${USER}:${USER} --from=vendor /usr/bin/composer /usr/bin/composer +#COPY --chown=${USER}:${USER} composer.json composer.lock ./ +# +#RUN composer install \ +# --no-dev \ +# --no-interaction \ +# --no-autoloader \ +# --no-ansi \ +# --no-scripts \ +# --audit COPY --chown=${USER}:${USER} . . +#COPY --chown=${USER}:${USER} --from=build ${ROOT}/public public RUN mkdir -p \ - storage/framework/{sessions,views,cache,testing} \ - storage/logs \ - bootstrap/cache && chmod -R a+rw storage - -COPY --chown=${USER}:${USER} docker/prod/deployment/supervisord.*.conf /etc/supervisor/conf.d/ -COPY --chown=${USER}:${USER} docker/prod/deployment/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini -COPY --chown=${USER}:${USER} docker/prod/deployment/start-container /usr/local/bin/start-container - -RUN cat .env -RUN php artisan env -RUN php artisan storage:link + storage/framework/{sessions,views,cache,testing} \ + storage/logs \ + bootstrap/cache && chmod -R a+rw storage + +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/supervisord.conf /etc/supervisor/ +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/octane/FrankenPHP/supervisord.frankenphp.conf /etc/supervisor/conf.d/ +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/supervisord.*.conf /etc/supervisor/conf.d/ +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/start-container /usr/local/bin/start-container +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini + +# FrankenPHP embedded PHP configuration +COPY --chown=${USER}:${USER} ${DOCKER_FILES_BASE_PATH}deployment/php.ini /lib/php.ini + +#RUN composer install \ +# --classmap-authoritative \ +# --no-interaction \ +# --no-ansi \ +# --no-dev \ +# && composer clear-cache RUN chmod +x /usr/local/bin/start-container -RUN cat docker/prod/deployment/utilities.sh >> ~/.bashrc +RUN cat ${DOCKER_FILES_BASE_PATH}deployment/utilities.sh >> ~/.bashrc EXPOSE 8000 diff --git a/docker/prod/README.md b/docker/prod/README.md deleted file mode 100644 index 0adef933..00000000 --- a/docker/prod/README.md +++ /dev/null @@ -1,128 +0,0 @@ -# Laravel Octane Dockerfile -License -GitHub release (latest by date) -GitHub closed pull requests -GitHub Workflow Status -GitHub Workflow Status -GitHub Workflow Status - - -Production-ready Dockerfiles for [Laravel Octane](https://github.com/laravel/octane) -powered web services and microservices. - -The Docker configuration provides the following setup: - -- PHP 8.2 and 8.3 official Debian-based images -- Preconfigured JIT compiler and OPcache - -## Container modes - -You can run the Docker container in different modes: - -| Mode | `CONTAINER_MODE` | HTTP server | -| --------------------- | ---------------- | ------------------- | -| HTTP Server (default) | `http` | FrankenPHP / Swoole / RoadRunner | -| Horizon | `horizon` | - | -| Scheduler | `scheduler` | - | -| Worker | `worker` | - | - -## Usage - -### Building Docker image -1. Clone this repository: -``` -git clone --depth 1 git@github.com:exaco/laravel-octane-dockerfile.git -``` -2. Copy cloned directory content including `deployment` directory, `Dockerfile`, and `.dockerignore` into your Octane powered Laravel project -3. Change the directory to your Laravel project -4. Build your image: -``` -docker build -t : -f .Dockerfile . -``` -### Running Docker container - -```bash -# HTTP mode -docker run -p :80 --rm : - -# Horizon mode -docker run -e CONTAINER_MODE=horizon --rm : - -# Scheduler mode -docker run -e CONTAINER_MODE=scheduler --rm : - -# HTTP mode with Horizon -docker run -e WITH_HORIZON=true -p :80 --rm : - -# HTTP mode with Scheduler -docker run -e WITH_SCHEDULER=true -p :80 --rm : - -# HTTP mode with Scheduler and Horizon -docker run -e WITH_SCHEDULER=true -e WITH_HORIZON=true -p :80 --rm : - -# Worker mode -docker run -e CONTAINER_MODE=worker -e WORKER_COMMAND="php /var/www/html/artisan foo:bar" --rm : - -# Running a single command -docker run --rm : php artisan about -``` - -## Configuration - -### Recommended `Swoole` options in `octane.php` - -```php -// config/octane.php - -return [ - 'swoole' => [ - 'options' => [ - 'http_compression' => true, - 'http_compression_level' => 6, // 1 - 9 - 'compression_min_length' => 20, - 'package_max_length' => 20 * 1024 * 1024, // 20MB - 'open_http2_protocol' => true, - 'document_root' => public_path(), - 'enable_static_handler' => true, - ] - ] -]; -``` - -## Utilities - -Also, some useful Bash functions and aliases are added in `utilities.sh` that maybe help. - -## Notes - -- Laravel Octane logs request information only in the `local` environment. -- Please be aware of `.dockerignore` content - -## ToDo -- [x] Add support for PHP 8.3 -- [x] Add support for worker mode -- [ ] Build assets with Bun -- [ ] Create standalone and self-executable app -- [x] Add support for Horizon -- [x] Add support for RoadRunner -- [x] Add support for FrankenPHP -- [x] Add support for the full-stack apps (Front-end assets) -- [ ] Add support `testing` environment and CI -- [x] Add support for the Laravel scheduler -- [ ] Add support for Laravel Dusk -- [x] Support more PHP extensions -- [x] Add tests -- [ ] Add Alpine-based images - -## Contributing - -Thank you for considering contributing! If you find an issue, or have a better way to do something, feel free to open an -issue, or a PR. - -## Credits -- [SMortexa](https://github.com/smortexa) -- [All contributors](https://github.com/exaco/laravel-octane-dockerfile/graphs/contributors) - -## License - -This repository is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/docker/prod/deployment/octane/FrankenPHP/supervisord.frankenphp.conf b/docker/prod/deployment/octane/FrankenPHP/supervisord.frankenphp.conf new file mode 100644 index 00000000..fb71df92 --- /dev/null +++ b/docker/prod/deployment/octane/FrankenPHP/supervisord.frankenphp.conf @@ -0,0 +1,51 @@ +[program:octane] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan octane:start --server=frankenphp --host=0.0.0.0 --port=8000 --admin-port=2019 +; command=php %(ENV_ROOT)s/artisan octane:start --server=frankenphp --host=localhost --port=443 --admin-port=2019 --https --http-redirect +user=%(ENV_USER)s +autostart=true +autorestart=true +environment=LARAVEL_OCTANE="1" +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:horizon] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan horizon +user=%(ENV_USER)s +autostart=%(ENV_WITH_HORIZON)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stderr_logfile_maxbytes=200MB +stopwaitsecs=3600 + +[program:scheduler] +process_name=%(program_name)s_%(process_num)02d +command=supercronic -overlapping /etc/supercronic/laravel +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[program:clear-scheduler-cache] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan schedule:clear-cache +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=false +startsecs=0 +startretries=1 +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[include] +files=/etc/supervisor/supervisord.conf diff --git a/docker/prod/deployment/octane/RoadRunner/.rr.prod.yaml b/docker/prod/deployment/octane/RoadRunner/.rr.prod.yaml new file mode 100644 index 00000000..07a4fdbb --- /dev/null +++ b/docker/prod/deployment/octane/RoadRunner/.rr.prod.yaml @@ -0,0 +1,25 @@ +version: '2.7' +rpc: + listen: 'tcp://127.0.0.1:6001' +server: + relay: pipes +http: + middleware: [ "static", "gzip", "headers" ] + max_request_size: 20 + static: + dir: "public" + forbid: [ ".php", ".htaccess" ] + uploads: + forbid: [".php", ".exe", ".bat", ".sh"] + pool: + allocate_timeout: 10s + destroy_timeout: 10s + supervisor: + max_worker_memory: 128 + exec_ttl: 60s +logs: + mode: production + level: debug + encoding: json +status: + address: localhost:2114 diff --git a/docker/prod/deployment/octane/RoadRunner/supervisord.roadrunner.conf b/docker/prod/deployment/octane/RoadRunner/supervisord.roadrunner.conf new file mode 100644 index 00000000..8ffd957f --- /dev/null +++ b/docker/prod/deployment/octane/RoadRunner/supervisord.roadrunner.conf @@ -0,0 +1,50 @@ +[program:octane] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan octane:start --server=roadrunner --host=0.0.0.0 --port=8000 --rpc-port=6001 --rr-config=%(ENV_ROOT)s/.rr.yaml +user=%(ENV_USER)s +autostart=true +autorestart=true +environment=LARAVEL_OCTANE="1" +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:horizon] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan horizon +user=%(ENV_USER)s +autostart=%(ENV_WITH_HORIZON)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stderr_logfile_maxbytes=200MB +stopwaitsecs=3600 + +[program:scheduler] +process_name=%(program_name)s_%(process_num)02d +command=supercronic -overlapping /etc/supercronic/laravel +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[program:clear-scheduler-cache] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan schedule:clear-cache +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=false +startsecs=0 +startretries=1 +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[include] +files=/etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/docker/prod/deployment/octane/Swoole/supervisord.swoole.conf b/docker/prod/deployment/octane/Swoole/supervisord.swoole.conf new file mode 100644 index 00000000..58abdc43 --- /dev/null +++ b/docker/prod/deployment/octane/Swoole/supervisord.swoole.conf @@ -0,0 +1,50 @@ +[program:octane] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan octane:start --server=swoole --host=0.0.0.0 --port=8000 +user=%(ENV_USER)s +autostart=true +autorestart=true +environment=LARAVEL_OCTANE="1" +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:horizon] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan horizon +user=%(ENV_USER)s +autostart=%(ENV_WITH_HORIZON)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/horizon.log +stderr_logfile_maxbytes=200MB +stopwaitsecs=3600 + +[program:scheduler] +process_name=%(program_name)s_%(process_num)02d +command=supercronic -overlapping /etc/supercronic/laravel +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=true +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[program:clear-scheduler-cache] +process_name=%(program_name)s_%(process_num)02d +command=php %(ENV_ROOT)s/artisan schedule:clear-cache +user=%(ENV_USER)s +autostart=%(ENV_WITH_SCHEDULER)s +autorestart=false +startsecs=0 +startretries=1 +stdout_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stdout_logfile_maxbytes=200MB +stderr_logfile=%(ENV_ROOT)s/storage/logs/scheduler.log +stderr_logfile_maxbytes=200MB + +[include] +files=/etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/docker/prod/deployment/php.ini b/docker/prod/deployment/php.ini index 816d9422..f8b7b629 100644 --- a/docker/prod/deployment/php.ini +++ b/docker/prod/deployment/php.ini @@ -4,6 +4,7 @@ upload_max_filesize = 100M expose_php = 0 realpath_cache_size = 16M realpath_cache_ttl = 360 +max_input_time = 5 [Opcache] opcache.enable = 1 diff --git a/docker/prod/deployment/start-container b/docker/prod/deployment/start-container index 2f9ac1c7..d47409dc 100644 --- a/docker/prod/deployment/start-container +++ b/docker/prod/deployment/start-container @@ -1,7 +1,7 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh set -e -container_mode=${CONTAINER_MODE:-http} +container_mode=${CONTAINER_MODE:-"http"} octane_server=${OCTANE_SERVER} auto_db_migrate=${AUTO_DB_MIGRATE:-false} echo "Container mode: $container_mode" @@ -9,7 +9,7 @@ echo "Container mode: $container_mode" initialStuff() { if [ ${auto_db_migrate} = "true" ]; then echo "Auto database migration enabled." - php artisan migrate --force + php artisan migrate --isolated --force fi php artisan optimize:clear; \ php artisan event:cache; \ @@ -22,7 +22,16 @@ if [ "$1" != "" ]; then elif [ ${container_mode} = "http" ]; then echo "Octane Server: $octane_server" initialStuff - exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.swoole.conf + if [ ${octane_server} = "frankenphp" ]; then + exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.frankenphp.conf + elif [ ${octane_server} = "swoole" ]; then + exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.swoole.conf + elif [ ${octane_server} = "roadrunner" ]; then + exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.roadrunner.conf + else + echo "Invalid Octane server supplied." + exit 1 + fi elif [ ${container_mode} = "horizon" ]; then initialStuff exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.horizon.conf diff --git a/docker/prod/deployment/supervisord.conf b/docker/prod/deployment/supervisord.conf new file mode 100644 index 00000000..7cdc8784 --- /dev/null +++ b/docker/prod/deployment/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true +user=%(ENV_USER)s +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +[unix_http_server] +file=/var/run/supervisor.sock + +[supervisorctl] +serverurl=unix:///var/run/supervisor.sock + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface \ No newline at end of file diff --git a/docker/prod/deployment/supervisord.horizon.conf b/docker/prod/deployment/supervisord.horizon.conf index 6d03393b..1ed21de7 100644 --- a/docker/prod/deployment/supervisord.horizon.conf +++ b/docker/prod/deployment/supervisord.horizon.conf @@ -1,9 +1,3 @@ -[supervisord] -nodaemon=true -user=%(ENV_USER)s -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - [program:horizon] process_name=%(program_name)s_%(process_num)02d command=php %(ENV_ROOT)s/artisan horizon @@ -15,3 +9,6 @@ stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 stopwaitsecs=3600 + +[include] +files=/etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/docker/prod/deployment/supervisord.scheduler.conf b/docker/prod/deployment/supervisord.scheduler.conf index fb4b1b25..a2e6825c 100644 --- a/docker/prod/deployment/supervisord.scheduler.conf +++ b/docker/prod/deployment/supervisord.scheduler.conf @@ -1,9 +1,3 @@ -[supervisord] -nodaemon=true -user=%(ENV_USER)s -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - [program:scheduler] process_name=%(program_name)s_%(process_num)02d command=supercronic -overlapping /etc/supercronic/laravel @@ -21,7 +15,12 @@ command=php %(ENV_ROOT)s/artisan schedule:clear-cache user=%(ENV_USER)s autostart=true autorestart=false +startsecs=0 +startretries=1 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 \ No newline at end of file +stderr_logfile_maxbytes=0 + +[include] +files=/etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/docker/prod/deployment/supervisord.worker.conf b/docker/prod/deployment/supervisord.worker.conf index efd760d0..ed420aa7 100644 --- a/docker/prod/deployment/supervisord.worker.conf +++ b/docker/prod/deployment/supervisord.worker.conf @@ -1,9 +1,3 @@ -[supervisord] -nodaemon=true -user=%(ENV_USER)s -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - [program:worker] process_name=%(program_name)s_%(process_num)02d command=%(ENV_WORKER_COMMAND)s @@ -14,3 +8,6 @@ stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 + +[include] +files=/etc/supervisor/supervisord.conf \ No newline at end of file