Skip to content

Commit

Permalink
feat: add server api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Jul 23, 2024
1 parent e96e8f6 commit 189a834
Show file tree
Hide file tree
Showing 13 changed files with 765 additions and 295 deletions.
1 change: 0 additions & 1 deletion app/Actions/Proxy/CheckConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function handle(Server $server, bool $reset = false)
"cat $proxy_path/docker-compose.yml",
];
$proxy_configuration = instant_remote_process($payload, $server, false);

if ($reset || ! $proxy_configuration || is_null($proxy_configuration)) {
$proxy_configuration = str(generate_default_proxy_configuration($server))->trim()->value;
}
Expand Down
67 changes: 67 additions & 0 deletions app/Actions/Server/ValidateServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Actions\Server;

use App\Models\Server;
use Lorisleiva\Actions\Concerns\AsAction;

class ValidateServer
{
use AsAction;

public ?string $uptime = null;

public ?string $error = null;

public ?string $supported_os_type = null;

public ?string $docker_installed = null;

public ?string $docker_compose_installed = null;

public ?string $docker_version = null;

public function handle(Server $server)
{
$server->update([
'validation_logs' => null,
]);
['uptime' => $this->uptime, 'error' => $error] = $server->validateConnection();
if (! $this->uptime) {
$this->error = 'Server is not reachable. Please validate your configuration and connection.<br>Check this <a target="_blank" class="text-black underline dark:text-white" href="https://coolify.io/docs/knowledge-base/server/openssh">documentation</a> for further help. <br><br><div class="text-error">Error: '.$error.'</div>';
$server->update([
'validation_logs' => $this->error,
]);
throw new \Exception($this->error);
}
$this->supported_os_type = $server->validateOS();
if (! $this->supported_os_type) {
$this->error = 'Server OS type is not supported. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$server->update([
'validation_logs' => $this->error,
]);
throw new \Exception($this->error);
}

$this->docker_installed = $server->validateDockerEngine();
$this->docker_compose_installed = $server->validateDockerCompose();
if (! $this->docker_installed || ! $this->docker_compose_installed) {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$server->update([
'validation_logs' => $this->error,
]);
throw new \Exception($this->error);
}
$this->docker_version = $server->validateDockerEngineVersion();

if ($this->docker_version) {
return 'OK';
} else {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$server->update([
'validation_logs' => $this->error,
]);
throw new \Exception($this->error);
}
}
}
10 changes: 3 additions & 7 deletions app/Http/Controllers/Api/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function environment_details(Request $request)
schema: new OA\Schema(
type: 'object',
properties: [
'name' => ['type' => 'string', 'description' => 'The name of the project.'],
'uuid' => ['type' => 'string', 'description' => 'The name of the project.'],
'description' => ['type' => 'string', 'description' => 'The description of the project.'],
],
),
Expand All @@ -183,9 +183,7 @@ public function environment_details(Request $request)
schema: new OA\Schema(
type: 'object',
properties: [
'uuid' => ['type' => 'string', 'example' => 'og888os'],
'name' => ['type' => 'string', 'example' => 'Project Name'],
'description' => ['type' => 'string', 'example' => 'Project Description'],
'uuid' => ['type' => 'string', 'example' => 'og888os', 'description' => 'The UUID of the project.'],
]
)
),
Expand Down Expand Up @@ -218,7 +216,7 @@ public function create_project(Request $request)
return $return;
}
$validator = customApiValidator($request->all(), [
'name' => 'string|max:255',
'name' => 'string|max:255|required',
'description' => 'string|nullable',
]);

Expand All @@ -245,8 +243,6 @@ public function create_project(Request $request)

return response()->json([
'uuid' => $project->uuid,
'name' => $project->name,
'description' => $project->description,
])->setStatusCode(201);
}

Expand Down
Loading

0 comments on commit 189a834

Please sign in to comment.