Skip to content

Commit 189a834

Browse files
committed
feat: add server api endpoints
1 parent e96e8f6 commit 189a834

File tree

13 files changed

+765
-295
lines changed

13 files changed

+765
-295
lines changed

app/Actions/Proxy/CheckConfiguration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function handle(Server $server, bool $reset = false)
2121
"cat $proxy_path/docker-compose.yml",
2222
];
2323
$proxy_configuration = instant_remote_process($payload, $server, false);
24-
2524
if ($reset || ! $proxy_configuration || is_null($proxy_configuration)) {
2625
$proxy_configuration = str(generate_default_proxy_configuration($server))->trim()->value;
2726
}

app/Actions/Server/ValidateServer.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace App\Actions\Server;
4+
5+
use App\Models\Server;
6+
use Lorisleiva\Actions\Concerns\AsAction;
7+
8+
class ValidateServer
9+
{
10+
use AsAction;
11+
12+
public ?string $uptime = null;
13+
14+
public ?string $error = null;
15+
16+
public ?string $supported_os_type = null;
17+
18+
public ?string $docker_installed = null;
19+
20+
public ?string $docker_compose_installed = null;
21+
22+
public ?string $docker_version = null;
23+
24+
public function handle(Server $server)
25+
{
26+
$server->update([
27+
'validation_logs' => null,
28+
]);
29+
['uptime' => $this->uptime, 'error' => $error] = $server->validateConnection();
30+
if (! $this->uptime) {
31+
$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>';
32+
$server->update([
33+
'validation_logs' => $this->error,
34+
]);
35+
throw new \Exception($this->error);
36+
}
37+
$this->supported_os_type = $server->validateOS();
38+
if (! $this->supported_os_type) {
39+
$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>.';
40+
$server->update([
41+
'validation_logs' => $this->error,
42+
]);
43+
throw new \Exception($this->error);
44+
}
45+
46+
$this->docker_installed = $server->validateDockerEngine();
47+
$this->docker_compose_installed = $server->validateDockerCompose();
48+
if (! $this->docker_installed || ! $this->docker_compose_installed) {
49+
$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>.';
50+
$server->update([
51+
'validation_logs' => $this->error,
52+
]);
53+
throw new \Exception($this->error);
54+
}
55+
$this->docker_version = $server->validateDockerEngineVersion();
56+
57+
if ($this->docker_version) {
58+
return 'OK';
59+
} else {
60+
$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>.';
61+
$server->update([
62+
'validation_logs' => $this->error,
63+
]);
64+
throw new \Exception($this->error);
65+
}
66+
}
67+
}

app/Http/Controllers/Api/ProjectController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function environment_details(Request $request)
167167
schema: new OA\Schema(
168168
type: 'object',
169169
properties: [
170-
'name' => ['type' => 'string', 'description' => 'The name of the project.'],
170+
'uuid' => ['type' => 'string', 'description' => 'The name of the project.'],
171171
'description' => ['type' => 'string', 'description' => 'The description of the project.'],
172172
],
173173
),
@@ -183,9 +183,7 @@ public function environment_details(Request $request)
183183
schema: new OA\Schema(
184184
type: 'object',
185185
properties: [
186-
'uuid' => ['type' => 'string', 'example' => 'og888os'],
187-
'name' => ['type' => 'string', 'example' => 'Project Name'],
188-
'description' => ['type' => 'string', 'example' => 'Project Description'],
186+
'uuid' => ['type' => 'string', 'example' => 'og888os', 'description' => 'The UUID of the project.'],
189187
]
190188
)
191189
),
@@ -218,7 +216,7 @@ public function create_project(Request $request)
218216
return $return;
219217
}
220218
$validator = customApiValidator($request->all(), [
221-
'name' => 'string|max:255',
219+
'name' => 'string|max:255|required',
222220
'description' => 'string|nullable',
223221
]);
224222

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

246244
return response()->json([
247245
'uuid' => $project->uuid,
248-
'name' => $project->name,
249-
'description' => $project->description,
250246
])->setStatusCode(201);
251247
}
252248

0 commit comments

Comments
 (0)