From e30e7487fd1f2eb25f212899b702c1ebd8295596 Mon Sep 17 00:00:00 2001 From: Victor R <39545521+viicslen@users.noreply.github.com> Date: Thu, 6 Apr 2023 17:19:44 -0400 Subject: [PATCH 1/2] Adds `fleet:ssl` command The `fleet:ssl` command adds SSL support for an existing installation of Fleet --- src/Commands/FleetSslCommand.php | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Commands/FleetSslCommand.php diff --git a/src/Commands/FleetSslCommand.php b/src/Commands/FleetSslCommand.php new file mode 100644 index 0000000..c5df30f --- /dev/null +++ b/src/Commands/FleetSslCommand.php @@ -0,0 +1,68 @@ +argument('domain'); + if (! $domain) { + $domain = $this->ask('What domain name would you like to use for this app?', 'laravel.localhost'); + } + + $file = base_path('docker-compose.yml'); + if (! file_exists($file)) { + $this->error('A docker-compose.yml file does not exist'); + + return self::FAILURE; + } + + $this->info(' 🔒 Adding SSL support...'); + + try { + $filesystem->createCertificates($domain); + } catch (\Exception $e) { + $this->error($e->getMessage()); + $this->line('For more information, try checking out the documentation at mkcert.dev'); + + return self::FAILURE; + } + + try { + $filesystem->createSslConfig($domain); + } catch (\Exception $e) { + $this->error($e->getMessage()); + + return self::FAILURE; + } + + $this->addTlsToDockerCompose($file, $domain); + + // return info back to the user + $this->info(' ✨ All done! You can now run `./vendor/bin/sail up`'); + $this->newLine(); + + return self::SUCCESS; + } + + private function addTlsToDockerCompose(string $file, string $domain): void + { + $yaml = Yaml::parseFile($file); + $heading = str_replace('.', '-', $domain); + + $yaml['services'][$heading]['labels'][] = "traefik.http.routers.{$heading}.tls=true"; + + file_put_contents(base_path('docker-compose.yml'), Yaml::dump($yaml, 6)); + } +} From 0f0a7cb98658fca370e5d1f0d4a4a69c996166ad Mon Sep 17 00:00:00 2001 From: Victor R <39545521+viicslen@users.noreply.github.com> Date: Thu, 6 Apr 2023 18:05:33 -0400 Subject: [PATCH 2/2] Adds option to add the tls label to the docker compose file --- src/Commands/FleetSslCommand.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Commands/FleetSslCommand.php b/src/Commands/FleetSslCommand.php index c5df30f..4662cbf 100644 --- a/src/Commands/FleetSslCommand.php +++ b/src/Commands/FleetSslCommand.php @@ -9,7 +9,8 @@ class FleetSslCommand extends Command { public $signature = 'fleet:ssl - {domain? : The test domain to use}'; + {domain? : The test domain to use} + {--add : Add TLS labels to the docker-compose.yml file}'; public $description = 'Adds SSL support for an existing Fleet installation'; @@ -47,7 +48,9 @@ public function handle(Filesystem $filesystem): int return self::FAILURE; } - $this->addTlsToDockerCompose($file, $domain); + if ($this->option('add')) { + $this->addTlsToDockerCompose($file, $domain); + } // return info back to the user $this->info(' ✨ All done! You can now run `./vendor/bin/sail up`');