Skip to content

Commit d6c2c7e

Browse files
authored
Merge branch 'next' into patch-1
2 parents 2af1ccd + 28c320a commit d6c2c7e

File tree

104 files changed

+828
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+828
-234
lines changed

app/Actions/Server/UpdateCoolify.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public function handle($manual_update = false)
3838
}
3939
$this->update();
4040
} catch (\Throwable $e) {
41-
ray('InstanceAutoUpdateJob failed');
42-
ray($e->getMessage());
43-
send_internal_notification('InstanceAutoUpdateJob failed: ' . $e->getMessage());
4441
throw $e;
4542
}
4643
}
@@ -57,7 +54,6 @@ private function update()
5754
"curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh",
5855
"bash /data/coolify/source/upgrade.sh $this->latestVersion"
5956
], $this->server);
60-
send_internal_notification("Instance updated from {$this->currentVersion} -> {$this->latestVersion}");
6157
return;
6258
}
6359
}

app/Console/Commands/ServicesGenerate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class ServicesGenerate extends Command
2626
*/
2727
public function handle()
2828
{
29-
// ray()->clearAll();
3029
$files = array_diff(scandir(base_path('templates/compose')), ['.', '..']);
3130
$files = array_filter($files, function ($file) {
3231
return strpos($file, '.yaml') !== false;
@@ -63,6 +62,7 @@ private function process_file($file)
6362
$documentation = collect(preg_grep('/^# documentation:/', explode("\n", $content)))->values();
6463
if ($documentation->count() > 0) {
6564
$documentation = str($documentation[0])->after('# documentation:')->trim()->value();
65+
$documentation = str($documentation)->append('?utm_source=coolify.io');
6666
} else {
6767
$documentation = 'https://coolify.io/docs';
6868
}

app/Console/Kernel.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
use App\Jobs\CleanupInstanceStuffsJob;
77
use App\Jobs\DatabaseBackupJob;
88
use App\Jobs\ScheduledTaskJob;
9-
use App\Jobs\InstanceAutoUpdateJob;
109
use App\Jobs\ContainerStatusJob;
10+
use App\Jobs\PullCoolifyImageJob;
1111
use App\Jobs\PullHelperImageJob;
1212
use App\Jobs\PullSentinelImageJob;
13-
use App\Jobs\PullTemplatesAndVersions;
1413
use App\Jobs\PullTemplatesFromCDN;
15-
use App\Jobs\PullVersionsFromCDN;
1614
use App\Jobs\ServerStatusJob;
17-
use App\Models\InstanceSettings;
1815
use App\Models\ScheduledDatabaseBackup;
1916
use App\Models\ScheduledTask;
2017
use App\Models\Server;
@@ -32,37 +29,33 @@ protected function schedule(Schedule $schedule): void
3229
// Instance Jobs
3330
$schedule->command('horizon:snapshot')->everyMinute();
3431
$schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
35-
$schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer();
3632
$schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer();
37-
// $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer();
3833
// Server Jobs
3934
$this->check_scheduled_backups($schedule);
4035
$this->check_resources($schedule);
4136
$this->check_scheduled_backups($schedule);
42-
// $this->pull_helper_image($schedule);
4337
$this->check_scheduled_tasks($schedule);
4438
$schedule->command('uploads:clear')->everyTwoMinutes();
4539
} else {
4640
// Instance Jobs
4741
$schedule->command('horizon:snapshot')->everyFiveMinutes();
4842
$schedule->command('cleanup:unreachable-servers')->daily();
49-
$schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer();
50-
$schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer();
43+
$schedule->job(new PullCoolifyImageJob)->everyTenMinutes()->onOneServer();
44+
$schedule->job(new PullTemplatesFromCDN)->everyThirtyMinutes()->onOneServer();
5145
$schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
5246
// $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer();
5347

5448
// Server Jobs
55-
$this->instance_auto_update($schedule);
5649
$this->check_scheduled_backups($schedule);
5750
$this->check_resources($schedule);
58-
$this->pull_helper_image($schedule);
51+
$this->pull_images($schedule);
5952
$this->check_scheduled_tasks($schedule);
6053

6154
$schedule->command('cleanup:database --yes')->daily();
6255
$schedule->command('uploads:clear')->everyTwoMinutes();
6356
}
6457
}
65-
private function pull_helper_image($schedule)
58+
private function pull_images($schedule)
6659
{
6760
$servers = $this->all_servers->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');
6861
foreach ($servers as $server) {
@@ -93,16 +86,6 @@ private function check_resources($schedule)
9386
$schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer();
9487
}
9588
}
96-
private function instance_auto_update($schedule)
97-
{
98-
if (isDev() || isCloud()) {
99-
return;
100-
}
101-
$settings = InstanceSettings::get();
102-
if ($settings->is_auto_update_enabled) {
103-
$schedule->job(new InstanceAutoUpdateJob)->everyTenMinutes()->onOneServer();
104-
}
105-
}
10689
private function check_scheduled_backups($schedule)
10790
{
10891
$scheduled_backups = ScheduledDatabaseBackup::all();

app/Http/Controllers/Webhook/Github.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,12 @@ public function normal(Request $request)
410410
if ($action === 'closed' || $action === 'close') {
411411
$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();
412412
if ($found) {
413-
ApplicationPullRequestUpdateJob::dispatchSync(application: $application, preview: $found, status: ProcessStatus::CLOSED);
414-
$found->delete();
415413
$container_name = generateApplicationContainerName($application, $pull_request_id);
416-
// ray('Stopping container: ' . $container_name);
417414
instant_remote_process(["docker rm -f $container_name"], $application->destination->server);
415+
416+
ApplicationPullRequestUpdateJob::dispatchSync(application: $application, preview: $found, status: ProcessStatus::CLOSED);
417+
$found->delete();
418+
418419
$return_payloads->push([
419420
'application' => $application->name,
420421
'status' => 'success',
@@ -430,7 +431,6 @@ public function normal(Request $request)
430431
}
431432
}
432433
}
433-
ray($return_payloads);
434434
return response($return_payloads);
435435
} catch (Exception $e) {
436436
ray($e->getMessage());

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
113113
public $tries = 1;
114114
public function __construct(int $application_deployment_queue_id)
115115
{
116-
ray()->clearAll();
117116
$this->application_deployment_queue = ApplicationDeploymentQueue::find($application_deployment_queue_id);
118117
$this->application = Application::find($this->application_deployment_queue->application_id);
119118
$this->build_pack = data_get($this->application, 'build_pack');
@@ -290,7 +289,6 @@ private function decide_what_to_do()
290289
}
291290
private function post_deployment()
292291
{
293-
294292
if ($this->server->isProxyShouldRun()) {
295293
GetContainersStatus::dispatch($this->server);
296294
// dispatch(new ContainerStatusJob($this->server));
@@ -347,9 +345,15 @@ private function deploy_docker_compose_buildpack()
347345
}
348346
if (data_get($this->application, 'docker_compose_custom_start_command')) {
349347
$this->docker_compose_custom_start_command = $this->application->docker_compose_custom_start_command;
348+
if (!str($this->docker_compose_custom_start_command)->contains('--project-directory')) {
349+
$this->docker_compose_custom_start_command = str($this->docker_compose_custom_start_command)->replaceFirst('compose', 'compose --project-directory ' . $this->workdir)->value();
350+
}
350351
}
351352
if (data_get($this->application, 'docker_compose_custom_build_command')) {
352353
$this->docker_compose_custom_build_command = $this->application->docker_compose_custom_build_command;
354+
if (!str($this->docker_compose_custom_build_command)->contains('--project-directory')) {
355+
$this->docker_compose_custom_build_command = str($this->docker_compose_custom_build_command)->replaceFirst('compose', 'compose --project-directory ' . $this->workdir)->value();
356+
}
353357
}
354358
if ($this->pull_request_id === 0) {
355359
$this->application_deployment_queue->addLogEntry("Starting deployment of {$this->application->name} to {$this->server->name}.");
@@ -367,7 +371,7 @@ private function deploy_docker_compose_buildpack()
367371
$yaml = $composeFile = $this->application->docker_compose_raw;
368372
$this->save_environment_variables();
369373
} else {
370-
$composeFile = $this->application->parseCompose(pull_request_id: $this->pull_request_id);
374+
$composeFile = $this->application->parseCompose(pull_request_id: $this->pull_request_id, preview_id: data_get($this, 'preview.id'));
371375
$this->save_environment_variables();
372376
if (!is_null($this->env_filename)) {
373377
$services = collect($composeFile['services']);
@@ -1987,7 +1991,7 @@ private function run_pre_deployment_command()
19871991
if ($containers->count() == 0) {
19881992
return;
19891993
}
1990-
$this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output).");
1994+
$this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output/errors).");
19911995

19921996
foreach ($containers as $container) {
19931997
$containerName = data_get($container, 'Names');
@@ -2010,6 +2014,7 @@ private function run_post_deployment_command()
20102014
if (empty($this->application->post_deployment_command)) {
20112015
return;
20122016
}
2017+
$this->application_deployment_queue->addLogEntry("----------------------------------------");
20132018
$this->application_deployment_queue->addLogEntry("Executing post-deployment command (see debug log for output).");
20142019

20152020
$containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id);
@@ -2018,11 +2023,20 @@ private function run_post_deployment_command()
20182023
if ($containers->count() == 1 || str_starts_with($containerName, $this->application->post_deployment_command_container . '-' . $this->application->uuid)) {
20192024
$cmd = "sh -c '" . str_replace("'", "'\''", $this->application->post_deployment_command) . "'";
20202025
$exec = "docker exec {$containerName} {$cmd}";
2021-
$this->execute_remote_command(
2022-
[
2023-
'command' => $exec, 'hidden' => true
2024-
],
2025-
);
2026+
try {
2027+
$this->execute_remote_command(
2028+
[
2029+
'command' => $exec, 'hidden' => true, 'save' => 'post-deployment-command-output'
2030+
],
2031+
);
2032+
} catch (Exception $e) {
2033+
$post_deployment_command_output = $this->saved_outputs->get('post-deployment-command-output');
2034+
if ($post_deployment_command_output) {
2035+
$this->application_deployment_queue->addLogEntry("Post-deployment command failed.");
2036+
$this->application_deployment_queue->addLogEntry($post_deployment_command_output, 'stderr');
2037+
}
2038+
}
2039+
20262040
return;
20272041
}
20282042
}

app/Jobs/ApplicationPullRequestUpdateJob.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function handle()
3131
{
3232
try {
3333
if ($this->application->is_public_repository()) {
34+
ray('Public repository. Skipping comment update.');
3435
return;
3536
}
3637
if ($this->status === ProcessStatus::CLOSED) {
@@ -59,7 +60,7 @@ public function handle()
5960
}
6061
} catch (\Throwable $e) {
6162
ray($e);
62-
throw $e;
63+
return $e;
6364
}
6465
}
6566

app/Jobs/CheckLogDrainContainerJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function handle(): void
8080
}
8181
}
8282
} catch (\Throwable $e) {
83-
send_internal_notification("CheckLogDrainContainerJob failed on ({$this->server->id}) with: " . $e->getMessage());
83+
if (!isCloud()) send_internal_notification("CheckLogDrainContainerJob failed on ({$this->server->id}) with: " . $e->getMessage());
8484
ray($e->getMessage());
85-
handleError($e);
85+
return handleError($e);
8686
}
8787
}
8888
}

