Skip to content

Commit

Permalink
Merge pull request #4941 from coollabsio/next
Browse files Browse the repository at this point in the history
v4.0.0-beta.390
  • Loading branch information
andrasbacsai authored Jan 28, 2025
2 parents 9a5f1ed + 55fb4e5 commit a768761
Show file tree
Hide file tree
Showing 33 changed files with 369 additions and 249 deletions.
4 changes: 2 additions & 2 deletions app/Actions/Proxy/StartProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function handle(Server $server, bool $async = true, bool $force = false):
$docker_compose_yml_base64 = base64_encode($configuration);
$server->proxy->last_applied_settings = str($docker_compose_yml_base64)->pipe('md5')->value();
$server->save();
if ($server->isSwarm()) {
if ($server->isSwarmManager()) {
$commands = $commands->merge([
"mkdir -p $proxy_path/dynamic",
"cd $proxy_path",
"echo 'Creating required Docker Compose file.'",
"echo 'Starting coolify-proxy.'",
'docker stack deploy -c docker-compose.yml coolify-proxy',
'docker stack deploy --detach=true -c docker-compose.yml coolify-proxy',
"echo 'Successfully started coolify-proxy.'",
]);
} else {
Expand Down
8 changes: 8 additions & 0 deletions app/Console/Commands/CleanupDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function handle()
$application_deployment_queues->delete();
}

// Cleanup scheduled_task_executions table
$scheduled_task_executions = DB::table('scheduled_task_executions')->where('created_at', '<', now()->subDays($keep_days))->orderBy('created_at', 'desc');
$count = $scheduled_task_executions->count();
echo "Delete $count entries from scheduled_task_executions.\n";
if ($this->option('yes')) {
$scheduled_task_executions->delete();
}

// Cleanup webhooks table
$webhooks = DB::table('webhooks')->where('created_at', '<', now()->subDays($keep_days));
$count = $webhooks->count();
Expand Down
12 changes: 9 additions & 3 deletions app/Jobs/ApplicationDeploymentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,11 @@ private function save_environment_variables()
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
$envs->push("COOLIFY_BRANCH=\"{$local_branch}\"");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_RESOURCE_UUID')->isEmpty()) {
$envs->push("COOLIFY_RESOURCE_UUID={$this->application->uuid}");
}
if ($this->application->environment_variables_preview->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$envs->push("COOLIFY_CONTAINER_NAME=\"{$this->container_name}\"");
$envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}");
}
}

Expand Down Expand Up @@ -982,8 +985,11 @@ private function save_environment_variables()
if ($this->application->environment_variables->where('key', 'COOLIFY_BRANCH')->isEmpty()) {
$envs->push("COOLIFY_BRANCH=\"{$local_branch}\"");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_RESOURCE_UUID')->isEmpty()) {
$envs->push("COOLIFY_RESOURCE_UUID={$this->application->uuid}");
}
if ($this->application->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$envs->push("COOLIFY_CONTAINER_NAME=\"{$this->container_name}\"");
$envs->push("COOLIFY_CONTAINER_NAME={$this->container_name}");
}
}

Expand Down Expand Up @@ -1145,7 +1151,7 @@ private function rolling_update()
$this->application_deployment_queue->addLogEntry('Rolling update started.');
$this->execute_remote_command(
[
executeInDocker($this->deployment_uuid, "docker stack deploy --with-registry-auth -c {$this->workdir}{$this->docker_compose_location} {$this->application->uuid}"),
executeInDocker($this->deployment_uuid, "docker stack deploy --detach=true --with-registry-auth -c {$this->workdir}{$this->docker_compose_location} {$this->application->uuid}"),
],
);
$this->application_deployment_queue->addLogEntry('Rolling update completed.');
Expand Down
7 changes: 1 addition & 6 deletions app/Jobs/DatabaseBackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,7 @@ private function upload_to_s3(): void
} else {
$commands[] = "docker run -d --network {$network} --name backup-of-{$this->backup->uuid} --rm -v $this->backup_location:$this->backup_location:ro {$fullImageName}";
}
if ($this->s3->isHetzner()) {
$endpointWithoutBucket = 'https://'.str($endpoint)->after('https://')->after('.')->value();
$commands[] = "docker exec backup-of-{$this->backup->uuid} mc alias set --path=off --api=S3v4 temporary {$endpointWithoutBucket} $key $secret";
} else {
$commands[] = "docker exec backup-of-{$this->backup->uuid} mc config host add temporary {$endpoint} $key $secret";
}
$commands[] = "docker exec backup-of-{$this->backup->uuid} mc config host add temporary {$endpoint} $key $secret";
$commands[] = "docker exec backup-of-{$this->backup->uuid} mc cp $this->backup_location temporary/$bucket{$this->backup_dir}/";
instant_remote_process($commands, $this->server);

