Skip to content

Commit f21c12f

Browse files
authored
Merge pull request coollabsio#2856 from coollabsio/next
v4.0.0-beta.316
2 parents c37398a + 6c1e50a commit f21c12f

27 files changed

+433
-268
lines changed

.github/ISSUE_TEMPLATE/BUG_REPORT.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Bug report
2-
description: 'Create a new bug report.'
3-
title: '[Bug]: '
2+
description: "Create a new bug report."
3+
title: "[Bug]: "
44
body:
55
- type: markdown
66
attributes:
@@ -35,3 +35,12 @@ body:
3535
description: Coolify's version (see top of your screen).
3636
validations:
3737
required: true
38+
- type: checkboxes
39+
attributes:
40+
label: Cloud?
41+
description: "Are you using the cloud version of Coolify?"
42+
options:
43+
- label: Yes
44+
required: false
45+
- label: No
46+
required: false

app/Console/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Jobs\CleanupInstanceStuffsJob;
77
use App\Jobs\ContainerStatusJob;
88
use App\Jobs\DatabaseBackupJob;
9+
use App\Jobs\DockerCleanupJob;
910
use App\Jobs\PullCoolifyImageJob;
1011
use App\Jobs\PullHelperImageJob;
1112
use App\Jobs\PullSentinelImageJob;
@@ -87,6 +88,7 @@ private function check_resources($schedule)
8788
}
8889
foreach ($servers as $server) {
8990
$schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer();
91+
$schedule->job(new DockerCleanupJob($server))->everyTenMinutes()->onOneServer();
9092
}
9193
}
9294

app/Http/Controllers/Api/ApplicationsController.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,10 @@ private function create_application(Request $request, $type)
732732
$application->environment_id = $environment->id;
733733
$application->save();
734734
$application->refresh();
735-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
736-
$application->save();
735+
if (! $application->settings->is_container_label_readonly_enabled) {
736+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
737+
$application->save();
738+
}
737739
$application->isConfigurationChanged(true);
738740

