Skip to content

Commit 2b42333

Browse files
authored
Merge pull request #35 from msmakouz/short-default-config
Simplify default config
2 parents 36878c8 + 124a6a6 commit 2b42333

7 files changed

Lines changed: 44 additions & 275 deletions

File tree

src/Configuration/Plugins.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,34 @@
44

55
namespace Spiral\RoadRunner\Console\Configuration;
66

7+
use Spiral\RoadRunner\Console\Configuration\Section\Http;
8+
use Spiral\RoadRunner\Console\Configuration\Section\Jobs;
9+
use Spiral\RoadRunner\Console\Configuration\Section\Kv;
10+
use Spiral\RoadRunner\Console\Configuration\Section\Metrics;
11+
use Spiral\RoadRunner\Console\Configuration\Section\Rpc;
712
use Spiral\RoadRunner\Console\Configuration\Section\SectionInterface;
13+
use Spiral\RoadRunner\Console\Configuration\Section\Server;
14+
use Spiral\RoadRunner\Console\Configuration\Section\Version;
815
use Spiral\Tokenizer\ClassLocator;
916
use Symfony\Component\Finder\Finder;
1017

1118
final class Plugins
1219
{
20+
/**
21+
* @psalm-var array<class-string>
22+
*
23+
* Default plugins in a class-string format.
24+
*/
25+
private array $defaultPlugins = [
26+
Version::class,
27+
Rpc::class,
28+
Server::class,
29+
Http::class,
30+
Jobs::class,
31+
Kv::class,
32+
Metrics::class,
33+
];
34+
1335
/**
1436
* @var string[]
1537
*
@@ -51,7 +73,7 @@ public static function fromPreset(string $preset): self
5173
public function getPlugins(): array
5274
{
5375
if ($this->requestedPlugins === []) {
54-
return $this->available;
76+
return $this->defaultPlugins;
5577
}
5678

5779
$plugins = [];

src/Configuration/Section/Http.php

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -12,121 +12,20 @@ public function render(): array
1212
{
1313
return [
1414
self::NAME => [
15-
'address' => '127.0.0.1:8080',
16-
'internal_error_code' => 505,
17-
'access_logs' => false,
18-
'max_request_size' => 256,
15+
'address' => '0.0.0.0:8080',
1916
'middleware' => [
20-
'headers',
21-
'gzip'
22-
],
23-
'trusted_subnets' => [
24-
'10.0.0.0/8',
25-
'127.0.0.0/8',
26-
'172.16.0.0/12',
27-
'192.168.0.0/16',
28-
'::1/128',
29-
'fc00::/7',
30-
'fe80::/10'
31-
],
32-
'new_relic' => [
33-
'app_name' => 'app',
34-
'license_key' => 'key'
35-
],
36-
'cache' => [
37-
'driver' => 'memory',
38-
'cache_methods' => [
39-
'GET',
40-
'HEAD',
41-
'POST'
42-
],
43-
'config' => []
44-
],
45-
'uploads' => [
46-
'dir' => '/tmp',
47-
'forbid' => [
48-
'.php',
49-
'.exe',
50-
'.bat',
51-
'.sh'
52-
],
53-
'allow' => [
54-
'.html',
55-
'.aaa'
56-
]
57-
],
58-
'headers' => [
59-
'cors' => [
60-
'allowed_origin' => '*',
61-
'allowed_headers' => '*',
62-
'allowed_methods' => 'GET,POST,PUT,DELETE',
63-
'allow_credentials' => true,
64-
'exposed_headers' => 'Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma',
65-
'max_age' => 600
66-
],
67-
'request' => [
68-
'input' => 'custom-header',
69-
],
70-
'response' => [
71-
'X-Powered-By' => 'RoadRunner'
72-
]
17+
'gzip',
18+
'static'
7319
],
7420
'static' => [
75-
'dir' => '.',
76-
'forbid' => [''],
77-
'calculate_etag' => false,
78-
'weak' => false,
79-
'allow' => [
80-
'.txt',
81-
'.php'
82-
],
83-
'request' => [
84-
'input' => 'custom-header'
85-
],
86-
'response' => [
87-
'output' => 'output-header'
88-
]
21+
'dir' => 'public',
22+
'forbid' => ['.php', '.htaccess'],
8923
],
9024
'pool' => [
91-
'debug' => false,
92-
'command' => 'php my-super-app.php',
93-
'num_workers' => 0,
94-
'max_jobs' => 64,
95-
'allocate_timeout' => '60s',
96-
'destroy_timeout' => '60s',
25+
'num_workers' => 1,
9726
'supervisor' => [
98-
'watch_tick' => '1s',
99-
'ttl' => '0s',
100-
'idle_ttl' => '10s',
101-
'max_worker_memory' => 128,
102-
'exec_ttl' => '60s'
27+
'max_worker_memory' => 100
10328
]
104-
],
105-
'ssl' => [
106-
'address' => '127.0.0.1:443',
107-
'acme' => [
108-
'certs_dir' => 'rr_le_certs',
109-
'email' => 'you-email-here@email',
110-
'alt_http_port' => 80,
111-
'alt_tlsalpn_port' => 443,
112-
'challenge_type' => 'http-01',
113-
'use_production_endpoint' => true,
114-
'domains' => [
115-
'your-cool-domain.here',
116-
'your-second-domain.here'
117-
]
118-
],
119-
'redirect' => true,
120-
'cert' => '/ssl/server.crt',
121-
'key' => '/ssl/server.key',
122-
'root_ca' => '/ssl/root.crt'
123-
],
124-
'fcgi' => [
125-
'address' => 'tcp://0.0.0.0:7921'
126-
],
127-
'http2' => [
128-
'h2c' => false,
129-
'max_concurrent_streams' => 128
13029
]
13130
]
13231
];

src/Configuration/Section/Jobs.php

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,98 +12,11 @@ public function render(): array
1212
{
1313
return [
1414
self::NAME => [
15-
'num_pollers' => 32,
16-
'pipeline_size' => 100000,
1715
'pool' => [
18-
'command' => '',
19-
'num_workers' => 10,
20-
'max_jobs' => 0,
21-
'allocate_timeout' => '60s',
22-
'destroy_timeout' => '60s'
16+
'num_workers' => 2,
17+
'max_worker_memory' => 100
2318
],
24-
'pipelines' => [
25-
'test-local' => [
26-
'driver' => 'memory',
27-
'config' => [
28-
'priority' => 10,
29-
'prefetch' => 10000
30-
]
31-
],
32-
'test-local-1' => [
33-
'driver' => 'boltdb',
34-
'config' => [
35-
'file' => 'path/to/rr.db',
36-
'priority' => 10,
37-
'prefetch' => 10000
38-
]
39-
],
40-
'test-local-2' => [
41-
'driver' => 'amqp',
42-
'config' => [
43-
'prefetch' => 10,
44-
'priority' => 1,
45-
'durable' => false,
46-
'delete_queue_on_stop' => false,
47-
'queue' => 'test-1-queue',
48-
'exchange' => 'default',
49-
'exchange_type' => 'direct',
50-
'routing_key' => 'test',
51-
'exclusive' => false,
52-
'multiple_ack' => false,
53-
'requeue_on_fail' => false
54-
]
55-
],
56-
'test-local-3' => [
57-
'driver' => 'beanstalk',
58-
'config' => [
59-
'priority' => 11,
60-
'tube_priority' => 1,
61-
'tube' => 'default-1',
62-
'reserve_timeout' => '10s'
63-
]
64-
],
65-
'test-local-4' => [
66-
'driver' => 'sqs',
67-
'config' => [
68-
'priority' => 10,
69-
'prefetch' => 10,
70-
'visibility_timeout' => 0,
71-
'wait_time_seconds' => 0,
72-
'queue' => 'default',
73-
'attributes' => [
74-
'DelaySeconds' => 0,
75-
'MaximumMessageSize' => 262144,
76-
'MessageRetentionPeriod' => 345600,
77-
'ReceiveMessageWaitTimeSeconds' => 0,
78-
'VisibilityTimeout' => 30
79-
],
80-
'tags' => [
81-
'test' => 'tag'
82-
]
83-
]
84-
],
85-
'test-local-5' => [
86-
'driver' => 'nats',
87-
'config' => [
88-
'priority' => 2,
89-
'prefetch' => 100,
90-
'subject' => 'default',
91-
'stream' => 'foo',
92-
'deliver_new' => true,
93-
'rate_limit' => 100,
94-
'delete_stream_on_stop' => false,
95-
'delete_after_ack' => false
96-
]
97-
]
98-
],
99-
'consume' => [
100-
'test-local',
101-
'test-local-1',
102-
'test-local-2',
103-
'test-local-3',
104-
'test-local-4',
105-
'test-local-5'
106-
]
19+
'consume' => []
10720
]
10821
];
10922
}

src/Configuration/Section/Kv.php

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,18 @@ public function render(): array
1212
{
1313
return [
1414
self::NAME => [
15-
'boltdb-south' => [
16-
'driver' => 'boltdb',
17-
'config' => [
18-
'file' => 'rr.db',
19-
'permissions' => 0777,
20-
'interval' => 40
21-
]
22-
],
23-
'us-central-kv' => [
24-
'driver' => 'memcached',
15+
'local' => [
16+
'driver' => 'memory',
2517
'config' => [
26-
'addr' => [
27-
'localhost:11211'
28-
]
18+
'interval' => 60
2919
]
3020
],
31-
'fast-kv-fr' => [
21+
'redis' => [
3222
'driver' => 'redis',
3323
'config' => [
3424
'addrs' => [
3525
'localhost:6379'
36-
],
37-
'master_name' => '',
38-
'username' => '',
39-
'password' => '',
40-
'db' => 0,
41-
'sentinel_password' => '',
42-
'route_by_latency' => false,
43-
'route_randomly' => false,
44-
'dial_timeout' => 0,
45-
'max_retries' => 1,
46-
'min_retry_backoff' => 0,
47-
'max_retry_backoff' => 0,
48-
'pool_size' => 0,
49-
'min_idle_conns' => 0,
50-
'max_conn_age' => 0,
51-
'read_timeout' => 0,
52-
'write_timeout' => 0,
53-
'pool_timeout' => 0,
54-
'idle_timeout' => 0,
55-
'idle_check_freq' => 0,
56-
'read_only' => false
57-
]
58-
],
59-
'local-memory' => [
60-
'driver' => 'memory',
61-
'config' => [
62-
'interval' => 1
26+
]
6327
]
6428
]
6529
]

src/Configuration/Section/Metrics.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,7 @@ public function render(): array
1212
{
1313
return [
1414
self::NAME => [
15-
'address' => '127.0.0.1:2112',
16-
'collect' => [
17-
'app_metric' => [
18-
'type' => 'histogram',
19-
'help' => 'Custom application metric',
20-
'labels' => [
21-
'type'
22-
],
23-
'buckets' => [
24-
0.1,
25-
0.2,
26-
0.3,
27-
1.0
28-
],
29-
'objectives' => [
30-
[
31-
'1.4' => 2.3
32-
],
33-
[
34-
'2.0' => 1.4
35-
]
36-
]
37-
]
38-
]
15+
'address' => 'localhost:2112'
3916
]
4017
];
4118
}

src/Configuration/Section/Server.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ public function render(): array
1212
{
1313
return [
1414
self::NAME => [
15-
'on_init' => [
16-
'command' => 'any php or script here',
17-
'exec_timeout' => '20s',
18-
],
19-
'command' => 'php psr-worker.php',
20-
'user' => '',
21-
'group' => '',
22-
'relay' => 'pipes',
23-
'relay_timeout' => '60s'
15+
'command' => 'php app.php',
16+
'relay' => 'pipes'
2417
]
2518
];
2619
}

src/DownloadProtocBinaryCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ private function findAsset(
167167

168168
foreach ($filtered as $release) {
169169
$asset = $release->getAssets()
170-
->filter(static fn (AssetInterface $asset): bool =>
171-
0 === \strncmp($asset->getName(), 'protoc-gen-php-grpc', \strlen('protoc-gen-php-grpc'))
170+
->filter(
171+
static fn (AssetInterface $asset): bool =>
172+
\str_starts_with($asset->getName(), 'protoc-gen-php-grpc')
172173
)
173174
->whereArchitecture($archOption)
174175
->whereOperatingSystem($osOption)

0 commit comments

Comments
 (0)