mirror of
https://github.com/ershisan99/coolify.git
synced 2026-01-03 12:34:08 +00:00
Compare commits
17 Commits
v4.0.0-bet
...
v4.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40a239ddda | ||
|
|
99d07981cf | ||
|
|
b3ee6b7144 | ||
|
|
468ad7d904 | ||
|
|
f1aa97e374 | ||
|
|
3b6d3343c7 | ||
|
|
ab2f9f073f | ||
|
|
67131152cc | ||
|
|
3bda289428 | ||
|
|
fadfa0ad8e | ||
|
|
11a957c6c9 | ||
|
|
b46de99af9 | ||
|
|
03420076c9 | ||
|
|
549446abdf | ||
|
|
06ab2145ca | ||
|
|
5d088e530e | ||
|
|
123e6eddd7 |
@@ -44,7 +44,7 @@ class CheckLogDrainContainerJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
{
|
{
|
||||||
// ray("checking log drain statuses for {$this->server->id}");
|
// ray("checking log drain statuses for {$this->server->id}");
|
||||||
try {
|
try {
|
||||||
if (!$this->server->isServerReady()) {
|
if (!$this->server->isFunctional()) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
$containers = instant_remote_process(["docker container ls -q"], $this->server, false);
|
$containers = instant_remote_process(["docker container ls -q"], $this->server, false);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
|
|||||||
{
|
{
|
||||||
ray("checking server status for {$this->server->id}");
|
ray("checking server status for {$this->server->id}");
|
||||||
try {
|
try {
|
||||||
if ($this->server->isServerReady()) {
|
if ($this->server->isFunctional()) {
|
||||||
$this->cleanup(notify: false);
|
$this->cleanup(notify: false);
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ class General extends Component
|
|||||||
$this->parsedServiceDomains[$serviceName]['domain'] = $domain;
|
$this->parsedServiceDomains[$serviceName]['domain'] = $domain;
|
||||||
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
|
$this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
|
||||||
$this->application->save();
|
$this->application->save();
|
||||||
$this->dispatch('success', 'Domain generated.');
|
|
||||||
}
|
}
|
||||||
return $domain;
|
return $domain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -966,66 +966,79 @@ class Application extends BaseModel
|
|||||||
function loadComposeFile($isInit = false)
|
function loadComposeFile($isInit = false)
|
||||||
{
|
{
|
||||||
$initialDockerComposeLocation = $this->docker_compose_location;
|
$initialDockerComposeLocation = $this->docker_compose_location;
|
||||||
// $initialDockerComposePrLocation = $this->docker_compose_pr_location;
|
if ($isInit && $this->docker_compose_raw) {
|
||||||
if ($this->build_pack === 'dockercompose') {
|
return;
|
||||||
if ($isInit && $this->docker_compose_raw) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$uuid = new Cuid2();
|
|
||||||
['commands' => $cloneCommand] = $this->generateGitImportCommands(deployment_uuid: $uuid, only_checkout: true, exec_in_docker: false, custom_base_dir: '.');
|
|
||||||
$workdir = rtrim($this->base_directory, '/');
|
|
||||||
$composeFile = $this->docker_compose_location;
|
|
||||||
// $prComposeFile = $this->docker_compose_pr_location;
|
|
||||||
$fileList = collect([".$workdir$composeFile"]);
|
|
||||||
// if ($composeFile !== $prComposeFile) {
|
|
||||||
// $fileList->push(".$prComposeFile");
|
|
||||||
// }
|
|
||||||
$commands = collect([
|
|
||||||
"mkdir -p /tmp/{$uuid} && cd /tmp/{$uuid}",
|
|
||||||
$cloneCommand,
|
|
||||||
"git sparse-checkout init --cone",
|
|
||||||
"git sparse-checkout set {$fileList->implode(' ')}",
|
|
||||||
"git read-tree -mu HEAD",
|
|
||||||
"cat .$workdir$composeFile",
|
|
||||||
]);
|
|
||||||
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
|
|
||||||
if (!$composeFileContent) {
|
|
||||||
$this->docker_compose_location = $initialDockerComposeLocation;
|
|
||||||
$this->save();
|
|
||||||
throw new \Exception("Could not load base compose file from $workdir$composeFile");
|
|
||||||
} else {
|
|
||||||
$this->docker_compose_raw = $composeFileContent;
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
// if ($composeFile === $prComposeFile) {
|
|
||||||
// $this->docker_compose_pr_raw = $composeFileContent;
|
|
||||||
// $this->save();
|
|
||||||
// } else {
|
|
||||||
// $commands = collect([
|
|
||||||
// "cd /tmp/{$uuid}",
|
|
||||||
// "cat .$workdir$prComposeFile",
|
|
||||||
// ]);
|
|
||||||
// $composePrFileContent = instant_remote_process($commands, $this->destination->server, false);
|
|
||||||
// if (!$composePrFileContent) {
|
|
||||||
// $this->docker_compose_pr_location = $initialDockerComposePrLocation;
|
|
||||||
// $this->save();
|
|
||||||
// throw new \Exception("Could not load compose file from $workdir$prComposeFile");
|
|
||||||
// } else {
|
|
||||||
// $this->docker_compose_pr_raw = $composePrFileContent;
|
|
||||||
// $this->save();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
$commands = collect([
|
|
||||||
"rm -rf /tmp/{$uuid}",
|
|
||||||
]);
|
|
||||||
instant_remote_process($commands, $this->destination->server, false);
|
|
||||||
return [
|
|
||||||
'parsedServices' => $this->parseCompose(),
|
|
||||||
'initialDockerComposeLocation' => $this->docker_compose_location,
|
|
||||||
'initialDockerComposePrLocation' => $this->docker_compose_pr_location,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
$uuid = new Cuid2();
|
||||||
|
['commands' => $cloneCommand] = $this->generateGitImportCommands(deployment_uuid: $uuid, only_checkout: true, exec_in_docker: false, custom_base_dir: '.');
|
||||||
|
$workdir = rtrim($this->base_directory, '/');
|
||||||
|
$composeFile = $this->docker_compose_location;
|
||||||
|
// $prComposeFile = $this->docker_compose_pr_location;
|
||||||
|
$fileList = collect([".$workdir$composeFile"]);
|
||||||
|
// if ($composeFile !== $prComposeFile) {
|
||||||
|
// $fileList->push(".$prComposeFile");
|
||||||
|
// }
|
||||||
|
$commands = collect([
|
||||||
|
"mkdir -p /tmp/{$uuid} && cd /tmp/{$uuid}",
|
||||||
|
$cloneCommand,
|
||||||
|
"git sparse-checkout init --cone",
|
||||||
|
"git sparse-checkout set {$fileList->implode(' ')}",
|
||||||
|
"git read-tree -mu HEAD",
|
||||||
|
"cat .$workdir$composeFile",
|
||||||
|
]);
|
||||||
|
$composeFileContent = instant_remote_process($commands, $this->destination->server, false);
|
||||||
|
if (!$composeFileContent) {
|
||||||
|
$this->docker_compose_location = $initialDockerComposeLocation;
|
||||||
|
$this->save();
|
||||||
|
throw new \Exception("Could not load base compose file from $workdir$composeFile");
|
||||||
|
} else {
|
||||||
|
$this->docker_compose_raw = $composeFileContent;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
// if ($composeFile === $prComposeFile) {
|
||||||
|
// $this->docker_compose_pr_raw = $composeFileContent;
|
||||||
|
// $this->save();
|
||||||
|
// } else {
|
||||||
|
// $commands = collect([
|
||||||
|
// "cd /tmp/{$uuid}",
|
||||||
|
// "cat .$workdir$prComposeFile",
|
||||||
|
// ]);
|
||||||
|
// $composePrFileContent = instant_remote_process($commands, $this->destination->server, false);
|
||||||
|
// if (!$composePrFileContent) {
|
||||||
|
// $this->docker_compose_pr_location = $initialDockerComposePrLocation;
|
||||||
|
// $this->save();
|
||||||
|
// throw new \Exception("Could not load compose file from $workdir$prComposeFile");
|
||||||
|
// } else {
|
||||||
|
// $this->docker_compose_pr_raw = $composePrFileContent;
|
||||||
|
// $this->save();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$commands = collect([
|
||||||
|
"rm -rf /tmp/{$uuid}",
|
||||||
|
]);
|
||||||
|
instant_remote_process($commands, $this->destination->server, false);
|
||||||
|
$parsedServices = $this->parseCompose();
|
||||||
|
if ($this->docker_compose_domains) {
|
||||||
|
$json = collect(json_decode($this->docker_compose_domains));
|
||||||
|
$names = collect(data_get($parsedServices, 'services'))->keys()->toArray();
|
||||||
|
$jsonNames = $json->keys()->toArray();
|
||||||
|
$diff = array_diff($jsonNames, $names);
|
||||||
|
$json = $json->filter(function ($value, $key) use ($diff) {
|
||||||
|
return !in_array($key, $diff);
|
||||||
|
});
|
||||||
|
if ($json) {
|
||||||
|
$this->docker_compose_domains = json_encode($json);
|
||||||
|
} else {
|
||||||
|
$this->docker_compose_domains = null;
|
||||||
|
}
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'parsedServices' => $parsedServices,
|
||||||
|
'initialDockerComposeLocation' => $this->docker_compose_location,
|
||||||
|
'initialDockerComposePrLocation' => $this->docker_compose_pr_location,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
function parseContainerLabels(?ApplicationPreview $preview = null)
|
function parseContainerLabels(?ApplicationPreview $preview = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,14 +153,15 @@ class Server extends BaseModel
|
|||||||
public function isServerReady()
|
public function isServerReady()
|
||||||
{
|
{
|
||||||
$serverUptimeCheckNumber = $this->unreachable_count;
|
$serverUptimeCheckNumber = $this->unreachable_count;
|
||||||
$serverUptimeCheckNumberMax = 3;
|
$serverUptimeCheckNumberMax = 8;
|
||||||
|
|
||||||
$currentTime = now()->timestamp;
|
$currentTime = now()->timestamp;
|
||||||
$runtime = 30;
|
$runtime = 50;
|
||||||
|
|
||||||
$isReady = false;
|
$isReady = false;
|
||||||
// Run for 30 seconds max and check every 5 seconds for 3 times
|
// Run for 50 seconds max and check every 5 seconds for 8 times
|
||||||
while ($currentTime + $runtime > now()->timestamp) {
|
while ($currentTime + $runtime > now()->timestamp) {
|
||||||
|
ray('serverUptimeCheckNumber: ' . $serverUptimeCheckNumber);
|
||||||
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
|
if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) {
|
||||||
if ($this->unreachable_notification_sent === false) {
|
if ($this->unreachable_notification_sent === false) {
|
||||||
ray('Server unreachable, sending notification...');
|
ray('Server unreachable, sending notification...');
|
||||||
@@ -200,7 +201,7 @@ class Server extends BaseModel
|
|||||||
'unreachable_count' => $serverUptimeCheckNumber,
|
'unreachable_count' => $serverUptimeCheckNumber,
|
||||||
]);
|
]);
|
||||||
Sleep::for(5)->seconds();
|
Sleep::for(5)->seconds();
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
$isReady = true;
|
$isReady = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class Unreachable extends Notification implements ShouldQueue
|
|||||||
public function toMail(): MailMessage
|
public function toMail(): MailMessage
|
||||||
{
|
{
|
||||||
$mail = new MailMessage();
|
$mail = new MailMessage();
|
||||||
$mail->subject("Coolify: Server ({$this->server->name}) is unreachable after trying to connect to it 3 times");
|
$mail->subject("Coolify: Your server ({$this->server->name}) is unreachable.");
|
||||||
$mail->view('emails.server-lost-connection', [
|
$mail->view('emails.server-lost-connection', [
|
||||||
'name' => $this->server->name,
|
'name' => $this->server->name,
|
||||||
]);
|
]);
|
||||||
@@ -52,13 +52,13 @@ class Unreachable extends Notification implements ShouldQueue
|
|||||||
|
|
||||||
public function toDiscord(): string
|
public function toDiscord(): string
|
||||||
{
|
{
|
||||||
$message = "Coolify: Server '{$this->server->name}' is unreachable after trying to connect to it 3 times. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server. If your server is back online, we will automatically turn on all automations & integrations.";
|
$message = "Coolify: Your server '{$this->server->name}' is unreachable. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server. If your server is back online, we will automatically turn on all automations & integrations.";
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
public function toTelegram(): array
|
public function toTelegram(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
"message" => "Coolify: Server '{$this->server->name}' is unreachable after trying to connect to it 3 times. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server. If your server is back online, we will automatically turn on all automations & integrations."
|
"message" => "Coolify: Your server '{$this->server->name}' is unreachable. All automations & integrations are turned off! Please check your server! IMPORTANT: We automatically try to revive your server. If your server is back online, we will automatically turn on all automations & integrations."
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1544,6 +1544,9 @@ function generateEnvValue(string $command)
|
|||||||
case 'USER':
|
case 'USER':
|
||||||
$generatedValue = Str::random(16);
|
$generatedValue = Str::random(16);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$generatedValue = Str::random(16);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return $generatedValue;
|
return $generatedValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ return [
|
|||||||
|
|
||||||
// The release version of your application
|
// The release version of your application
|
||||||
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
|
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
|
||||||
'release' => '4.0.0-beta.162',
|
'release' => '4.0.0-beta.164',
|
||||||
// When left empty or `null` the Laravel environment will be used
|
// When left empty or `null` the Laravel environment will be used
|
||||||
'environment' => config('app.env'),
|
'environment' => config('app.env'),
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return '4.0.0-beta.162';
|
return '4.0.0-beta.164';
|
||||||
|
|||||||
@@ -23,20 +23,22 @@
|
|||||||
@if (data_get($application, 'build_pack') === 'dockercompose')
|
@if (data_get($application, 'build_pack') === 'dockercompose')
|
||||||
@foreach (collect(json_decode($this->application->docker_compose_domains)) as $fqdn)
|
@foreach (collect(json_decode($this->application->docker_compose_domains)) as $fqdn)
|
||||||
@if (data_get($fqdn, 'domain'))
|
@if (data_get($fqdn, 'domain'))
|
||||||
<li>
|
@foreach (explode(',', data_get($fqdn, 'domain')) as $domain)
|
||||||
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
|
<li>
|
||||||
target="_blank" href="{{ getFqdnWithoutPort(data_get($fqdn, 'domain')) }}">
|
<a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
|
target="_blank" href="{{ getFqdnWithoutPort($domain) }}">
|
||||||
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
|
||||||
stroke-linejoin="round">
|
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
stroke-linejoin="round">
|
||||||
<path d="M9 15l6 -6" />
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
|
<path d="M9 15l6 -6" />
|
||||||
<path
|
<path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />
|
||||||
d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />
|
<path
|
||||||
</svg>{{ getFqdnWithoutPort(data_get($fqdn, 'domain')) }}
|
d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />
|
||||||
</a>
|
</svg>{{ getFqdnWithoutPort($domain) }}
|
||||||
</li>
|
</a>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -230,14 +230,7 @@
|
|||||||
<li class="step step-secondary">Select a Server</li>
|
<li class="step step-secondary">Select a Server</li>
|
||||||
<li class="step step-secondary">Select a Destination</li>
|
<li class="step step-secondary">Select a Destination</li>
|
||||||
</ul>
|
</ul>
|
||||||
<a wire:navigate href="{{ route('destination.new', ['server_id' => $server_id]) }}"
|
|
||||||
class="items-center justify-center pb-10 text-center box-without-bg group bg-coollabs hover:bg-coollabs-100">
|
|
||||||
<div class="flex flex-col mx-6 ">
|
|
||||||
<div class="font-bold text-white">
|
|
||||||
+ Add New
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<div class="flex flex-col justify-center gap-2 text-left xl:flex-row xl:flex-wrap">
|
<div class="flex flex-col justify-center gap-2 text-left xl:flex-row xl:flex-wrap">
|
||||||
|
|
||||||
@foreach ($standaloneDockers as $standaloneDocker)
|
@foreach ($standaloneDockers as $standaloneDocker)
|
||||||
@@ -260,6 +253,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
<a wire:navigate href="{{ route('destination.new', ['server_id' => $server_id]) }}"
|
||||||
|
class="items-center justify-center pb-10 text-center box-without-bg group bg-coollabs hover:bg-coollabs-100">
|
||||||
|
<div class="flex flex-col mx-6 ">
|
||||||
|
<div class="font-bold text-white">
|
||||||
|
+ Add New
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if ($current_step === 'existing-postgresql')
|
@if ($current_step === 'existing-postgresql')
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ Route::get('/source/github/install', function () {
|
|||||||
});
|
});
|
||||||
Route::post('/source/gitlab/events/manual', function () {
|
Route::post('/source/gitlab/events/manual', function () {
|
||||||
try {
|
try {
|
||||||
|
$return_payloads = collect([]);
|
||||||
$payload = request()->collect();
|
$payload = request()->collect();
|
||||||
$headers = request()->headers->all();
|
$headers = request()->headers->all();
|
||||||
ray($payload, $headers);
|
|
||||||
$x_gitlab_token = data_get($headers, 'x-gitlab-token.0');
|
$x_gitlab_token = data_get($headers, 'x-gitlab-token.0');
|
||||||
$x_gitlab_event = data_get($payload, 'object_kind');
|
$x_gitlab_event = data_get($payload, 'object_kind');
|
||||||
if ($x_gitlab_event === 'push') {
|
if ($x_gitlab_event === 'push') {
|
||||||
@@ -77,20 +77,27 @@ Route::post('/source/gitlab/events/manual', function () {
|
|||||||
$branch = Str::after($branch, 'refs/heads/');
|
$branch = Str::after($branch, 'refs/heads/');
|
||||||
}
|
}
|
||||||
if (!$branch) {
|
if (!$branch) {
|
||||||
return response('Nothing to do. No branch found in the request.');
|
$return_payloads->push([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Nothing to do. No branch found in the request.',
|
||||||
|
]);
|
||||||
|
return response($return_payloads);
|
||||||
}
|
}
|
||||||
ray('Manual Webhook GitLab Push Event with branch: ' . $branch);
|
ray('Manual Webhook GitLab Push Event with branch: ' . $branch);
|
||||||
}
|
}
|
||||||
if ($x_gitlab_event === 'merge_request') {
|
if ($x_gitlab_event === 'merge_request') {
|
||||||
$action = data_get($payload, 'object_attributes.action');
|
$action = data_get($payload, 'object_attributes.action');
|
||||||
ray($action);
|
|
||||||
$branch = data_get($payload, 'object_attributes.source_branch');
|
$branch = data_get($payload, 'object_attributes.source_branch');
|
||||||
$base_branch = data_get($payload, 'object_attributes.target_branch');
|
$base_branch = data_get($payload, 'object_attributes.target_branch');
|
||||||
$full_name = data_get($payload, 'project.path_with_namespace');
|
$full_name = data_get($payload, 'project.path_with_namespace');
|
||||||
$pull_request_id = data_get($payload, 'object_attributes.iid');
|
$pull_request_id = data_get($payload, 'object_attributes.iid');
|
||||||
$pull_request_html_url = data_get($payload, 'object_attributes.url');
|
$pull_request_html_url = data_get($payload, 'object_attributes.url');
|
||||||
if (!$branch) {
|
if (!$branch) {
|
||||||
return response('Nothing to do. No branch found in the request.');
|
$return_payloads->push([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Nothing to do. No branch found in the request.',
|
||||||
|
]);
|
||||||
|
return response($return_payloads);
|
||||||
}
|
}
|
||||||
ray('Webhook GitHub Pull Request Event with branch: ' . $branch . ' and base branch: ' . $base_branch . ' and pull request id: ' . $pull_request_id);
|
ray('Webhook GitHub Pull Request Event with branch: ' . $branch . ' and base branch: ' . $base_branch . ' and pull request id: ' . $pull_request_id);
|
||||||
}
|
}
|
||||||
@@ -98,23 +105,41 @@ Route::post('/source/gitlab/events/manual', function () {
|
|||||||
if ($x_gitlab_event === 'push') {
|
if ($x_gitlab_event === 'push') {
|
||||||
$applications = $applications->where('git_branch', $branch)->get();
|
$applications = $applications->where('git_branch', $branch)->get();
|
||||||
if ($applications->isEmpty()) {
|
if ($applications->isEmpty()) {
|
||||||
return response("Nothing to do. No applications found with deploy key set, branch is '$branch' and Git Repository name has $full_name.");
|
$return_payloads->push([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => "Nothing to do. No applications found with deploy key set, branch is '$branch' and Git Repository name has $full_name.",
|
||||||
|
]);
|
||||||
|
return response($return_payloads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($x_gitlab_event === 'merge_request') {
|
if ($x_gitlab_event === 'merge_request') {
|
||||||
$applications = $applications->where('git_branch', $base_branch)->get();
|
$applications = $applications->where('git_branch', $base_branch)->get();
|
||||||
if ($applications->isEmpty()) {
|
if ($applications->isEmpty()) {
|
||||||
return response("Nothing to do. No applications found with branch '$base_branch'.");
|
$return_payloads->push([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => "Nothing to do. No applications found with branch '$base_branch'.",
|
||||||
|
]);
|
||||||
|
return response($return_payloads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($applications as $application) {
|
foreach ($applications as $application) {
|
||||||
$webhook_secret = data_get($application, 'manual_webhook_secret_gitlab');
|
$webhook_secret = data_get($application, 'manual_webhook_secret_gitlab');
|
||||||
if ($webhook_secret !== $x_gitlab_token) {
|
if ($webhook_secret !== $x_gitlab_token) {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Invalid token.',
|
||||||
|
]);
|
||||||
ray('Invalid signature');
|
ray('Invalid signature');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$isFunctional = $application->destination->server->isFunctional();
|
$isFunctional = $application->destination->server->isFunctional();
|
||||||
if (!$isFunctional) {
|
if (!$isFunctional) {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Server is not functional',
|
||||||
|
]);
|
||||||
ray('Server is not functional: ' . $application->destination->server->name);
|
ray('Server is not functional: ' . $application->destination->server->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -129,6 +154,11 @@ Route::post('/source/gitlab/events/manual', function () {
|
|||||||
is_webhook: true
|
is_webhook: true
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Deployments disabled',
|
||||||
|
]);
|
||||||
ray('Deployments disabled for ' . $application->name);
|
ray('Deployments disabled for ' . $application->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,25 +184,48 @@ Route::post('/source/gitlab/events/manual', function () {
|
|||||||
git_type: 'gitlab'
|
git_type: 'gitlab'
|
||||||
);
|
);
|
||||||
ray('Deploying preview for ' . $application->name . ' with branch ' . $branch . ' and base branch ' . $base_branch . ' and pull request id ' . $pull_request_id);
|
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 {
|
} else {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'Preview deployments disabled',
|
||||||
|
]);
|
||||||
ray('Preview deployments disabled for ' . $application->name);
|
ray('Preview deployments disabled for ' . $application->name);
|
||||||
return response('Nothing to do. Preview Deployments disabled.');
|
|
||||||
}
|
}
|
||||||
}
|
} else if ($action === 'closed') {
|
||||||
if ($action === 'closed') {
|
|
||||||
$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();
|
$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();
|
||||||
if ($found) {
|
if ($found) {
|
||||||
$found->delete();
|
$found->delete();
|
||||||
$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,
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Preview Deployment closed',
|
||||||
|
]);
|
||||||
|
return response($return_payloads);
|
||||||
}
|
}
|
||||||
return response('Nothing to do. No Preview Deployment found');
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'No Preview Deployment found',
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$return_payloads->push([
|
||||||
|
'application' => $application->name,
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'No action found. Contact us for debugging.',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return response($return_payloads);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ray($e->getMessage());
|
ray($e->getMessage());
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"version": "3.12.36"
|
"version": "3.12.36"
|
||||||
},
|
},
|
||||||
"v4": {
|
"v4": {
|
||||||
"version": "4.0.0-beta.162"
|
"version": "4.0.0-beta.164"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user