739741
if ($instantDeploy) {
@@ -826,8 +828,10 @@ private function create_application(Request $request, $type)
826828
$application->source_id = $githubApp->id;
827829
$application->save();
828830
$application->refresh();
829-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
830-
$application->save();
831+
if (! $application->settings->is_container_label_readonly_enabled) {
832+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
833+
$application->save();
834+
}
831835
$application->isConfigurationChanged(true);
832836

833837
if ($instantDeploy) {
@@ -916,8 +920,10 @@ private function create_application(Request $request, $type)
916920
$application->environment_id = $environment->id;
917921
$application->save();
918922
$application->refresh();
919-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
920-
$application->save();
923+
if (! $application->settings->is_container_label_readonly_enabled) {
924+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
925+
$application->save();
926+
}
921927
$application->isConfigurationChanged(true);
922928

923929
if ($instantDeploy) {
@@ -996,8 +1002,10 @@ private function create_application(Request $request, $type)
9961002
$application->git_branch = 'main';
9971003
$application->save();
9981004
$application->refresh();
999-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1000-
$application->save();
1005+
if (! $application->settings->is_container_label_readonly_enabled) {
1006+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1007+
$application->save();
1008+
}
10011009
$application->isConfigurationChanged(true);
10021010

10031011
if ($instantDeploy) {
@@ -1052,8 +1060,10 @@ private function create_application(Request $request, $type)
10521060
$application->git_branch = 'main';
10531061
$application->save();
10541062
$application->refresh();
1055-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1056-
$application->save();
1063+
if (! $application->settings->is_container_label_readonly_enabled) {
1064+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1065+
$application->save();
1066+
}
10571067
$application->isConfigurationChanged(true);
10581068

10591069
if ($instantDeploy) {
@@ -1494,8 +1504,10 @@ public function update_by_uuid(Request $request)
14941504
$fqdn = str($fqdn)->replaceEnd(',', '')->trim();
14951505
$fqdn = str($fqdn)->replaceStart(',', '')->trim();
14961506
$application->fqdn = $fqdn;
1497-
$customLabels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1498-
$application->custom_labels = base64_encode($customLabels);
1507+
if (! $application->settings->is_container_label_readonly_enabled) {
1508+
$customLabels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1509+
$application->custom_labels = base64_encode($customLabels);
1510+
}
14991511
$request->offsetUnset('domains');
15001512
}
15011513

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
157157

158158
private ?string $coolify_variables = null;
159159

160+
private bool $preserveRepository = true;
161+
160162
public $tries = 1;
161163

162164
public function __construct(int $application_deployment_queue_id)
@@ -187,6 +189,7 @@ public function __construct(int $application_deployment_queue_id)
187189
$this->server = $this->mainServer = $this->destination->server;
188190
$this->serverUser = $this->server->user;
189191
$this->is_this_additional_server = $this->application->additional_servers()->wherePivot('server_id', $this->server->id)->count() > 0;
192+
$this->preserveRepository = $this->application->settings->is_preserve_repository_enabled;
190193

191194
$this->basedir = $this->application->generateBaseDir($this->deployment_uuid);
192195
$this->workdir = "{$this->basedir}".rtrim($this->application->base_directory, '/');
@@ -296,13 +299,13 @@ public function handle(): void
296299
} else {
297300
$this->write_deployment_configurations();
298301
}
299-
$this->execute_remote_command(
300-
[
301-
"docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
302-
'hidden' => true,
303-
'ignore_errors' => true,
304-
]
305-
);
302+
// $this->execute_remote_command(
303+
// [
304+
// "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
305+
// 'hidden' => true,
306+
// 'ignore_errors' => true,
307+
// ]
308+
// );
306309

307310
// $this->execute_remote_command(
308311
// [
@@ -517,6 +520,8 @@ private function deploy_docker_compose_buildpack()
517520
$command .= " --env-file {$this->workdir}/{$this->env_filename}";
518521
}
519522
$command .= " --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d";
523+
ray($command);
524+
520525
$this->execute_remote_command(
521526
[executeInDocker($this->deployment_uuid, $command), 'hidden' => true],
522527
);
@@ -605,6 +610,28 @@ private function deploy_static_buildpack()
605610

606611
private function write_deployment_configurations()
607612
{
613+
if ($this->preserveRepository) {
614+
if ($this->use_build_server) {
615+
$this->server = $this->original_server;
616+
}
617+
if (str($this->configuration_dir)->isNotEmpty()) {
618+
ray("docker cp {$this->deployment_uuid}:{$this->workdir} {$this->configuration_dir}");
619+
$this->execute_remote_command(
620+
[
621+
"mkdir -p $this->configuration_dir",
622+
],
623+
[
624+
"rm -rf $this->configuration_dir/{*,.*}",
625+
],
626+
[
627+
"docker cp {$this->deployment_uuid}:{$this->workdir}/. {$this->configuration_dir}",
628+
],
629+
);
630+
}
631+
if ($this->use_build_server) {
632+
$this->server = $this->build_server;
633+
}
634+
}
608635
if (isset($this->docker_compose_base64)) {
609636
if ($this->use_build_server) {
610637
$this->server = $this->original_server;
@@ -1007,7 +1034,7 @@ private function rolling_update()
10071034
if ((bool) $this->application->settings->is_consistent_container_name_enabled) {
10081035
$this->application_deployment_queue->addLogEntry('Consistent container name feature enabled, rolling update is not supported.');
10091036
}
1010-
if (isset($this->application->settings->custom_internal_name)) {
1037+
if (str($this->application->settings->custom_internal_name)->isNotEmpty()) {
10111038
$this->application_deployment_queue->addLogEntry('Custom internal name is set, rolling update is not supported.');
10121039
}
10131040
if ($this->pull_request_id !== 0) {
@@ -1523,7 +1550,9 @@ private function generate_compose_file()
15231550
$this->application->custom_labels = base64_encode($labels->implode("\n"));
15241551
$this->application->save();
15251552
} else {
1526-
$labels = collect(generateLabelsApplication($this->application, $this->preview));
1553+
if (! $this->application->settings->is_container_label_readonly_enabled) {
1554+
$labels = collect(generateLabelsApplication($this->application, $this->preview));
1555+
}
15271556
}
15281557
if ($this->pull_request_id !== 0) {
15291558
$labels = collect(generateLabelsApplication($this->application, $this->preview));

app/Jobs/DockerCleanupJob.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,55 +12,55 @@
1212
use Illuminate\Queue\InteractsWithQueue;
1313
use Illuminate\Queue\SerializesModels;
1414
use Illuminate\Support\Facades\Log;
15-
use RuntimeException;
1615

1716
class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueue
1817
{
1918
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2019

2120
public $timeout = 300;
2221

23-
public ?int $usageBefore = null;
22+
public int|string|null $usageBefore = null;
2423

2524
public function __construct(public Server $server) {}
2625

2726
public function handle(): void
2827
{
2928
try {
30-
$isInprogress = false;
31-
$this->server->applications()->each(function ($application) use (&$isInprogress) {
32-
if ($application->isDeploymentInprogress()) {
33-
$isInprogress = true;
29+
// $isInprogress = false;
30+
// $this->server->applications()->each(function ($application) use (&$isInprogress) {
31+
// if ($application->isDeploymentInprogress()) {
32+
// $isInprogress = true;
3433

35-
return;
36-
}
37-
});
34+
// return;
35+
// }
36+
// });
3837
// if ($isInprogress) {
3938
// throw new RuntimeException('DockerCleanupJob: ApplicationDeploymentQueue is not empty, skipping...');
4039
// }
4140
if (! $this->server->isFunctional()) {
4241
return;
4342
}
43+
if ($this->server->settings->is_force_cleanup_enabled) {
44+
Log::info('DockerCleanupJob force cleanup on '.$this->server->name);
45+
CleanupDocker::run(server: $this->server, force: true);
46+
47+
return;
48+
}
49+
4450
$this->usageBefore = $this->server->getDiskUsage();
45-
ray('Usage before: '.$this->usageBefore);
4651
if ($this->usageBefore >= $this->server->settings->cleanup_after_percentage) {
47-
ray('Cleaning up '.$this->server->name);
48-
CleanupDocker::run($this->server);
52+
CleanupDocker::run(server: $this->server, force: false);
4953
$usageAfter = $this->server->getDiskUsage();
5054
if ($usageAfter < $this->usageBefore) {
5155
$this->server->team?->notify(new DockerCleanup($this->server, 'Saved '.($this->usageBefore - $usageAfter).'% disk space.'));
52-
// ray('Saved ' . ($this->usageBefore - $usageAfter) . '% disk space on ' . $this->server->name);
53-
// send_internal_notification('DockerCleanupJob done: Saved ' . ($this->usageBefore - $usageAfter) . '% disk space on ' . $this->server->name);
5456
Log::info('DockerCleanupJob done: Saved '.($this->usageBefore - $usageAfter).'% disk space on '.$this->server->name);
5557
} else {
5658
Log::info('DockerCleanupJob failed to save disk space on '.$this->server->name);
5759
}
5860
} else {
59-
ray('No need to clean up '.$this->server->name);
6061
Log::info('No need to clean up '.$this->server->name);
6162
}
6263
} catch (\Throwable $e) {
63-
// send_internal_notification('DockerCleanupJob failed with: '.$e->getMessage());
6464
ray($e->getMessage());
6565
throw $e;
6666
}

app/Jobs/ServerStatusJob.php

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Jobs;
44

55
use App\Models\Server;
6-
use App\Notifications\Server\HighDiskUsage;
76
use Illuminate\Bus\Queueable;
87
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
98
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -44,7 +43,6 @@ public function handle()
4443
}
4544
try {
4645
if ($this->server->isFunctional()) {
47-
$this->cleanup(notify: false);
4846
$this->remove_unnecessary_coolify_yaml();
4947
if ($this->server->isSentinelEnabled()) {
5048
$this->server->checkSentinel();
@@ -56,45 +54,7 @@ public function handle()
5654

5755
return handleError($e);
5856
}
59-
try {
60-
// $this->check_docker_engine();
61-
} catch (\Throwable $e) {
62-
// Do nothing
63-
}
64-
}
65-
66-
private function check_docker_engine()
67-
{
68-
$version = instant_remote_process([
69-
'docker info',
70-
], $this->server, false);
71-
if (is_null($version)) {
72-
$os = instant_remote_process([
73-
'cat /etc/os-release | grep ^ID=',
74-
], $this->server, false);
75-
$os = str($os)->after('ID=')->trim();
76-
if ($os === 'ubuntu') {
77-
try {
78-
instant_remote_process([
79-
'systemctl start docker',
80-
], $this->server);
81-
} catch (\Throwable $e) {
82-
ray($e->getMessage());
8357

84-
return handleError($e);
85-
}
86-
} else {
87-
try {
88-
instant_remote_process([
89-
'service docker start',
90-
], $this->server);
91-
} catch (\Throwable $e) {
92-
ray($e->getMessage());
93-
94-
return handleError($e);
95-
}
96-
}
97-
}
9858
}
9959

10060
private function remove_unnecessary_coolify_yaml()
@@ -108,28 +68,4 @@ private function remove_unnecessary_coolify_yaml()
10868
], $this->server, false);
10969
}
11070
}
111-
112-
public function cleanup(bool $notify = false): void
113-
{
114-
$this->disk_usage = $this->server->getDiskUsage();
115-
if ($this->disk_usage >= $this->server->settings->cleanup_after_percentage) {
116-
if ($notify) {
117-
if ($this->server->high_disk_usage_notification_sent) {
118-
ray('high disk usage notification already sent');
119-
120-
return;
121-
} else {
122-
$this->server->high_disk_usage_notification_sent = true;
123-
$this->server->save();
124-
$this->server->team?->notify(new HighDiskUsage($this->server, $this->disk_usage, $this->server->settings->cleanup_after_percentage));
125-
}
126-
} else {
127-
DockerCleanupJob::dispatchSync($this->server);
128-
$this->cleanup(notify: true);
129-
}
130-
} else {
131-
$this->server->high_disk_usage_notification_sent = false;
132-
$this->server->save();
133-
}
134-
}
13571
}

0 commit comments

Comments
 (0)