-
Notifications
You must be signed in to change notification settings - Fork 0
feat(site): add site:https command for enabling HTTPS #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b367631
feat(site): add site:https command for enabling HTTPS
loadinglucian 8cbbad3
fix(site:https): guard against unknown PHP version from server config
loadinglucian 8473dd6
refactor(servers): centralize site config parsing in displayServerInfo
loadinglucian 8c03b53
fix(site:add): add validation for WWW mode selection
loadinglucian ab18577
fix(server:info): quote YAML values in sites config output
loadinglucian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Bigpixelrocket\DeployerPHP\Console\Site; | ||
|
|
||
| use Bigpixelrocket\DeployerPHP\Contracts\BaseCommand; | ||
| use Bigpixelrocket\DeployerPHP\Traits\PlaybooksTrait; | ||
| use Bigpixelrocket\DeployerPHP\Traits\ServersTrait; | ||
| use Bigpixelrocket\DeployerPHP\Traits\SitesTrait; | ||
| 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: 'site:https', | ||
| description: 'Enable HTTPS for a site using Caddy automatic certificates' | ||
| )] | ||
| class SiteHttpsCommand extends BaseCommand | ||
| { | ||
| use PlaybooksTrait; | ||
| use ServersTrait; | ||
| use SitesTrait; | ||
|
|
||
| // ---- | ||
| // Configuration | ||
| // ---- | ||
|
|
||
| protected function configure(): void | ||
| { | ||
| parent::configure(); | ||
|
|
||
| $this->addOption('domain', null, InputOption::VALUE_REQUIRED, 'Domain name'); | ||
| } | ||
|
|
||
| // ---- | ||
| // Execution | ||
| // ---- | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| parent::execute($input, $output); | ||
|
|
||
| $this->heading('Enable HTTPS'); | ||
|
|
||
| // | ||
| // Select site | ||
| // ---- | ||
|
|
||
| $site = $this->selectSite() | ||
| ; | ||
| if (is_int($site)) { | ||
| return $site; | ||
| } | ||
|
|
||
| // | ||
| // Get server for site | ||
| // ---- | ||
|
|
||
| $server = $this->getServerForSite($site); | ||
|
|
||
| if (is_int($server)) { | ||
| return $server; | ||
| } | ||
|
|
||
| $this->displayServerDeets($server); | ||
|
|
||
| // | ||
| // Get server info (verifies SSH connection and validates distribution & permissions) | ||
| // ---- | ||
|
|
||
| $info = $this->serverInfo($server); | ||
|
|
||
| if (is_int($info)) { | ||
| return $info; | ||
| } | ||
|
|
||
| [ | ||
| 'distro' => $distro, | ||
| 'permissions' => $permissions, | ||
| ] = $info; | ||
|
|
||
| /** @var string $distro */ | ||
| /** @var string $permissions */ | ||
|
|
||
| // | ||
| // Get site configuration | ||
| // ---- | ||
|
|
||
| $config = $this->getSiteConfig($info, $site->domain); | ||
|
|
||
| if ($config === null) { | ||
| $this->io->warning("Site '{$site->domain}' configuration not found on server"); | ||
| $this->io->writeln([ | ||
| '', | ||
| 'It looks like this site has not been provisioned yet.', | ||
| 'Run <fg=cyan>site:add</> to provision the site first.', | ||
| '', | ||
| ]); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| if ($config['php_version'] === 'unknown') { | ||
| $this->nay("Could not detect PHP version for '{$site->domain}' from server config; re-provision the site or run server:info to debug."); | ||
|
|
||
| return Command::FAILURE; | ||
| } | ||
|
|
||
| // | ||
| // Execute playbook | ||
| // ---- | ||
|
|
||
| $result = $this->executePlaybook( | ||
| $server, | ||
| 'site-https', | ||
| 'Enabling HTTPS...', | ||
| [ | ||
| 'DEPLOYER_DISTRO' => $distro, | ||
| 'DEPLOYER_PERMS' => $permissions, | ||
| 'DEPLOYER_SITE_DOMAIN' => $site->domain, | ||
| 'DEPLOYER_PHP_VERSION' => $config['php_version'], | ||
| 'DEPLOYER_WWW_MODE' => $config['www_mode'], | ||
| ], | ||
| true | ||
| ); | ||
|
|
||
| if (is_int($result)) { | ||
| return $result; | ||
| } | ||
|
|
||
| $this->yay('HTTPS enabled successfully'); | ||
|
|
||
| // | ||
| // Display next steps | ||
| // ---- | ||
|
|
||
| $displayUrl = ($config['www_mode'] === 'redirect-to-www') | ||
| ? 'https://www.' . $site->domain | ||
| : 'https://' . $site->domain; | ||
|
|
||
| $this->io->writeln([ | ||
| 'Your site is now accessible over HTTPS:', | ||
| ' <fg=cyan>' . $displayUrl . '</>', | ||
| '', | ||
| ]); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.