app/Jobs/PullCoolifyImageJob.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use App\Models\InstanceSettings;
6+
use App\Models\Server;
7+
use Illuminate\Bus\Queueable;
8+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
10+
use Illuminate\Foundation\Bus\Dispatchable;
11+
use Illuminate\Queue\InteractsWithQueue;
12+
use Illuminate\Queue\SerializesModels;
13+
use Illuminate\Support\Facades\File;
14+
use Illuminate\Support\Facades\Http;
15+
16+
class PullCoolifyImageJob implements ShouldQueue, ShouldBeEncrypted
17+
{
18+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
19+
20+
public $timeout = 1000;
21+
22+
public function __construct()
23+
{
24+
}
25+
public function handle(): void
26+
{
27+
try {
28+
if (isDev() || isCloud()) {
29+
return;
30+
}
31+
$server = Server::findOrFail(0);
32+
$response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');
33+
if ($response->successful()) {
34+
$versions = $response->json();
35+
File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT));
36+
}
37+
$latest_version = get_latest_version_of_coolify();
38+
instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$latest_version}"], $server, false);
39+
40+
$settings = InstanceSettings::get();
41+
$current_version = config('version');
42+
if (!$settings->is_auto_update_enabled) {
43+
return;
44+
}
45+
if ($latest_version === $current_version) {
46+
return;
47+
}
48+
if (version_compare($latest_version, $current_version, '<')) {
49+
return;
50+
}
51+
instant_remote_process([
52+
"curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh",
53+
"bash /data/coolify/source/upgrade.sh $latest_version"
54+
], $server);
55+
} catch (\Throwable $e) {
56+
throw $e;
57+
}
58+
}
59+
}

app/Jobs/PullVersionsFromCDN.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public function handle(): void
3434
}
3535
}
3636
} catch (\Throwable $e) {
37-
send_internal_notification('PullTemplatesAndVersions failed with: ' . $e->getMessage());
38-
ray($e->getMessage());
37+
throw $e;
3938
}
4039
}
4140
}

app/Livewire/Project/Application/Heading.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function getListeners()
2525
return [
2626
"echo-private:team.{$teamId},ApplicationStatusChanged" => 'check_status',
2727
"compose_loaded" => '$refresh',
28+
"update_links" => '$refresh',
2829
];
2930
}
3031
public function mount()

0 commit comments

Comments
 (0)