Skip to content

Commit 4a3301a

Browse files
committed
Merge branch 'feat/auto-rr-binary-updater'
2 parents 2ac7452 + 6f51d00 commit 4a3301a

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

src/Commands/Concerns/InstallsRoadRunnerDependencies.php

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
use Symfony\Component\Process\ExecutableFinder;
1010
use Symfony\Component\Process\PhpExecutableFinder;
1111
use Symfony\Component\Process\Process;
12+
use Throwable;
1213

1314
trait InstallsRoadRunnerDependencies
1415
{
16+
/**
17+
* The minimum required version of the RoadRunner binary.
18+
*
19+
* @var string
20+
*/
21+
protected $requiredVersion = '2.0.4';
22+
1523
/**
1624
* Determine if RoadRunner is installed.
1725
*
@@ -100,23 +108,74 @@ protected function ensureRoadRunnerBinaryIsInstalled(): string
100108
}
101109

102110
if ($this->confirm('Unable to locate RoadRunner binary. Should Octane download the binary for your operating system?', true)) {
103-
tap(new Process(array_filter([
104-
(new PhpExecutableFinder)->find(),
105-
'./vendor/bin/rr',
106-
'get-binary',
107-
'-n',
108-
'--ansi',
109-
]), base_path(), null, null, null))->run(
110-
fn ($type, $buffer) => $this->output->write($buffer)
111+
$this->downloadRoadRunnerBinary();
112+
113+
copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml'));
114+
}
115+
116+
return base_path('rr');
117+
}
118+
119+
/**
120+
* Ensure the RoadRunner binary installed in your project meets Octane requirements.
121+
*
122+
* @param string $roadRunnerBinary
123+
* @return void
124+
*/
125+
protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary)
126+
{
127+
$version = tap(new Process([$roadRunnerBinary, '--version'], base_path()))
128+
->run()
129+
->getOutput();
130+
131+
if (! Str::startsWith($version, 'rr version 2.')) {
132+
return $this->warn(
133+
'Unable to determine the current RoadRunner binary version. Please report this issue: https://github.com/laravel/octane/issues/new.'
111134
);
135+
}
112136

113-
$this->line('');
137+
$version = explode(' ', $version)[2];
114138

115-
chmod(base_path('rr'), 755);
139+
if (version_compare($version, $this->requiredVersion, '<')) {
140+
$this->warn("Your RoadRunner binary version (<fg=red>$version</>) may be incompatible with Octane.");
116141

117-
copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml'));
142+
if ($this->confirm('Should Octane download the latest RoadRunner binary version for your operating system?', true)) {
143+
rename($roadRunnerBinary, "$roadRunnerBinary.backup");
144+
145+
try {
146+
$this->downloadRoadRunnerBinary();
147+
} catch (Throwable $e) {
148+
report($e);
149+
150+
rename("$roadRunnerBinary.backup", $roadRunnerBinary);
151+
152+
return $this->warn('Unable to download RoadRunner binary. The HTTP request exception has been logged.');
153+
}
154+
155+
unlink("$roadRunnerBinary.backup");
156+
}
118157
}
158+
}
119159

120-
return base_path('rr');
160+
/**
161+
* Download the latest version of the RoadRunner binary.
162+
*
163+
* @return void
164+
*/
165+
protected function downloadRoadRunnerBinary()
166+
{
167+
tap(new Process(array_filter([
168+
(new PhpExecutableFinder)->find(),
169+
'./vendor/bin/rr',
170+
'get-binary',
171+
'-n',
172+
'--ansi',
173+
]), base_path(), null, null, null))->mustRun(
174+
fn ($type, $buffer) => $this->output->write($buffer)
175+
);
176+
177+
chmod(base_path('rr'), 755);
178+
179+
$this->line('');
121180
}
122181
}

src/Commands/StartRoadRunnerCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
6363
return 1;
6464
}
6565

66+
$this->ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary);
67+
6668
$this->writeServerStateFile($serverStateFile);
6769

6870
touch(base_path('.rr.yaml'));

0 commit comments

Comments
 (0)