An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(api): return deployment UUID strings directly
Andras Bacsai29c122b31a98
diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.phpindex d125c01ec5..790fdf2008 100644--- a/app/Http/Controllers/Api/ApplicationsController.php+++ b/app/Http/Controllers/Api/ApplicationsController.php@@ -3609,7 +3609,7 @@ class ApplicationsController extends Controller'team_id' => $teamId,'application_uuid' => $application->uuid,'application_name' => $application->name,- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,'force_rebuild' => $force,'instant_deploy' => $instant_deploy,]);@@ -3617,7 +3617,7 @@ class ApplicationsController extends Controllerreturn response()->json(['message' => 'Deployment request queued.',- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,],200);@@ -3803,13 +3803,13 @@ class ApplicationsController extends Controller'team_id' => $teamId,'application_uuid' => $application->uuid,'application_name' => $application->name,- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,]);return response()->json(['message' => 'Restart request queued.',- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,],);}diff --git a/app/Http/Controllers/Api/DeployController.php b/app/Http/Controllers/Api/DeployController.phpindex f0cf48efab..182080044b 100644--- a/app/Http/Controllers/Api/DeployController.php+++ b/app/Http/Controllers/Api/DeployController.php@@ -425,7 +425,7 @@ class DeployController extends Controller}['message' => $return_message, 'deployment_uuid' => $deployment_uuid] = $result;if ($deployment_uuid) {- $deployments->push(['message' => $return_message, 'resource_uuid' => $uuid, 'deployment_uuid' => $deployment_uuid->toString()]);+ $deployments->push(['message' => $return_message, 'resource_uuid' => $uuid, 'deployment_uuid' => $deployment_uuid]);} else {$deployments->push(['message' => $return_message, 'resource_uuid' => $uuid]);}@@ -471,7 +471,7 @@ class DeployController extends Controller}['message' => $return_message, 'deployment_uuid' => $deployment_uuid] = $result;if ($deployment_uuid) {- $deployments->push(['resource_uuid' => $resource->uuid, 'deployment_uuid' => $deployment_uuid->toString()]);+ $deployments->push(['resource_uuid' => $resource->uuid, 'deployment_uuid' => $deployment_uuid]);}$message = $message->merge($return_message);}@@ -529,7 +529,7 @@ class DeployController extends Controller'resource_type' => 'application','application_uuid' => $resource->uuid,'application_name' => $resource->name,- 'deployment_uuid' => $deployment_uuid?->toString(),+ 'deployment_uuid' => $deployment_uuid,'force_rebuild' => $force,'pull_request_id' => $pr,]);diff --git a/app/Http/Controllers/Webhook/Bitbucket.php b/app/Http/Controllers/Webhook/Bitbucket.phpindex 435f5efab6..fea55586bc 100644--- a/app/Http/Controllers/Webhook/Bitbucket.php+++ b/app/Http/Controllers/Webhook/Bitbucket.php@@ -162,7 +162,7 @@ class Bitbucket extends Controller'mode' => 'manual','application_uuid' => $application->uuid,'application_name' => $application->name,- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,'commit' => $commit,'repository' => $full_name ?? null,]);diff --git a/app/Http/Controllers/Webhook/Gitea.php b/app/Http/Controllers/Webhook/Gitea.phpindex 82a8cc8aff..a59cb54982 100644--- a/app/Http/Controllers/Webhook/Gitea.php+++ b/app/Http/Controllers/Webhook/Gitea.php@@ -148,7 +148,7 @@ class Gitea extends Controller'mode' => 'manual','application_uuid' => $application->uuid,'application_name' => $application->name,- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,'commit' => data_get($payload, 'after'),'repository' => $full_name ?? null,]);diff --git a/app/Http/Controllers/Webhook/Gitlab.php b/app/Http/Controllers/Webhook/Gitlab.phpindex c90f4ad400..cd68c1b673 100644--- a/app/Http/Controllers/Webhook/Gitlab.php+++ b/app/Http/Controllers/Webhook/Gitlab.php@@ -190,7 +190,7 @@ class Gitlab extends Controller'mode' => 'manual','application_uuid' => $application->uuid,'application_name' => $application->name,- 'deployment_uuid' => $deployment_uuid->toString(),+ 'deployment_uuid' => $deployment_uuid,'commit' => data_get($payload, 'after'),'repository' => $full_name ?? null,]);diff --git a/tests/Feature/ApiApplicationDeploymentActionsTest.php b/tests/Feature/ApiApplicationDeploymentActionsTest.phpnew file mode 100644index 0000000000..d431b3577d--- /dev/null+++ b/tests/Feature/ApiApplicationDeploymentActionsTest.php@@ -0,0 +1,108 @@+<?php++use App\Jobs\ApplicationDeploymentJob;+use App\Models\Application;+use App\Models\ApplicationDeploymentQueue;+use App\Models\Environment;+use App\Models\InstanceSettings;+use App\Models\Project;+use App\Models\Server;+use App\Models\StandaloneDocker;+use App\Models\Team;+use App\Models\User;+use Illuminate\Foundation\Testing\RefreshDatabase;+use Illuminate\Support\Facades\Bus;+use Illuminate\Testing\Fluent\AssertableJson;++uses(RefreshDatabase::class);++beforeEach(function () {+ Bus::fake([ApplicationDeploymentJob::class]);++ InstanceSettings::unguarded(fn () => InstanceSettings::query()->updateOrCreate(+ ['id' => 0],+ ['is_api_enabled' => true],+ ));++ $this->team = Team::factory()->create();+ $this->user = User::factory()->create();+ $this->team->members()->attach($this->user->id, ['role' => 'owner']);+ session(['currentTeam' => $this->team]);++ $this->token = $this->user->createToken('deployment-actions-test', ['deploy'])->plainTextToken;++ $this->server = Server::factory()->create(['team_id' => $this->team->id]);+ $this->destination = StandaloneDocker::query()->where('server_id', $this->server->id)->firstOrFail();+ $this->project = Project::factory()->create(['team_id' => $this->team->id]);+ $this->environment = Environment::factory()->create(['project_id' => $this->project->id]);+});++function deploymentActionHeaders(string $token): array+{+ return [+ 'Authorization' => 'Bearer '.$token,+ 'Content-Type' => 'application/json',+ ];+}++function makeDeploymentActionApplication(Environment $environment, StandaloneDocker $destination): Application+{+ return Application::factory()->create([+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ 'git_repository' => 'https://github.com/coollabsio/coolify',+ 'git_branch' => 'main',+ 'git_commit_sha' => 'HEAD',+ ]);+}++test('application start API returns queued deployment uuid as a string', function () {+ $application = makeDeploymentActionApplication($this->environment, $this->destination);++ $response = $this->withHeaders(deploymentActionHeaders($this->token))+ ->postJson("/api/v1/applications/{$application->uuid}/start");++ $response->assertSuccessful()+ ->assertJson(fn (AssertableJson $json) => $json+ ->where('message', 'Deployment request queued.')+ ->whereType('deployment_uuid', 'string')+ );++ expect(ApplicationDeploymentQueue::query()->where('deployment_uuid', $response->json('deployment_uuid'))->exists())->toBeTrue();+});++test('application restart API returns queued deployment uuid as a string', function () {+ $application = makeDeploymentActionApplication($this->environment, $this->destination);++ $response = $this->withHeaders(deploymentActionHeaders($this->token))+ ->postJson("/api/v1/applications/{$application->uuid}/restart");++ $response->assertSuccessful()+ ->assertJson(fn (AssertableJson $json) => $json+ ->where('message', 'Restart request queued.')+ ->whereType('deployment_uuid', 'string')+ );++ $deployment = ApplicationDeploymentQueue::query()+ ->where('deployment_uuid', $response->json('deployment_uuid'))+ ->first();++ expect($deployment)->not->toBeNull()+ ->and($deployment->restart_only)->toBeTruthy();+});++test('deployment uuid strings are not converted as objects in API and webhook controllers', function () {+ $files = [+ app_path('Http/Controllers/Api/DeployController.php'),+ app_path('Http/Controllers/Webhook/Bitbucket.php'),+ app_path('Http/Controllers/Webhook/Gitea.php'),+ app_path('Http/Controllers/Webhook/Gitlab.php'),+ ];++ foreach ($files as $file) {+ expect(file_get_contents($file))+ ->not->toContain('$deployment_uuid->toString()')+ ->not->toContain('$deployment_uuid?->toString()');+ }+});