Skip to content

Commit

Permalink
Ensure the certificates generation can be done from everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Jan 23, 2024
1 parent 15e4261 commit 3769ee2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .castor/infra.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ function generate_certificates(
#[AsOption(description: 'Force the certificates re-generation without confirmation', shortcut: 'f')]
bool $force = false,
): void {
if (file_exists(variable('root_dir') . '/infrastructure/docker/services/router/certs/cert.pem') && !$force) {
$sslDir = variable('root_dir') . '/infrastructure/development/services/router/certs';

if (file_exists("$sslDir/cert.pem") && !$force) {
io()->comment('SSL certificates already exists.');
io()->note('Run "castor infra:generate-certificates --force" to generate new certificates.');

return;
}

if ($force) {
if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/certs/cert.pem')) {
if (file_exists($f = "$sslDir/cert.pem")) {
io()->comment('Removing existing certificates in infrastructure/docker/services/router/certs/*.pem.');
unlink($f);
}

if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/certs/key.pem')) {
if (file_exists($f = "$sslDir/key.pem")) {
unlink($f);
}
}
Expand All @@ -138,8 +140,8 @@ function generate_certificates(

run([
'mkcert',
'-cert-file', 'infrastructure/docker/services/router/certs/cert.pem',
'-key-file', 'infrastructure/docker/services/router/certs/key.pem',
'-cert-file', "$sslDir/cert.pem",
'-key-file', "$sslDir/key.pem",
$rootDomain,
"*.{$rootDomain}",
...variable('extra_domains'),
Expand Down

0 comments on commit 3769ee2

Please sign in to comment.