Skip to content

Commit 5fddf01

Browse files
authored
Merge pull request coollabsio#2355 from coollabsio/next
v4.0.0-beta.295
2 parents 88581c8 + c804341 commit 5fddf01

File tree

120 files changed

+1036
-277
lines changed

Some content is hidden

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

120 files changed

+1036
-277
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/Http/Controllers/Webhook/Gitlab.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function manual(Request $request)
202202
]);
203203
ray('Preview deployments disabled for ' . $application->name);
204204
}
205-
} else if ($action === 'closed' || $action === 'close') {
205+
} else if ($action === 'closed' || $action === 'close' || $action === 'merge') {
206206
$found = ApplicationPreview::where('application_id', $application->id)->where('pull_request_id', $pull_request_id)->first();
207207
if ($found) {
208208
$found->delete();

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 43 additions & 12 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']);
@@ -759,7 +763,7 @@ private function save_environment_variables()
759763
if ($env->version === '4.0.0-beta.239') {
760764
$real_value = $env->real_value;
761765
} else {
762-
if ($env->is_literal) {
766+
if ($env->is_literal || $env->is_multiline) {
763767
$real_value = '\'' . $real_value . '\'';
764768
} else {
765769
$real_value = escapeEnvVariables($env->real_value);
@@ -800,10 +804,11 @@ private function save_environment_variables()
800804
if ($env->version === '4.0.0-beta.239') {
801805
$real_value = $env->real_value;
802806
} else {
803-
if ($env->is_literal) {
807+
if ($env->is_literal || $env->is_multiline) {
804808
$real_value = '\'' . $real_value . '\'';
805809
} else {
806810
$real_value = escapeEnvVariables($env->real_value);
811+
ray($real_value);
807812
}
808813
}
809814
$envs->push($env->key . '=' . $real_value);
@@ -1944,11 +1949,17 @@ private function generate_build_env_variables()
19441949
if ($this->pull_request_id === 0) {
19451950
foreach ($this->application->build_environment_variables as $env) {
19461951
$value = escapeshellarg($env->real_value);
1952+
if (str($value)->contains("\n") && data_get($env, 'is_multiline') === true) {
1953+
$value = str_replace("\n", "\\\n", $value);
1954+
}
19471955
$this->build_args->push("--build-arg {$env->key}={$value}");
19481956
}
19491957
} else {
19501958
foreach ($this->application->build_environment_variables_preview as $env) {
19511959
$value = escapeshellarg($env->real_value);
1960+
if (str($value)->contains("\n") && data_get($env, 'is_multiline') === true) {
1961+
$value = str_replace("\n", "\\\n", $value);
1962+
}
19521963
$this->build_args->push("--build-arg {$env->key}={$value}");
19531964
}
19541965
}
@@ -1964,10 +1975,20 @@ private function add_build_env_variables_to_dockerfile()
19641975
$dockerfile = collect(Str::of($this->saved_outputs->get('dockerfile'))->trim()->explode("\n"));
19651976
if ($this->pull_request_id === 0) {
19661977
foreach ($this->application->build_environment_variables as $env) {
1967-
$dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}");
1978+
if (str($env->real_value)->contains("\n") && data_get($env, 'is_multiline') === true) {
1979+
$value = str_replace("\n", "\\\n", $env->real_value);
1980+
} else {
1981+
$value = $env->real_value;
1982+
}
1983+
$dockerfile->splice(1, 0, "ARG {$env->key}={$value}");
19681984
}
19691985
} else {
19701986
foreach ($this->application->build_environment_variables_preview as $env) {
1987+
if (str($env->real_value)->contains("\n") && data_get($env, 'is_multiline') === true) {
1988+
$value = str_replace("\n", "\\\n", $env->real_value);
1989+
} else {
1990+
$value = $env->real_value;
1991+
}
19711992
$dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}");
19721993
}
19731994
}
@@ -1987,7 +2008,7 @@ private function run_pre_deployment_command()
19872008
if ($containers->count() == 0) {
19882009
return;
19892010
}
1990-
$this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output).");
2011+
$this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output/errors).");
19912012

19922013
foreach ($containers as $container) {
19932014
$containerName = data_get($container, 'Names');
@@ -2010,6 +2031,7 @@ private function run_post_deployment_command()
20102031
if (empty($this->application->post_deployment_command)) {
20112032
return;
20122033
}
2034+
$this->application_deployment_queue->addLogEntry("----------------------------------------");
20132035
$this->application_deployment_queue->addLogEntry("Executing post-deployment command (see debug log for output).");
20142036

20152037
$containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id);
@@ -2018,11 +2040,20 @@ private function run_post_deployment_command()
20182040
if ($containers->count() == 1 || str_starts_with($containerName, $this->application->post_deployment_command_container . '-' . $this->application->uuid)) {
20192041
$cmd = "sh -c '" . str_replace("'", "'\''", $this->application->post_deployment_command) . "'";
20202042
$exec = "docker exec {$containerName} {$cmd}";
2021-
$this->execute_remote_command(
2022-
[
2023-
'command' => $exec, 'hidden' => true
2024-
],
2025-
);
2043+
try {
2044+
$this->execute_remote_command(
2045+
[
2046+
'command' => $exec, 'hidden' => true, 'save' => 'post-deployment-command-output'
2047+
],
2048+
);
2049+
} catch (Exception $e) {
2050+
$post_deployment_command_output = $this->saved_outputs->get('post-deployment-command-output');
2051+
if ($post_deployment_command_output) {
2052+
$this->application_deployment_queue->addLogEntry("Post-deployment command failed.");
2053+
$this->application_deployment_queue->addLogEntry($post_deployment_command_output, 'stderr');
2054+
}
2055+
}
2056+
20262057
return;
20272058
}
20282059
}

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
}

0 commit comments

Comments
 (0)