Skip to content

Commit

Permalink
Merge branch 'feat/auto-rr-binary-updater'
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 21, 2021
2 parents 2ac7452 + 6f51d00 commit 4a3301a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
83 changes: 71 additions & 12 deletions src/Commands/Concerns/InstallsRoadRunnerDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Throwable;

trait InstallsRoadRunnerDependencies
{
/**
* The minimum required version of the RoadRunner binary.
*
* @var string
*/
protected $requiredVersion = '2.0.4';

/**
* Determine if RoadRunner is installed.
*
Expand Down Expand Up @@ -100,23 +108,74 @@ protected function ensureRoadRunnerBinaryIsInstalled(): string
}

if ($this->confirm('Unable to locate RoadRunner binary. Should Octane download the binary for your operating system?', true)) {
tap(new Process(array_filter([
(new PhpExecutableFinder)->find(),
'./vendor/bin/rr',
'get-binary',
'-n',
'--ansi',
]), base_path(), null, null, null))->run(
fn ($type, $buffer) => $this->output->write($buffer)
$this->downloadRoadRunnerBinary();

copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml'));
}

return base_path('rr');
}

/**
* Ensure the RoadRunner binary installed in your project meets Octane requirements.
*
* @param string $roadRunnerBinary
* @return void
*/
protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary)
{
$version = tap(new Process([$roadRunnerBinary, '--version'], base_path()))
->run()
->getOutput();

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

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

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

copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml'));
if ($this->confirm('Should Octane download the latest RoadRunner binary version for your operating system?', true)) {
rename($roadRunnerBinary, "$roadRunnerBinary.backup");

try {
$this->downloadRoadRunnerBinary();
} catch (Throwable $e) {
report($e);

rename("$roadRunnerBinary.backup", $roadRunnerBinary);

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

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

return base_path('rr');
/**
* Download the latest version of the RoadRunner binary.
*
* @return void
*/
protected function downloadRoadRunnerBinary()
{
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)
);

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

$this->line('');
}
}
2 changes: 2 additions & 0 deletions src/Commands/StartRoadRunnerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
return 1;
}

$this->ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary);

$this->writeServerStateFile($serverStateFile);

touch(base_path('.rr.yaml'));
Expand Down

0 comments on commit 4a3301a

Please sign in to comment.