Skip to content

Commit

Permalink
[2.x] Adds support for RoadRunner v3 and updates dependencies (#690)
Browse files Browse the repository at this point in the history
* support roadrunner http v3

* Update InstallsRoadRunnerDependencies.php

* Update InstallsRoadRunnerDependencies.php

* Uses Roadrunner v3 only

* Bump dependencies

* Adjusts coding style

* Migrates to PHPUnit 10

* Adds upgrade guide

* Ui improvements

* Updates upgrade guide

* Updates list of dependencies

* Adds pint

* Ensures latest versions of dependencies

* Updates upgrade guide

* Updates build file

* Fixes tests

* Updates upgrade guide

* Updates upgrade guide

* Update upgrade guide

* Update UPGRADE.md

---------

Co-authored-by: Fabio Capucci <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored May 3, 2023
1 parent 215b471 commit 09dadee
Show file tree
Hide file tree
Showing 106 changed files with 110 additions and 469 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: fix code styling

on: [push]

jobs:
lint:
uses: laravel/.github/.github/workflows/coding-standards.yml@main
11 changes: 3 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['8.0', 8.1, 8.2]
laravel: [8, 9, 10]
php: [8.1, 8.2]
laravel: [10]
driver: [swoole, openswoole]
exclude:
- php: 8.0
laravel: 10
- php: 8.2
laravel: 8

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.driver }}

Expand All @@ -50,4 +45,4 @@ jobs:
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
29 changes: 29 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Upgrade Guide

## Upgrading To 3.0 From 2.x

### Minimum Versions

The following requirements have been updated:

- The minimum PHP version is now `v8.1.0`
- The minimum Laravel version is now `v10.9.0`

### Updating Dependencies

You should update the following dependency in your application's `composer.json` file:

```diff
- "laravel/octane": "^1.5",
+ "laravel/octane": "^2.0",
```

If you are using RoadRunner, you should update the corresponding dependency in your application's `composer.json` file:

```diff
- "spiral/roadrunner": "^2.8.2",
+ "spiral/roadrunner-http": "^3.0.1",
+ "spiral/roadrunner-cli": "^2.5.0",
```

