Add Caddy Server Support Alongside Nginx (#600)

* added enum

* add config for caddy

* add svg icon

* add caddy service class

* wip

* install caddy

* create base Caddyfile with common snippets

* Create a systemd service to run Caddy in the background.

* create uninstall file

* wip

* create path

* create vhost

* get vhost

* delete site

* add php version change file

* add custom ssl

* create redirect file

* add vhost for caddy site & load balancer

* update svg

* fix caddy icon

* fix style

* add systemctl reload method

* Reload systemd after modifying the Caddy service file.

* add caddy

* added tests

* format with pint

* prevent multiple web server installations

* added error log & access log

(cherry picked from commit 2318e1b1df)
This commit is contained in:
Rasel Islam Rafi
2025-05-29 15:25:36 +06:00
committed by Saeed Vaziry
parent 61506ff70e
commit 984c1f3a8e
24 changed files with 590 additions and 18 deletions

View File

@ -68,6 +68,31 @@ public function test_create_server(): void
]);
}
public function test_create_server_with_caddy(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);
SSH::fake('Active: active'); // fake output for service installations
$this->json('POST', route('api.projects.servers.create', [
'project' => $this->user->current_project_id,
]), [
'provider' => ServerProvider::CUSTOM,
'name' => 'test',
'ip' => '1.1.1.1',
'port' => '22',
'os' => OperatingSystem::UBUNTU22,
'webserver' => Webserver::CADDY,
'database' => Database::MYSQL80,
'php' => '8.2',
])
->assertSuccessful()
->assertJsonFragment([
'name' => 'test',
'type' => ServerType::REGULAR,
]);
}
public function test_delete_server(): void
{
Sanctum::actingAs($this->user, ['read', 'write']);

View File

@ -83,6 +83,63 @@ public function test_create_regular_server(): void
]);
}
public function test_create_regular_server_with_caddy(): void
{
$this->actingAs($this->user);
SSH::fake('Active: active'); // fake output for service installations
Livewire::test(Index::class)
->callAction('create', [
'provider' => ServerProvider::CUSTOM,
'name' => 'caddy-test',
'ip' => '2.2.2.2',
'port' => '22',
'os' => OperatingSystem::UBUNTU22,
'webserver' => Webserver::CADDY,
'database' => Database::MYSQL80,
'php' => '8.2',
])
->assertSuccessful();
$this->assertDatabaseHas('servers', [
'name' => 'caddy-test',
'ip' => '2.2.2.2',
'status' => ServerStatus::READY,
]);
$this->assertDatabaseHas('services', [
'server_id' => 2,
'type' => 'php',
'version' => '8.2',
'status' => ServiceStatus::READY,
]);
$this->assertDatabaseHas('services', [
'server_id' => 2,
'type' => 'webserver',
'name' => 'caddy',
'version' => 'latest',
'status' => ServiceStatus::READY,
]);
$this->assertDatabaseHas('services', [
'server_id' => 2,
'type' => 'database',
'name' => 'mysql',
'version' => '8.0',
'status' => ServiceStatus::READY,
]);
$this->assertDatabaseHas('services', [
'server_id' => 2,
'type' => 'firewall',
'name' => 'ufw',
'version' => 'latest',
'status' => ServiceStatus::READY,
]);
}
public function test_delete_server(): void
{
$this->actingAs($this->user);

View File

@ -75,6 +75,29 @@ public function test_install_nginx(): void
$this->assertNotNull($service->type_data);
}
public function test_install_caddy(): void
{
$this->server->webserver()->delete();
SSH::fake('Active: active');
$service = app(Install::class)->install($this->server, [
'type' => 'webserver',
'name' => 'caddy',
'version' => 'latest',
]);
$this->assertDatabaseHas('services', [
'server_id' => $this->server->id,
'name' => 'caddy',
'type' => 'webserver',
'version' => 'latest',
'status' => ServiceStatus::READY,
]);
$this->assertNotNull($service->type_data);
}
public function test_install_mysql(): void
{
$this->server->database()->delete();

View File

@ -51,6 +51,18 @@ public function test_cannot_uninstall_nginx(): void
app(Uninstall::class)->uninstall($this->server->webserver());
}
/**
* Cannot uninstall caddy because some sites using it
*/
public function test_cannot_uninstall_caddy(): void
{
SSH::fake();
$this->expectException(ValidationException::class);
app(Uninstall::class)->uninstall($this->server->webserver());
}
/**
* Cannot uninstall mysql because some databases exist
*/