feat: able to deploy multiple resources with webhook
This commit is contained in:
130
routes/api.php
130
routes/api.php
@@ -34,74 +34,82 @@ Route::group([
|
|||||||
$token = auth()->user()->currentAccessToken();
|
$token = auth()->user()->currentAccessToken();
|
||||||
$teamId = data_get($token, 'team_id');
|
$teamId = data_get($token, 'team_id');
|
||||||
$uuid = $request->query->get('uuid');
|
$uuid = $request->query->get('uuid');
|
||||||
|
$uuids = explode(',', $uuid);
|
||||||
|
$uuids = collect(array_filter($uuids));
|
||||||
$force = $request->query->get('force') ?? false;
|
$force = $request->query->get('force') ?? false;
|
||||||
if (is_null($teamId)) {
|
if (is_null($teamId)) {
|
||||||
return response()->json(['error' => 'Invalid token.'], 400);
|
return response()->json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400);
|
||||||
}
|
}
|
||||||
if (!$uuid) {
|
if (count($uuids) === 0) {
|
||||||
return response()->json(['error' => 'No UUID provided.'], 400);
|
return response()->json(['error' => 'No UUIDs provided.', 'docs' => 'https://coolify.io/docs/api/deploy-webhook'], 400);
|
||||||
}
|
}
|
||||||
$resource = getResourceByUuid($uuid, $teamId);
|
$message = collect([]);
|
||||||
if ($resource) {
|
foreach ($uuids as $uuid) {
|
||||||
$type = $resource->getMorphClass();
|
$resource = getResourceByUuid($uuid, $teamId);
|
||||||
if ($type === 'App\Models\Application') {
|
if ($resource) {
|
||||||
queue_application_deployment(
|
$type = $resource->getMorphClass();
|
||||||
application_id: $resource->id,
|
if ($type === 'App\Models\Application') {
|
||||||
deployment_uuid: new Cuid2(7),
|
queue_application_deployment(
|
||||||
force_rebuild: $force,
|
application_id: $resource->id,
|
||||||
);
|
deployment_uuid: new Cuid2(7),
|
||||||
return response()->json(['message' => 'Deployment queued.'], 200);
|
force_rebuild: $force,
|
||||||
} else if ($type === 'App\Models\StandalonePostgresql') {
|
);
|
||||||
if (str($resource->status)->startsWith('running')) {
|
$message->push("Application {$resource->name} deployment queued.");
|
||||||
return response()->json(['message' => 'Database already running.'], 200);
|
} else if ($type === 'App\Models\StandalonePostgresql') {
|
||||||
|
if (str($resource->status)->startsWith('running')) {
|
||||||
|
$message->push("Database {$resource->name} already running.");
|
||||||
|
}
|
||||||
|
StartPostgresql::run($resource);
|
||||||
|
$resource->update([
|
||||||
|
'started_at' => now(),
|
||||||
|
]);
|
||||||
|
$message->push("Database {$resource->name} started.");
|
||||||
|
} else if ($type === 'App\Models\StandaloneRedis') {
|
||||||
|
if (str($resource->status)->startsWith('running')) {
|
||||||
|
$message->push("Database {$resource->name} already running.");
|
||||||
|
}
|
||||||
|
StartRedis::run($resource);
|
||||||
|
$resource->update([
|
||||||
|
'started_at' => now(),
|
||||||
|
]);
|
||||||
|
$message->push("Database {$resource->name} started.");
|
||||||
|
} else if ($type === 'App\Models\StandaloneMongodb') {
|
||||||
|
if (str($resource->status)->startsWith('running')) {
|
||||||
|
$message->push("Database {$resource->name} already running.");
|
||||||
|
}
|
||||||
|
StartMongodb::run($resource);
|
||||||
|
$resource->update([
|
||||||
|
'started_at' => now(),
|
||||||
|
]);
|
||||||
|
$message->push("Database {$resource->name} started.");
|
||||||
|
} else if ($type === 'App\Models\StandaloneMysql') {
|
||||||
|
if (str($resource->status)->startsWith('running')) {
|
||||||
|
$message->push("Database {$resource->name} already running.");
|
||||||
|
}
|
||||||
|
StartMysql::run($resource);
|
||||||
|
$resource->update([
|
||||||
|
'started_at' => now(),
|
||||||
|
]);
|
||||||
|
$message->push("Database {$resource->name} started.");
|
||||||
|
} else if ($type === 'App\Models\StandaloneMariadb') {
|
||||||
|
if (str($resource->status)->startsWith('running')) {
|
||||||
|
$message->push("Database {$resource->name} already running.");
|
||||||
|
}
|
||||||
|
StartMariadb::run($resource);
|
||||||
|
$resource->update([
|
||||||
|
'started_at' => now(),
|
||||||
|
]);
|
||||||
|
$message->push("Database {$resource->name} started.");
|
||||||
|
} else if ($type === 'App\Models\Service') {
|
||||||
|
StartService::run($resource);
|
||||||
|
$message->push("Service {$resource->name} started. It could take a while, be patient.");
|
||||||
}
|
}
|
||||||
StartPostgresql::run($resource);
|
|
||||||
$resource->update([
|
|
||||||
'started_at' => now(),
|
|
||||||
]);
|
|
||||||
return response()->json(['message' => 'Database started.'], 200);
|
|
||||||
} else if ($type === 'App\Models\StandaloneRedis') {
|
|
||||||
if (str($resource->status)->startsWith('running')) {
|
|
||||||
return response()->json(['message' => 'Database already running.'], 200);
|
|
||||||
}
|
|
||||||
StartRedis::run($resource);
|
|
||||||
$resource->update([
|
|
||||||
'started_at' => now(),
|
|
||||||
]);
|
|
||||||
return response()->json(['message' => 'Database started.'], 200);
|
|
||||||
} else if ($type === 'App\Models\StandaloneMongodb') {
|
|
||||||
if (str($resource->status)->startsWith('running')) {
|
|
||||||
return response()->json(['message' => 'Database already running.'], 200);
|
|
||||||
}
|
|
||||||
StartMongodb::run($resource);
|
|
||||||
$resource->update([
|
|
||||||
'started_at' => now(),
|
|
||||||
]);
|
|
||||||
return response()->json(['message' => 'Database started.'], 200);
|
|
||||||
} else if ($type === 'App\Models\StandaloneMysql') {
|
|
||||||
if (str($resource->status)->startsWith('running')) {
|
|
||||||
return response()->json(['message' => 'Database already running.'], 200);
|
|
||||||
}
|
|
||||||
StartMysql::run($resource);
|
|
||||||
$resource->update([
|
|
||||||
'started_at' => now(),
|
|
||||||
]);
|
|
||||||
return response()->json(['message' => 'Database started.'], 200);
|
|
||||||
} else if ($type === 'App\Models\StandaloneMariadb') {
|
|
||||||
if (str($resource->status)->startsWith('running')) {
|
|
||||||
return response()->json(['message' => 'Database already running.'], 200);
|
|
||||||
}
|
|
||||||
StartMariadb::run($resource);
|
|
||||||
$resource->update([
|
|
||||||
'started_at' => now(),
|
|
||||||
]);
|
|
||||||
return response()->json(['message' => 'Database started.'], 200);
|
|
||||||
} else if ($type === 'App\Models\Service') {
|
|
||||||
StartService::run($resource);
|
|
||||||
return response()->json(['message' => 'Service started. It could take a while, be patient.'], 200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response()->json(['error' => "No resource found with {$uuid}."], 404);
|
if ($message->count() > 0) {
|
||||||
|
return response()->json(['message' => $message->toArray()], 200);
|
||||||
|
}
|
||||||
|
return response()->json(['error' => "No resources found.", 'docs' => 'https://coolify.io/docs/api/deploy-webhook'], 404);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user