In production, you should "stop" your Octane workers prior to updating your dependencies. After updating, you may restart your workers.
9 changes: 9 additions & 0 deletions bin/WorkerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
class WorkerState
{
public $server;

public $workerId;

public $workerPid;

public $worker;

public $client;

public $timerTable;

public $cacheTable;

public $tables = [];

public $tickTimerId;

public $lastRequestTime;
}
40 changes: 23 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,36 @@
}
],
"require": {
"php": "^8.0",
"laravel/framework": "^8.83.26|^9.38.0|^10.0",
"laminas/laminas-diactoros": "^2.5",
"laravel/serializable-closure": "^1.0",
"nesbot/carbon": "^2.60",
"symfony/psr-http-message-bridge": "^2.0"
"php": "^8.1.0",
"laravel/framework": "^10.9.0",
"laminas/laminas-diactoros": "^2.25.2",
"laravel/serializable-closure": "^1.3.0",
"nesbot/carbon": "^2.66.0",
"symfony/psr-http-message-bridge": "^2.2.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
"guzzlehttp/guzzle": "^7.5.1",
"inertiajs/inertia-laravel": "^0.6.9",
"laravel/scout": "^9.8",
"laravel/socialite": "^5.6",
"livewire/livewire": "^2.12",
"mockery/mockery": "^1.4",
"nunomaduro/collision": "^5.10|^6.0|^7.0",
"orchestra/testbench": "^6.16|^7.0|^8.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.3",
"spiral/roadrunner": "^2.8.2"
"laravel/scout": "^10.1.1",
"laravel/socialite": "^5.6.1",
"livewire/livewire": "^2.12.3",
"mockery/mockery": "^1.5.1",
"nunomaduro/collision": "^6.4.0|^7.5.2",
"orchestra/testbench": "^8.5.1",
"phpstan/phpstan": "^1.10.14",
"phpunit/phpunit": "^10.0.0",
"spiral/roadrunner-http": "^3.0.1",
"spiral/roadrunner-cli": "^2.5.0"
},
"bin": [
"bin/roadrunner-worker",
"bin/swoole-server"
],
"conflict": {
"spiral/roadrunner": "<2023.1.0",
"spiral/roadrunner-cli": "<2.5.0",
"spiral/roadrunner-http": "<3.0.1"
},
"autoload": {
"psr-4": {
"Laravel\\Octane\\": "src"
Expand Down Expand Up @@ -69,6 +75,6 @@
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true
}
12 changes: 1 addition & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<phpunit colors="true">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests</directory>
Expand Down
19 changes: 0 additions & 19 deletions src/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public function __construct(protected string $basePath)

/**
* Create a new application instance.
*
* @param array $initialInstances
* @return \Illuminate\Foundation\Application
*/
public function createApplication(array $initialInstances = []): Application
{
Expand All @@ -39,10 +36,6 @@ public function createApplication(array $initialInstances = []): Application

/**
* Bootstrap the given application.
*
* @param \Illuminate\Foundation\Application $app
* @param array $initialInstances
* @return \Illuminate\Foundation\Application
*/
public function bootstrap(Application $app, array $initialInstances = []): Application
{
Expand All @@ -59,9 +52,6 @@ public function bootstrap(Application $app, array $initialInstances = []): Appli

/**
* Get the application's HTTP kernel bootstrappers.
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getBootstrappers(Application $app): array
{
Expand All @@ -80,11 +70,6 @@ protected function getBootstrappers(Application $app): array

/**
* Inject a given bootstrapper before another bootstrapper.
*
* @param string $before
* @param string $inject
* @param array $bootstrappers
* @return array
*/
protected function injectBootstrapperBefore(string $before, string $inject, array $bootstrappers): array
{
Expand All @@ -99,10 +84,6 @@ protected function injectBootstrapperBefore(string $before, string $inject, arra

/**
* Warm the application with pre-resolved, cached services that persist across requests.
*
* @param \Illuminate\Foundation\Application $app
* @param array $services
* @return \Illuminate\Foundation\Application
*/
public function warm(Application $app, array $services = []): Application
{
Expand Down
7 changes: 0 additions & 7 deletions src/ApplicationGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public function __construct(protected Application $app, protected Application $s

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request): Response
{
Expand All @@ -41,10 +38,6 @@ public function handle(Request $request): Response

/**
* "Shut down" the application after a request.
*
* @param \Illuminate\Http\Request $request
* @param \Symfony\Component\HttpFoundation\Response $response
* @return void
*/
public function terminate(Request $request, Response $response): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Cache/OctaneArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class OctaneArrayStore extends ArrayStore
* Register a cache key that should be refreshed at a given interval (in minutes).
*
* @param string $key
* @param \Closure $resolver
* @param int $seconds
* @return mixed
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Cache/OctaneStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected function getInterval($key)
*
* Items not found in the cache will have a null value.
*
* @param array $keys
* @return array
*/
public function many(array $keys)
Expand All @@ -94,7 +93,6 @@ public function put($key, $value, $seconds)
/**
* Store multiple items in the cache for a given number of seconds.
*
* @param array $values
* @param int $seconds
* @return bool
*/
Expand Down Expand Up @@ -155,7 +153,6 @@ public function forever($key, $value)
* Register a cache key that should be refreshed at a given interval (in minutes).
*
* @param string $key
* @param \Closure $resolver
* @param int $seconds
* @return void
*/
Expand Down Expand Up @@ -203,7 +200,6 @@ public function refreshIntervalCaches()
/**
* Determine if the given interval record should be refreshed.
*
* @param array $interval
* @return bool
*/
protected function intervalShouldBeRefreshed(array $interval)
Expand Down
50 changes: 28 additions & 22 deletions src/Commands/Concerns/InstallsRoadRunnerDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait InstallsRoadRunnerDependencies
*
* @var string
*/
protected $requiredVersion = '2.8.2';
protected $requiredVersion = '2023.1.1';

/**
* Determine if RoadRunner is installed.
Expand All @@ -44,13 +44,13 @@ protected function ensureRoadRunnerPackageIsInstalled()
return true;
}

if (! $this->confirm('Octane requires "spiral/roadrunner:^2.8.2". Do you wish to install it as a dependency?')) {
$this->error('Octane requires "spiral/roadrunner".');
if (! $this->confirm('Octane requires "spiral/roadrunner-http:^3.0.1" and "spiral/roadrunner-cli:^2.5.0". Do you wish to install them as a dependencies?')) {
$this->error('Octane requires "spiral/roadrunner-http" and "spiral/roadrunner-cli".');

return false;
}

$command = $this->findComposer().' require spiral/roadrunner:^2.8.2 --with-all-dependencies';
$command = $this->findComposer().' require spiral/roadrunner-http:^3.0.1 spiral/roadrunner-cli:^2.5.0 --with-all-dependencies';

$process = Process::fromShellCommandline($command, null, null, null, null);

Expand Down Expand Up @@ -95,8 +95,6 @@ protected function findComposer()

/**
* Ensure the RoadRunner binary is installed into the project.
*
* @return string
*/
protected function ensureRoadRunnerBinaryIsInstalled(): string
{
Expand Down Expand Up @@ -125,32 +123,34 @@ protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary)
->run()
->getOutput();

if (! Str::startsWith($version, 'rr version 2.')) {
if (! Str::startsWith($version, 'rr version')) {
return $this->warn(
'Unable to determine the current RoadRunner binary version. Please report this issue: https://github.com/laravel/octane/issues/new.'
);
}

$version = explode(' ', $version)[2];

if (version_compare($version, $this->requiredVersion, '<')) {
$this->warn("Your RoadRunner binary version (<fg=red>$version</>) may be incompatible with Octane.");
if (version_compare($version, $this->requiredVersion, '>=')) {
return;
}

if ($this->confirm('Should Octane download the latest RoadRunner binary version for your operating system?', true)) {
rename($roadRunnerBinary, "$roadRunnerBinary.backup");
$this->warn("Your RoadRunner binary version (<fg=red>$version</>) may be incompatible with Octane.");

try {
$this->downloadRoadRunnerBinary();
} catch (Throwable $e) {
report($e);
if ($this->confirm('Should Octane download the latest RoadRunner binary version for your operating system?', true)) {
rename($roadRunnerBinary, "$roadRunnerBinary.backup");

rename("$roadRunnerBinary.backup", $roadRunnerBinary);
try {
$this->downloadRoadRunnerBinary();
} catch (Throwable $e) {
report($e);

return $this->warn('Unable to download RoadRunner binary. The HTTP request exception has been logged.');
}
rename("$roadRunnerBinary.backup", $roadRunnerBinary);

unlink("$roadRunnerBinary.backup");
return $this->warn('Unable to download RoadRunner binary. The HTTP request exception has been logged.');
}

unlink("$roadRunnerBinary.backup");
}
}

Expand All @@ -161,15 +161,21 @@ protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary)
*/
protected function downloadRoadRunnerBinary()
{
$installed = false;

tap(new Process(array_filter([
(new PhpExecutableFinder)->find(),
'./vendor/bin/rr',
'get-binary',
'-n',
'--ansi',
]), base_path(), null, null, null))->mustRun(
fn ($type, $buffer) => $this->output->write($buffer)
);
]), base_path(), null, null, null))->mustRun(function (string $type, string $buffer) use (&$installed) {
if (! $installed) {
$this->output->write($buffer);

$installed = str_contains($buffer, 'has been installed into');
}
});

chmod(base_path('rr'), 0755);

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Concerns/InteractsWithIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function raw($string)
*/
public function info($string, $verbosity = null)
{
$this->label($string, $verbosity, 'INFO', 'cyan', 'black');
$this->label($string, $verbosity, 'INFO', 'blue', 'white');
}

/**
Expand Down
Loading

0 comments on commit 09dadee

Please sign in to comment.