Expand Down
18 changes: 17 additions & 1 deletion app/Livewire/Project/Application/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,20 @@ public function syncData(bool $toModel = false)
}
}

private function resetDefaultLabels()
{
if ($this->application->settings->is_container_label_readonly_enabled === false) {
return;
}
$customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
$this->application->custom_labels = base64_encode($customLabels);
$this->application->save();
}

public function instantSave()
{
try {
$reset = false;
if ($this->isLogDrainEnabled) {
if (! $this->application->destination->server->isLogDrainEnabled()) {
$this->isLogDrainEnabled = false;
Expand All @@ -140,7 +151,7 @@ public function instantSave()
$this->application->isGzipEnabled() !== $this->isGzipEnabled ||
$this->application->isStripprefixEnabled() !== $this->isStripprefixEnabled
) {
$this->dispatch('resetDefaultLabels', false);
$reset = true;
}

if ($this->application->settings->is_raw_compose_deployment_enabled) {
Expand All @@ -149,6 +160,11 @@ public function instantSave()
$this->application->parse();
}
$this->syncData(true);

if ($reset) {
$this->resetDefaultLabels();
}

$this->dispatch('success', 'Settings saved.');
$this->dispatch('configurationChanged');
} catch (\Throwable $e) {
Expand Down
3 changes: 3 additions & 0 deletions app/Livewire/Project/Application/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public function instantSave()
});
}
}
if ($this->application->settings->is_container_label_readonly_enabled) {
$this->resetDefaultLabels(false);
}
}

