diff --git a/.rr.local.unix.yaml b/.rr.local.unix.yaml index ad262e6..4bb0a29 100644 --- a/.rr.local.unix.yaml +++ b/.rr.local.unix.yaml @@ -21,9 +21,9 @@ server: # Worker starting command, with any required arguments. # # This option is required. - command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr/rr-relay.sock" + command: "php -dxdebug.start_with_request=trigger -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 -didekey=PHPSTORM ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr/rr-relay.sock" env: - - scout_driver: typesense + - XDEBUG_SESSION: "1" ## Environment variables for the worker processes. ## @@ -104,6 +104,7 @@ http: # Workers pool settings. pool: + debug: true # How many worker processes will be started. Zero (or nothing) means the number of logical CPUs. # # Default: 0 @@ -138,28 +139,6 @@ http: # Default: 0s exec_ttl: 60s - # SSL (Secure Sockets Layer) settings (docs: https://roadrunner.dev/docs/http-https). - # ssl: - # # Host and port to listen on (eg.: `127.0.0.1:443`). - # # - # # Default: ":443" - # address: 0.0.0.0:8443 - # - # # Automatic redirect from http:// to https:// schema. - # # - # # Default: false - # redirect: false - # - # # Path to the cert file. This option is required for SSL working. - # # - # # This option is required. - # cert: /etc/ssl/certs/selfsigned.crt - # - # # Path to the cert key file. - # # - # # This option is required. - # key: /etc/ssl/private/selfsigned.key - # HTTP/2 settings. http2: # HTTP/2 over non-encrypted TCP connection using H2C. @@ -189,7 +168,7 @@ status: # "rpc" are active (connected) plugins. # # This option is required. - address: 127.0.0.1:8082 + address: 127.0.0.1:2114 # Response status code if a requested plugin not ready to handle requests # Valid for both /health and /ready endpoints diff --git a/.rr.local.yaml b/.rr.local.yaml index f0b67df..90d4523 100644 --- a/.rr.local.yaml +++ b/.rr.local.yaml @@ -21,9 +21,9 @@ server: # Worker starting command, with any required arguments. # # This option is required. - command: "php ./vendor/bin/rr-worker start" + command: "php -dxdebug.start_with_request=trigger -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 -didekey=PHPSTORM ./vendor/bin/rr-worker start" env: - - scout_driver: typesense + - XDEBUG_SESSION: "1" ## Environment variables for the worker processes. ## @@ -104,6 +104,7 @@ http: # Workers pool settings. pool: + debug: true # How many worker processes will be started. Zero (or nothing) means the number of logical CPUs. # # Default: 0 @@ -138,28 +139,6 @@ http: # Default: 0s exec_ttl: 60s - # SSL (Secure Sockets Layer) settings (docs: https://roadrunner.dev/docs/http-https). -# ssl: -# # Host and port to listen on (eg.: `127.0.0.1:443`). -# # -# # Default: ":443" -# address: 0.0.0.0:8443 -# -# # Automatic redirect from http:// to https:// schema. -# # -# # Default: false -# redirect: false -# -# # Path to the cert file. This option is required for SSL working. -# # -# # This option is required. -# cert: /etc/ssl/certs/selfsigned.crt -# -# # Path to the cert key file. -# # -# # This option is required. -# key: /etc/ssl/private/selfsigned.key - # HTTP/2 settings. http2: # HTTP/2 over non-encrypted TCP connection using H2C. @@ -189,7 +168,7 @@ status: # "rpc" are active (connected) plugins. # # This option is required. - address: 127.0.0.1:8082 + address: 127.0.0.1:2114 # Response status code if a requested plugin not ready to handle requests # Valid for both /health and /ready endpoints diff --git a/.rr.yaml b/.rr.yaml index 0d09fa8..a95ed8f 100644 --- a/.rr.yaml +++ b/.rr.yaml @@ -1,7 +1,8 @@ -Production usage guide: https://roadrunner.dev/docs/beep-beep-production +# Production usage guide: https://roadrunner.dev/docs/beep-beep-production # Hint: RR will replace any config options using reference to environment variables, # eg.: `option_key: ${ENVIRONMENT_VARIABLE_NAME}`. +# Please note that this config is used within the docker container. # RR configuration version version: "2.7" @@ -51,7 +52,7 @@ logs: # Logging level can be "panic", "error", "warning", "info", "debug". # # Default: "debug" - level: debug + level: info # Encoding format can be "console" or "json" (last is preferred for production usage). # @@ -65,6 +66,11 @@ http: # This option is required. address: 0.0.0.0:8080 + # HTTP access logs + # + # Default: false + access_logs: true + # Maximal incoming request size in megabytes. Zero means no limit. # # Default: 0 @@ -100,7 +106,7 @@ http: # Path to the directory with static assets. # # This option is required. - dir: "/app/public" + dir: "./public" # File extensions to forbid. # @@ -149,28 +155,6 @@ http: # Default: 0s exec_ttl: 60s - # SSL (Secure Sockets Layer) settings (docs: https://roadrunner.dev/docs/http-https). - ssl: - # Host and port to listen on (eg.: `127.0.0.1:443`). - # - # Default: ":443" - address: 0.0.0.0:8443 - - # Automatic redirect from http:// to https:// schema. - # - # Default: false - redirect: false - - # Path to the cert file. This option is required for SSL working. - # - # This option is required. - cert: /etc/ssl/certs/selfsigned.crt - - # Path to the cert key file. - # - # This option is required. - key: /etc/ssl/private/selfsigned.key - # HTTP/2 settings. http2: # HTTP/2 over non-encrypted TCP connection using H2C. @@ -200,7 +184,7 @@ status: # "rpc" are active (connected) plugins. # # This option is required. - address: 127.0.0.1:8082 + address: 127.0.0.1:2114 # Response status code if a requested plugin not ready to handle requests # Valid for both /health and /ready endpoints @@ -208,6 +192,12 @@ status: # Default: 503 unavailable_status_code: 503 +service: + laravel_queue_worker_1: + command: "php /app/artisan queue:work --queue=high,low" + process_num: 1 + restart_sec: 5 + # RoadRunner internal container configuration (docs: https://github.com/spiral/endure). endure: # Logging level. Possible values: "debug", "info", "warning", "error", "panic", "fatal". diff --git a/Dockerfile b/Dockerfile index 07af37a..4e036e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,5 +55,10 @@ RUN set -ex \ && chmod -R a+w storage/ \ && chown -R jikanapi:jikanapi /app +EXPOSE 8080 +EXPOSE 2114 + +HEALTHCHECK CMD curl --fail http://localhost:2114/health?plugin=http || exit 1 + # unset default image entrypoint. -ENTRYPOINT [] +ENTRYPOINT ["/app/docker-entrypoint.sh"] diff --git a/app/Listeners/PsrWorkerBeforeRequestHandlingListener.php b/app/Listeners/PsrWorkerBeforeRequestHandlingListener.php deleted file mode 100644 index 6e6a42b..0000000 --- a/app/Listeners/PsrWorkerBeforeRequestHandlingListener.php +++ /dev/null @@ -1,37 +0,0 @@ -application(); - - $serviceProviderClass = ""; - - if (env("SCOUT_DRIVER") === "typesense") { - $serviceProviderClass = \Typesense\LaravelTypesense\TypesenseServiceProvider::class; - } - - if (env("SCOUT_DRIVER") === "Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine") { - $serviceProviderClass = \Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class; - } - - if ($serviceProviderClass !== "") { - $provider = new $serviceProviderClass($app); - - $provider->register(); - - if (\method_exists($provider, $boot_method = 'boot')) { - $app->call([$provider, $boot_method]); - } - } - } - } -} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 79c65a6..c1461c6 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -175,6 +175,7 @@ class AppServiceProvider extends ServiceProvider TopAnimeQueryBuilder::class, TopMangaQueryBuilder::class ]; + if (env("SCOUT_DRIVER") === "typesense") { $services[] = Typesense::class; } diff --git a/composer.json b/composer.json index 826493f..0031613 100755 --- a/composer.json +++ b/composer.json @@ -28,14 +28,15 @@ "laravel/scout": "^9.4", "league/flysystem": "^3.0", "matchish/laravel-scout-elasticsearch": "^6.0", + "mirazmac/dotenvwriter": "^0.1.0", "ocramius/package-versions": "^2.5", "predis/predis": "^1.1", + "pushrbx/lumen-roadrunner": "dev-master", "sentry/sentry-laravel": "^2.8", "symfony/yaml": "^4.1", "typesense/laravel-scout-typesense-driver": "^5.0", "vlucas/phpdotenv": "^5", - "zircote/swagger-php": "3.*", - "pushrbx/lumen-roadrunner": "dev-master" + "zircote/swagger-php": "3.*" }, "require-dev": { "mockery/mockery": "^1.3.1", diff --git a/config/roadrunner.php b/config/roadrunner.php index 00078c0..2873bac 100644 --- a/config/roadrunner.php +++ b/config/roadrunner.php @@ -41,8 +41,7 @@ return [ Events\BeforeRequestHandlingEvent::class => [ ...Defaults::beforeRequestHandling(), - Listeners\InjectStatsIntoRequestListener::class, - \App\Listeners\PsrWorkerBeforeRequestHandlingListener::class + Listeners\InjectStatsIntoRequestListener::class ], Events\AfterRequestHandlingEvent::class => [ @@ -82,7 +81,7 @@ return [ 'warm' => [ ...Defaults::servicesToWarm(), - ...\App\Providers\AppServiceProvider::servicesToWarm(), + ...\App\Providers\AppServiceProvider::servicesToWarm() ], 'clear' => [ diff --git a/docker-entrypoint.php b/docker-entrypoint.php new file mode 100755 index 0000000..b2872dc --- /dev/null +++ b/docker-entrypoint.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php + "null", + "SCOUT_QUEUE" => false, + "THROTTLE" => false, + "QUEUE_CONNECTION" => "database", + "DB_CACHING" => true, + "DB_HOST" => "localhost", + "DB_PORT" => 27017, + "DB_DATABASE" => "jikan", + "DB_USERNAME" => "", + "DB_PASSWORD" => "" +]; + +if (!file_exists(".env")) { + copy(".env.dist", ".env"); + $writer = new \MirazMac\DotEnv\Writer(__DIR__ . '/' . '.env'); + + foreach ($safe_defaults as $env_var_name => $env_var_default) { + $writer->set("SCOUT_DRIVER", env($env_var_name, $env_var_default)); + } + $writer->write(); +} + +$dotenv = Dotenv::create( + Env::getRepository(), + __DIR__ +); +$current_env = $dotenv->load(); + +if ($current_env["SCOUT_DRIVER"] === "typesense" && empty($current_env["TYPESENSE_API_KEY"])) { + echo "Please set the TYPESENSE_API_KEY environment variable when setting SCOUT_DRIVER to typesense."; + exit(1); +} + +$rrConfig = \Symfony\Component\Yaml\Yaml::parse(file_get_contents(".rr.yaml")); +$rrConfig["http"]["pool"]["supervisor"]["max_worker_memory"] = (int) env("RR_MAX_WORKER_MEMORY", 128); +$rrConfig["http"]["max_request_size"] = (int) env("RR_MAX_REQUEST_SIZE_MB", 256); +file_put_contents(".rr.yaml", \Symfony\Component\Yaml\Yaml::dump($rrConfig, 8)); diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..9e1598d --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eo pipefail + +if [[ $# -eq 0 ]] ; then + exec php /app/docker-entrypoint.php +else + exec php /app/docker-entrypoint.php "$@" +fi + +exec rr serve -c .rr.yaml