fix: webhooks for multiple apps
This commit is contained in:
@@ -1522,7 +1522,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
|||||||
public function failed(Throwable $exception): void
|
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("Oops something is not okay, are you okay? 😢", 'stderr');
|
||||||
|
if (str($exception->getMessage())->isNotEmpty()) {
|
||||||
$this->application_deployment_queue->addLogEntry($exception->getMessage(), 'stderr');
|
$this->application_deployment_queue->addLogEntry($exception->getMessage(), 'stderr');
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->application->build_pack !== 'dockercompose') {
|
if ($this->application->build_pack !== 'dockercompose') {
|
||||||
$this->application_deployment_queue->addLogEntry("Deployment failed. Removing the new version of your application.", 'stderr');
|
$this->application_deployment_queue->addLogEntry("Deployment failed. Removing the new version of your application.", 'stderr');
|
||||||
|
@@ -7,6 +7,6 @@
|
|||||||
@endif
|
@endif
|
||||||
@if (data_get($application_deployment_queue, 'status') === 'in_progress' ||
|
@if (data_get($application_deployment_queue, 'status') === 'in_progress' ||
|
||||||
data_get($application_deployment_queue, 'status') === 'queued')
|
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
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
<h1>Deployments</h1>
|
<h1>Deployments</h1>
|
||||||
<livewire:project.application.heading :application="$application" />
|
<livewire:project.application.heading :application="$application" />
|
||||||
{{-- <livewire:project.application.deployment.show :application="$application" :deployments="$deployments" :deployments_count="$deployments_count" /> --}}
|
{{-- <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">
|
<div class="flex items-end gap-2 pt-4">
|
||||||
<h2>Deployments <span class="text-xs">({{ $deployments_count }})</span></h2>
|
<h2>Deployments <span class="text-xs">({{ $deployments_count }})</span></h2>
|
||||||
@if ($show_next)
|
@if ($show_next)
|
||||||
@@ -33,19 +34,27 @@
|
|||||||
<span class=" text-warning">></span>
|
<span class=" text-warning">></span>
|
||||||
{{ $deployment->status }}
|
{{ $deployment->status }}
|
||||||
</div>
|
</div>
|
||||||
@if (data_get($deployment, 'pull_request_id'))
|
@if (data_get($deployment, 'is_webhook') || data_get($deployment, 'pull_request_id'))
|
||||||
<div>
|
<div class="flex gap-1">
|
||||||
<span class=" text-warning">></span>
|
|
||||||
Pull Request #{{ data_get($deployment, 'pull_request_id') }}
|
|
||||||
@if (data_get($deployment, 'is_webhook'))
|
@if (data_get($deployment, 'is_webhook'))
|
||||||
(Webhook)
|
Webhook
|
||||||
@endif
|
@endif
|
||||||
Webhook (SHA
|
@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'))
|
@if (data_get($deployment, 'commit'))
|
||||||
{{ data_get($deployment, 'commit') }})
|
{{ data_get($deployment, 'commit') }})
|
||||||
@else
|
@else
|
||||||
HEAD)
|
HEAD)
|
||||||
@endif
|
@endif
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="flex gap-1">
|
||||||
|
Manual
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@@ -397,6 +397,7 @@ Route::post('/source/bitbucket/events/manual', function () {
|
|||||||
});
|
});
|
||||||
Route::post('/source/github/events/manual', function () {
|
Route::post('/source/github/events/manual', function () {
|
||||||
try {
|
try {
|
||||||
|
$return_payloads = collect([]);
|
||||||
$x_github_event = Str::lower(request()->header('X-GitHub-Event'));
|
$x_github_event = Str::lower(request()->header('X-GitHub-Event'));
|
||||||
$x_hub_signature_256 = Str::after(request()->header('X-Hub-Signature-256'), 'sha256=');
|
$x_hub_signature_256 = Str::after(request()->header('X-Hub-Signature-256'), 'sha256=');
|
||||||
$content_type = request()->header('Content-Type');
|
$content_type = request()->header('Content-Type');
|
||||||
@@ -445,13 +446,22 @@ Route::post('/source/github/events/manual', function () {
|
|||||||
foreach ($applications as $application) {
|
foreach ($applications as $application) {
|
||||||
$webhook_secret = data_get($application, 'manual_webhook_secret_github');
|
$webhook_secret = data_get($application, 'manual_webhook_secret_github');
|
||||||
$hmac = hash_hmac('sha256', request()->getContent(), $webhook_secret);
|
$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');
|
ray('Invalid signature');
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Invalid token.',
|
||||||
|
]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$isFunctional = $application->destination->server->isFunctional();
|
$isFunctional = $application->destination->server->isFunctional();
|
||||||
if (!$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;
|
continue;
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'push') {
|
if ($x_github_event === 'push') {
|
||||||
@@ -462,10 +472,19 @@ Route::post('/source/github/events/manual', function () {
|
|||||||
application: $application,
|
application: $application,
|
||||||
deployment_uuid: $deployment_uuid,
|
deployment_uuid: $deployment_uuid,
|
||||||
force_rebuild: false,
|
force_rebuild: false,
|
||||||
is_webhook: true
|
is_webhook: true,
|
||||||
);
|
);
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Deployment queued.',
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
ray('Deployments disabled for ' . $application->name);
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Deployments disabled.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'pull_request') {
|
if ($x_github_event === 'pull_request') {
|
||||||
@@ -489,11 +508,17 @@ Route::post('/source/github/events/manual', function () {
|
|||||||
is_webhook: true,
|
is_webhook: true,
|
||||||
git_type: 'github'
|
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_payloads->push([
|
||||||
return response('Preview Deployment queued.');
|
'application' => $application->name,
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Preview deployment queued.',
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
ray('Preview deployments disabled for ' . $application->name);
|
$return_payloads->push([
|
||||||
return response('Nothing to do. Preview Deployments disabled.');
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Preview deployments disabled.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($action === 'closed') {
|
if ($action === 'closed') {
|
||||||
@@ -503,12 +528,23 @@ Route::post('/source/github/events/manual', function () {
|
|||||||
$container_name = generateApplicationContainerName($application, $pull_request_id);
|
$container_name = generateApplicationContainerName($application, $pull_request_id);
|
||||||
// ray('Stopping container: ' . $container_name);
|
// ray('Stopping container: ' . $container_name);
|
||||||
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
|
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
|
||||||
return response('Preview Deployment closed.');
|
$return_payloads->push([
|
||||||
}
|
'application' => $application->name,
|
||||||
return response('Nothing to do. No Preview Deployment found');
|
'status' => 'success',
|
||||||
|
'message' => 'Preview deployment closed.',
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'No preview deployment found.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ray($return_payloads);
|
||||||
|
return response($return_payloads);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
@@ -516,6 +552,7 @@ Route::post('/source/github/events/manual', function () {
|
|||||||
});
|
});
|
||||||
Route::post('/source/github/events', function () {
|
Route::post('/source/github/events', function () {
|
||||||
try {
|
try {
|
||||||
|
$return_payloads = collect([]);
|
||||||
$id = null;
|
$id = null;
|
||||||
$x_github_delivery = request()->header('X-GitHub-Delivery');
|
$x_github_delivery = request()->header('X-GitHub-Delivery');
|
||||||
$x_github_event = Str::lower(request()->header('X-GitHub-Event'));
|
$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);
|
$hmac = hash_hmac('sha256', request()->getContent(), $webhook_secret);
|
||||||
if (config('app.env') !== 'local') {
|
if (config('app.env') !== 'local') {
|
||||||
if (!hash_equals($x_hub_signature_256, $hmac)) {
|
if (!hash_equals($x_hub_signature_256, $hmac)) {
|
||||||
return response('not cool');
|
return response('Invalid signature.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'push') {
|
if ($x_github_event === 'push') {
|
||||||
@@ -579,7 +616,11 @@ Route::post('/source/github/events', function () {
|
|||||||
foreach ($applications as $application) {
|
foreach ($applications as $application) {
|
||||||
$isFunctional = $application->destination->server->isFunctional();
|
$isFunctional = $application->destination->server->isFunctional();
|
||||||
if (!$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;
|
continue;
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'push') {
|
if ($x_github_event === 'push') {
|
||||||
@@ -592,8 +633,17 @@ Route::post('/source/github/events', function () {
|
|||||||
force_rebuild: false,
|
force_rebuild: false,
|
||||||
is_webhook: true
|
is_webhook: true
|
||||||
);
|
);
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Deployment queued.',
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
ray('Deployments disabled for ' . $application->name);
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Deployments disabled.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($x_github_event === 'pull_request') {
|
if ($x_github_event === 'pull_request') {
|
||||||
@@ -617,11 +667,17 @@ Route::post('/source/github/events', function () {
|
|||||||
is_webhook: true,
|
is_webhook: true,
|
||||||
git_type: 'github'
|
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_payloads->push([
|
||||||
return response('Preview Deployment queued.');
|
'application' => $application->name,
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Preview deployment queued.',
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
ray('Preview deployments disabled for ' . $application->name);
|
$return_payloads->push([
|
||||||
return response('Nothing to do. Preview Deployments disabled.');
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Preview deployments disabled.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($action === 'closed' || $action === 'close') {
|
if ($action === 'closed' || $action === 'close') {
|
||||||
@@ -632,12 +688,23 @@ Route::post('/source/github/events', function () {
|
|||||||
$container_name = generateApplicationContainerName($application, $pull_request_id);
|
$container_name = generateApplicationContainerName($application, $pull_request_id);
|
||||||
// ray('Stopping container: ' . $container_name);
|
// ray('Stopping container: ' . $container_name);
|
||||||
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
|
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
|
||||||
return response('Preview Deployment closed.');
|
$return_payloads->push([
|
||||||
}
|
'application' => $application->name,
|
||||||
return response('Nothing to do. No Preview Deployment found');
|
'status' => 'success',
|
||||||
|
'message' => 'Preview deployment closed.',
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'No preview deployment found.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ray($return_payloads);
|
||||||
|
return response($return_payloads);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
|
Reference in New Issue
Block a user