Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/Console/Server/ServerInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected function configure(): void
parent::configure();

$this->addOption('server', null, InputOption::VALUE_REQUIRED, 'Server name');
$this->addOption('php-version', null, InputOption::VALUE_REQUIRED, 'PHP version to install');
$this->addOption('php-default', null, InputOption::VALUE_NONE, 'Set as default PHP version');
}

// ----
Expand Down Expand Up @@ -99,6 +101,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->yay('Server installed successfully');

//
// Install PHP
// ----

$phpResult = $this->installPhp($server, $info);

if (is_int($phpResult)) {
return $phpResult;
}

/** @var array{status: int, php_version: string, php_default: bool} $phpResult */
$phpVersion = $phpResult['php_version'];
$phpDefault = $phpResult['php_default'];

//
// Setup demo site
// ----
Expand Down Expand Up @@ -152,6 +168,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->showCommandReplay('server:install', [
'server' => $server->name,
'php-version' => $phpVersion,
'php-default' => $phpDefault,
]);

return Command::SUCCESS;
Expand Down
97 changes: 97 additions & 0 deletions app/Console/Server/ServerInstallPhpCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace Bigpixelrocket\DeployerPHP\Console\Server;

use Bigpixelrocket\DeployerPHP\Contracts\BaseCommand;
use Bigpixelrocket\DeployerPHP\Traits\PlaybooksTrait;
use Bigpixelrocket\DeployerPHP\Traits\ServersTrait;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'server:install:php',
description: 'Install PHP on a server'
)]
class ServerInstallPhpCommand extends BaseCommand
{
use PlaybooksTrait;
use ServersTrait;

// ----
// Configuration
// ----

protected function configure(): void
{
parent::configure();

$this->addOption('server', null, InputOption::VALUE_REQUIRED, 'Server name');
$this->addOption('php-version', null, InputOption::VALUE_REQUIRED, 'PHP version to install');
$this->addOption('php-default', null, InputOption::VALUE_NONE, 'Set as default PHP version');
}

// ----
// Execution
// ----

protected function execute(InputInterface $input, OutputInterface $output): int
{
parent::execute($input, $output);

$this->heading('Install PHP');

//
// Select server & display details
// ----

$server = $this->selectServer();

if (is_int($server)) {
return $server;
}

$this->displayServerDeets($server);

//
// Get server info (verifies SSH connection and validates distribution & permissions)
// ----

$info = $this->getServerInfo($server);

if (is_int($info)) {
return $info;
}

//
// Install PHP
// ----

$phpResult = $this->installPhp($server, $info);

if (is_int($phpResult)) {
return $phpResult;
}

/** @var array{status: int, php_version: string, php_default: bool} $phpResult */
$phpVersion = $phpResult['php_version'];
$phpDefault = $phpResult['php_default'];

//
// Show command replay
// ----

$this->showCommandReplay('server:install:php', [
'server' => $server->name,
'php-version' => $phpVersion,
'php-default' => $phpDefault,
]);

return Command::SUCCESS;
}

}
2 changes: 2 additions & 0 deletions app/SymfonyApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Bigpixelrocket\DeployerPHP\Console\Server\ServerDeleteCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerInfoCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerInstallCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerInstallPhpCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerListCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerLogsCommand;
use Bigpixelrocket\DeployerPHP\Console\Server\ServerProvisionDigitalOceanCommand;
Expand Down Expand Up @@ -144,6 +145,7 @@ private function registerCommands(): void
ServerListCommand::class,
ServerInfoCommand::class,
ServerInstallCommand::class,
ServerInstallPhpCommand::class,
ServerLogsCommand::class,
ServerRunCommand::class,

Expand Down
7 changes: 7 additions & 0 deletions app/Traits/PlaybooksTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ protected function executePlaybook(
$playbookPath = $projectRoot . '/playbooks/' . $playbookName . '.sh';
$scriptContents = $this->fs->readFile($playbookPath);

// Prepend helpers.sh content to playbook for remote execution
$helpersPath = $projectRoot . '/playbooks/helpers.sh';
if (file_exists($helpersPath)) {
$helpersContents = $this->fs->readFile($helpersPath);
$scriptContents = $helpersContents . "\n\n" . $scriptContents;
}

// Unique output file name
$outputFile = sprintf('/tmp/deployer-output-%d-%s.yml', time(), bin2hex(random_bytes(8)));

Expand Down
Loading