diff --git a/src/Commands/FleetSslCommand.php b/src/Commands/FleetSslCommand.php new file mode 100644 index 0000000..4662cbf --- /dev/null +++ b/src/Commands/FleetSslCommand.php @@ -0,0 +1,71 @@ +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; + } + + 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`'); + $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)); + } +}