public function loadComposeFile($isInit = false)
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Project/Database/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function runImport()
case \App\Models\StandaloneMongodb::class:
$restoreCommand = $this->mongodbRestoreCommand;
if ($this->dumpAll === false) {
$restoreCommand .= " {$tmpPath}";
$restoreCommand .= "{$tmpPath}";
}
break;
}
Expand Down
7 changes: 6 additions & 1 deletion app/Livewire/Project/Shared/ScheduledTask/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function syncData(bool $toModel = false)
{
if ($toModel) {
$this->validate();
$isValid = validate_cron_expression($this->frequency);
if (! $isValid) {
$this->frequency = $this->task->frequency;
throw new \Exception('Invalid Cron / Human expression.');
}
$this->task->enabled = $this->isEnabled;
$this->task->name = str($this->name)->trim()->value();
$this->task->command = str($this->command)->trim()->value();
Expand Down Expand Up @@ -109,7 +114,7 @@ public function submit()
$this->syncData(true);
$this->dispatch('success', 'Scheduled task updated.');
} catch (\Exception $e) {
return handleError($e);
return handleError($e, $this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/Server/ConfigureCloudflareTunnels.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function submit()
$server->ip = $this->ssh_domain;
$server->save();
$server->settings->save();
$this->dispatch('warning', 'Cloudflare Tunnels configuration started.');
$this->dispatch('info', 'Cloudflare Tunnels configuration started.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
Expand Down
28 changes: 19 additions & 9 deletions app/Livewire/Storage/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire\Storage;

use App\Models\S3Storage;
use Illuminate\Support\Uri;
use Livewire\Component;

class Create extends Component
Expand Down Expand Up @@ -45,15 +46,24 @@ class Create extends Component

public function updatedEndpoint($value)
{
if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) {
$this->endpoint = 'https://'.$value;
$value = $this->endpoint;
}

if (str($value)->contains('your-objectstorage.com') && ! isset($this->bucket)) {
$this->bucket = str($value)->after('//')->before('.');
} elseif (str($value)->contains('your-objectstorage.com')) {
$this->bucket = $this->bucket ?: str($value)->after('//')->before('.');
try {
if (empty($value)) {
return;
}
if (str($value)->contains('digitaloceanspaces.com')) {
$uri = Uri::of($value);
$host = $uri->host();

if (preg_match('/^(.+)\.([^.]+\.digitaloceanspaces\.com)$/', $host, $matches)) {
$host = $matches[2];
$value = "https://{$host}";
}
}
} finally {
if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) {
$value = 'https://'.$value;
}
$this->endpoint = $value;
}
}

Expand Down
10 changes: 0 additions & 10 deletions app/Models/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public function awsUrl()
return "{$this->endpoint}/{$this->bucket}";
}

public function isHetzner()
{
return str($this->endpoint)->contains('your-objectstorage.com');
}

public function isDigitalOcean()
{
return str($this->endpoint)->contains('digitaloceanspaces.com');
}

public function testConnection(bool $shouldSave = false)
{
try {
Expand Down
2 changes: 1 addition & 1 deletion app/Models/ServiceDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function serviceType()
public function databaseType()
{
$image = str($this->image)->before(':');
if ($image->value() === 'postgres') {
if ($image->contains('postgres') || $image->contains('postgis')) {
$image = 'postgresql';
}

Expand Down
1 change: 0 additions & 1 deletion bootstrap/helpers/databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function deleteBackupsS3(string|array|null $filenames, S3Storage $s3): void
'bucket' => $s3->bucket,
'endpoint' => $s3->endpoint,
'use_path_style_endpoint' => true,
'bucket_endpoint' => $s3->isHetzner() || $s3->isDigitalOcean(),
'aws_url' => $s3->awsUrl(),
]);

Expand Down
5 changes: 3 additions & 2 deletions bootstrap/helpers/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ function generate_default_proxy_configuration(Server $server)
'--entryPoints.https.http2.maxConcurrentStreams=50',
'--entrypoints.https.http3',
'--providers.file.directory=/traefik/dynamic/',
'--providers.docker.exposedbydefault=false',
'--providers.file.watch=true',
'--certificatesresolvers.letsencrypt.acme.httpchallenge=true',
'--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http',
Expand All @@ -212,7 +211,8 @@ function generate_default_proxy_configuration(Server $server)
data_forget($config, 'services.traefik.restart');
data_forget($config, 'services.traefik.labels');

$config['services']['traefik']['command'][] = '--providers.docker.swarmMode=true';
$config['services']['traefik']['command'][] = '--providers.swarm.endpoint=unix:///var/run/docker.sock';
$config['services']['traefik']['command'][] = '--providers.swarm.exposedbydefault=false';
$config['services']['traefik']['deploy'] = [
'labels' => $labels,
'placement' => [
Expand All @@ -223,6 +223,7 @@ function generate_default_proxy_configuration(Server $server)
];
} else {
$config['services']['traefik']['command'][] = '--providers.docker=true';
$config['services']['traefik']['command'][] = '--providers.docker.exposedbydefault=false';
}
} elseif ($proxy_type === 'CADDY') {
$config = [
Expand Down
3 changes: 0 additions & 3 deletions bootstrap/helpers/s3.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

function set_s3_target(S3Storage $s3)
{
$is_digital_ocean = false;

config()->set('filesystems.disks.custom-s3', [
'driver' => 's3',
'region' => $s3['region'],
Expand All @@ -14,7 +12,6 @@ function set_s3_target(S3Storage $s3)
'bucket' => $s3['bucket'],
'endpoint' => $s3['endpoint'],
'use_path_style_endpoint' => true,
'bucket_endpoint' => $s3->isHetzner() || $s3->isDigitalOcean(),
'aws_url' => $s3->awsUrl(),
]);
}
8 changes: 7 additions & 1 deletion bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$parsedServiceVariables->put($key, $value);
}
}
$parsedServiceVariables->put('COOLIFY_RESOURCE_UUID', "{$resource->uuid}");
$parsedServiceVariables->put('COOLIFY_CONTAINER_NAME', "$serviceName-{$resource->uuid}");

// TODO: move this in a shared function
Expand Down Expand Up @@ -3606,9 +3607,14 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
}
}

// Add COOLIFY_RESOURCE_UUID to environment
if ($resource->environment_variables->where('key', 'COOLIFY_RESOURCE_UUID')->isEmpty()) {
$coolifyEnvironments->put('COOLIFY_RESOURCE_UUID', "{$resource->uuid}");
}

// Add COOLIFY_CONTAINER_NAME to environment
if ($resource->environment_variables->where('key', 'COOLIFY_CONTAINER_NAME')->isEmpty()) {
$coolifyEnvironments->put('COOLIFY_CONTAINER_NAME', "\"{$containerName}\"");
$coolifyEnvironments->put('COOLIFY_CONTAINER_NAME', "{$containerName}");
}

if ($isApplication) {
Expand Down
2 changes: 1 addition & 1 deletion config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [
'coolify' => [
'version' => '4.0.0-beta.389',
'version' => '4.0.0-beta.390',
'helper_version' => '1.0.6',
'realtime_version' => '1.0.5',
'self_hosted' => env('SELF_HOSTED', true),
Expand Down
Loading

0 comments on commit a768761

Please sign in to comment.