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: webhooks for multiple apps
Andras Bacsai49845f3da743
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 9e046fd426..4aa4a898aa 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -1522,7 +1522,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");public function failed(Throwable $exception): void{$this->application_deployment_queue->addLogEntry("Oops something is not okay, are you okay? 😢", 'stderr');- $this->application_deployment_queue->addLogEntry($exception->getMessage(), 'stderr');+ if (str($exception->getMessage())->isNotEmpty()) {+ $this->application_deployment_queue->addLogEntry($exception->getMessage(), 'stderr');+ }if ($this->application->build_pack !== 'dockercompose') {$this->application_deployment_queue->addLogEntry("Deployment failed. Removing the new version of your application.", 'stderr');diff --git a/resources/views/livewire/project/application/deployment-navbar.blade.php b/resources/views/livewire/project/application/deployment-navbar.blade.phpindex 936a3fb6eb..49f66dac01 100644--- a/resources/views/livewire/project/application/deployment-navbar.blade.php+++ b/resources/views/livewire/project/application/deployment-navbar.blade.php@@ -7,6 +7,6 @@@endif@if (data_get($application_deployment_queue, 'status') === 'in_progress' ||data_get($application_deployment_queue, 'status') === 'queued')- <x-forms.button wire:click.prevent="cancel">Cancel Deployment</x-forms.button>+ <x-forms.button isError wire:click.prevent="cancel">Cancel Deployment</x-forms.button>@endif</div>diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.phpindex 818005a124..9bfcda4b23 100644--- a/resources/views/livewire/project/application/deployment/index.blade.php+++ b/resources/views/livewire/project/application/deployment/index.blade.php@@ -2,7 +2,8 @@<h1>Deployments</h1><livewire:project.application.heading :application="$application" />{{-- <livewire:project.application.deployment.show :application="$application" :deployments="$deployments" :deployments_count="$deployments_count" /> --}}- <div class="flex flex-col gap-2 pb-10" @if ($skip == 0) wire:poll.5000ms='reload_deployments' @endif>+ <div class="flex flex-col gap-2 pb-10"+ @if ($skip == 0) wire:poll.5000ms='reload_deployments' @endif><div class="flex items-end gap-2 pt-4"><h2>Deployments <span class="text-xs">({{ $deployments_count }})</span></h2>@if ($show_next)@@ -15,7 +16,7 @@<x-forms.button type="submit">Filter</x-forms.button></form>@forelse ($deployments as $deployment)- <a @class([+ <a @class(['bg-coolgray-100 p-2 border-l border-dashed transition-colors hover:no-underline','hover:bg-coolgray-200' => data_get($deployment, 'status') === 'queued','border-warning hover:bg-warning hover:text-black' =>@@ -33,20 +34,28 @@<span class=" text-warning">></span>{{ $deployment->status }}</div>- @if (data_get($deployment, 'pull_request_id'))- <div>- <span class=" text-warning">></span>- Pull Request #{{ data_get($deployment, 'pull_request_id') }}+ @if (data_get($deployment, 'is_webhook') || data_get($deployment, 'pull_request_id'))+ <div class="flex gap-1">@if (data_get($deployment, 'is_webhook'))- (Webhook)+ Webhook@endif- Webhook (SHA- @if (data_get($deployment, 'commit'))- {{ data_get($deployment, 'commit') }})- @else- HEAD)+ @if (data_get($deployment, 'pull_request_id'))+ @if (data_get($deployment, 'is_webhook'))+ |+ @endif+ Pull Request #{{ data_get($deployment, 'pull_request_id') }}+ (SHA+ @if (data_get($deployment, 'commit'))+ {{ data_get($deployment, 'commit') }})+ @else+ HEAD)+ @endif@endif</div>+ @else+ <div class="flex gap-1">+ Manual+ </div>@endif</div>diff --git a/routes/webhooks.php b/routes/webhooks.phpindex 3eab89a3a3..515b90d847 100644--- a/routes/webhooks.php+++ b/routes/webhooks.php@@ -397,6 +397,7 @@ Route::post('/source/bitbucket/events/manual', function () {});Route::post('/source/github/events/manual', function () {try {+ $return_payloads = collect([]);$x_github_event = Str::lower(request()->header('X-GitHub-Event'));$x_hub_signature_256 = Str::after(request()->header('X-Hub-Signature-256'), 'sha256=');$content_type = request()->header('Content-Type');@@ -445,13 +446,22 @@ Route::post('/source/github/events/manual', function () {foreach ($applications as $application) {$webhook_secret = data_get($application, 'manual_webhook_secret_github');$hmac = hash_hmac('sha256', request()->getContent(), $webhook_secret);- if (!hash_equals($x_hub_signature_256, $hmac)) {+ if (!hash_equals($x_hub_signature_256, $hmac) && !isDev()) {ray('Invalid signature');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Invalid token.',+ ]);continue;}$isFunctional = $application->destination->server->isFunctional();if (!$isFunctional) {- ray('Server is not functional: ' . $application->destination->server->name);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Server is not functional.',+ ]);continue;}if ($x_github_event === 'push') {@@ -462,10 +472,19 @@ Route::post('/source/github/events/manual', function () {application: $application,deployment_uuid: $deployment_uuid,force_rebuild: false,- is_webhook: true+ is_webhook: true,);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Deployment queued.',+ ]);} else {- ray('Deployments disabled for ' . $application->name);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Deployments disabled.',+ ]);}}if ($x_github_event === 'pull_request') {@@ -489,11 +508,17 @@ Route::post('/source/github/events/manual', function () {is_webhook: true,git_type: 'github');- ray('Deploying preview for ' . $application->name . ' with branch ' . $branch . ' and base branch ' . $base_branch . ' and pull request id ' . $pull_request_id);- return response('Preview Deployment queued.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Preview deployment queued.',+ ]);} else {- ray('Preview deployments disabled for ' . $application->name);- return response('Nothing to do. Preview Deployments disabled.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Preview deployments disabled.',+ ]);}}if ($action === 'closed') {@@ -503,12 +528,23 @@ Route::post('/source/github/events/manual', function () {$container_name = generateApplicationContainerName($application, $pull_request_id);// ray('Stopping container: ' . $container_name);instant_remote_process(["docker rm -f $container_name"], $application->destination->server);- return response('Preview Deployment closed.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Preview deployment closed.',+ ]);+ } else {+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'No preview deployment found.',+ ]);}- return response('Nothing to do. No Preview Deployment found');}}}+ ray($return_payloads);+ return response($return_payloads);} catch (Exception $e) {ray($e->getMessage());return handleError($e);@@ -516,6 +552,7 @@ Route::post('/source/github/events/manual', function () {});Route::post('/source/github/events', function () {try {+ $return_payloads = collect([]);$id = null;$x_github_delivery = request()->header('X-GitHub-Delivery');$x_github_event = Str::lower(request()->header('X-GitHub-Event'));@@ -539,7 +576,7 @@ Route::post('/source/github/events', function () {$hmac = hash_hmac('sha256', request()->getContent(), $webhook_secret);if (config('app.env') !== 'local') {if (!hash_equals($x_hub_signature_256, $hmac)) {- return response('not cool');+ return response('Invalid signature.');}}if ($x_github_event === 'push') {@@ -579,7 +616,11 @@ Route::post('/source/github/events', function () {foreach ($applications as $application) {$isFunctional = $application->destination->server->isFunctional();if (!$isFunctional) {- ray('Server is not functional: ' . $application->destination->server->name);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Server is not functional.',+ ]);continue;}if ($x_github_event === 'push') {@@ -592,8 +633,17 @@ Route::post('/source/github/events', function () {force_rebuild: false,is_webhook: true);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Deployment queued.',+ ]);} else {- ray('Deployments disabled for ' . $application->name);+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Deployments disabled.',+ ]);}}if ($x_github_event === 'pull_request') {@@ -617,11 +667,17 @@ Route::post('/source/github/events', function () {is_webhook: true,git_type: 'github');- ray('Deploying preview for ' . $application->name . ' with branch ' . $branch . ' and base branch ' . $base_branch . ' and pull request id ' . $pull_request_id);- return response('Preview Deployment queued.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Preview deployment queued.',+ ]);} else {- ray('Preview deployments disabled for ' . $application->name);- return response('Nothing to do. Preview Deployments disabled.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'Preview deployments disabled.',+ ]);}}if ($action === 'closed' || $action === 'close') {@@ -632,12 +688,23 @@ Route::post('/source/github/events', function () {$container_name = generateApplicationContainerName($application, $pull_request_id);// ray('Stopping container: ' . $container_name);instant_remote_process(["docker rm -f $container_name"], $application->destination->server);- return response('Preview Deployment closed.');+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'success',+ 'message' => 'Preview deployment closed.',+ ]);+ } else {+ $return_payloads->push([+ 'application' => $application->name,+ 'status' => 'failed',+ 'message' => 'No preview deployment found.',+ ]);}- return response('Nothing to do. No Preview Deployment found');}}}+ ray($return_payloads);+ return response($return_payloads);} catch (Exception $e) {ray($e->getMessage());return handleError($e);