mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
added docker entrypoint and healthchecks, fixed psr worker warmup
This commit is contained in:
parent
fa36c6eebf
commit
49faaf0a2f
@ -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
|
||||
|
@ -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
|
||||
|
42
.rr.yaml
42
.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".
|
||||
|
@ -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"]
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use pushrbx\LumenRoadRunner\Events\Contracts\WithApplication;
|
||||
use pushrbx\LumenRoadRunner\Listeners\ListenerInterface;
|
||||
|
||||
class PsrWorkerBeforeRequestHandlingListener implements ListenerInterface
|
||||
{
|
||||
|
||||
public function handle($event): void
|
||||
{
|
||||
if ($event instanceof WithApplication) {
|
||||
$app = $event->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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -175,6 +175,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
TopAnimeQueryBuilder::class,
|
||||
TopMangaQueryBuilder::class
|
||||
];
|
||||
|
||||
if (env("SCOUT_DRIVER") === "typesense") {
|
||||
$services[] = Typesense::class;
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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' => [
|
||||
|
47
docker-entrypoint.php
Executable file
47
docker-entrypoint.php
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Illuminate\Support\Env;
|
||||
|
||||
require_once __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$safe_defaults = [
|
||||
// mongodb regex search by default
|
||||
"SCOUT_DRIVER" => "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));
|
10
docker-entrypoint.sh
Executable file
10
docker-entrypoint.sh
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user