+
diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php
index 981b81378..926d30fe6 100644
--- a/app/Actions/CoolifyTask/RunRemoteProcess.php
+++ b/app/Actions/CoolifyTask/RunRemoteProcess.php
@@ -91,16 +91,9 @@ class RunRemoteProcess
} else {
if ($processResult->exitCode() == 0) {
$status = ProcessStatus::FINISHED;
- }
- if ($processResult->exitCode() != 0 && ! $this->ignore_errors) {
+ } else {
$status = ProcessStatus::ERROR;
}
- // if (($processResult->exitCode() == 0 && $this->is_finished) || $this->activity->properties->get('status') === ProcessStatus::FINISHED->value) {
- // $status = ProcessStatus::FINISHED;
- // }
- // if ($processResult->exitCode() != 0 && !$this->ignore_errors) {
- // $status = ProcessStatus::ERROR;
- // }
}
$this->activity->properties = $this->activity->properties->merge([
@@ -110,9 +103,6 @@ class RunRemoteProcess
'status' => $status->value,
]);
$this->activity->save();
- if ($processResult->exitCode() != 0 && ! $this->ignore_errors) {
- throw new \RuntimeException($processResult->errorOutput(), $processResult->exitCode());
- }
if ($this->call_event_on_finish) {
try {
if ($this->call_event_data) {
@@ -128,6 +118,9 @@ class RunRemoteProcess
Log::error('Error calling event: '.$e->getMessage());
}
}
+ if ($processResult->exitCode() != 0 && ! $this->ignore_errors) {
+ throw new \RuntimeException($processResult->errorOutput(), $processResult->exitCode());
+ }
return $processResult;
}
diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php
index 42c6e1449..f218fcabb 100644
--- a/app/Actions/Database/StartClickhouse.php
+++ b/app/Actions/Database/StartClickhouse.php
@@ -49,11 +49,7 @@ class StartClickhouse
'hard' => 262144,
],
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "clickhouse-client --password {$this->database->clickhouse_admin_password} --query 'SELECT 1'",
'interval' => '5s',
diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php
index 3ddf6c036..d9272356c 100644
--- a/app/Actions/Database/StartDatabaseProxy.php
+++ b/app/Actions/Database/StartDatabaseProxy.php
@@ -67,6 +67,10 @@ class StartDatabaseProxy
$type = \App\Models\StandaloneClickhouse::class;
$containerName = "clickhouse-{$database->service->uuid}";
break;
+ case 'standalone-supabase/postgres':
+ $type = \App\Models\StandalonePostgresql::class;
+ $containerName = "supabase-db-{$database->service->uuid}";
+ break;
}
}
if ($type === \App\Models\StandaloneRedis::class) {
diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php
index ea235be4e..4f9f45b7c 100644
--- a/app/Actions/Database/StartDragonfly.php
+++ b/app/Actions/Database/StartDragonfly.php
@@ -46,11 +46,7 @@ class StartDragonfly
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "redis-cli -a {$this->database->dragonfly_password} ping",
'interval' => '5s',
diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php
index 010bf5884..6c733d318 100644
--- a/app/Actions/Database/StartKeydb.php
+++ b/app/Actions/Database/StartKeydb.php
@@ -48,11 +48,7 @@ class StartKeydb
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "keydb-cli --pass {$this->database->keydb_password} ping",
'interval' => '5s',
diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php
index 2437a013e..299b07385 100644
--- a/app/Actions/Database/StartMariadb.php
+++ b/app/Actions/Database/StartMariadb.php
@@ -43,11 +43,7 @@ class StartMariadb
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized'],
'interval' => '5s',
diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php
index a33e72c27..89d35ca7b 100644
--- a/app/Actions/Database/StartMongodb.php
+++ b/app/Actions/Database/StartMongodb.php
@@ -51,11 +51,7 @@ class StartMongodb
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD',
diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php
index 0b19b3f0c..73db1512a 100644
--- a/app/Actions/Database/StartMysql.php
+++ b/app/Actions/Database/StartMysql.php
@@ -43,11 +43,7 @@ class StartMysql
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => ['CMD', 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', "-p{$this->database->mysql_root_password}"],
'interval' => '5s',
diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php
index 7faa232c3..035849340 100644
--- a/app/Actions/Database/StartPostgresql.php
+++ b/app/Actions/Database/StartPostgresql.php
@@ -23,6 +23,9 @@ class StartPostgresql
$this->database = $database;
$container_name = $this->database->uuid;
$this->configuration_dir = database_configuration_dir().'/'.$container_name;
+ if (isDev()) {
+ $this->configuration_dir = '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/databases/'.$container_name;
+ }
$this->commands = [
"echo 'Starting database.'",
@@ -47,11 +50,7 @@ class StartPostgresql
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD-SHELL',
@@ -78,7 +77,7 @@ class StartPostgresql
],
],
];
- if (! is_null($this->database->limits_cpuset)) {
+ if (filled($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
@@ -108,7 +107,7 @@ class StartPostgresql
];
}
}
- if (! is_null($this->database->postgres_conf) && ! empty($this->database->postgres_conf)) {
+ if (filled($this->database->postgres_conf)) {
$docker_compose['services'][$container_name]['volumes'][] = [
'type' => 'bind',
'source' => $this->configuration_dir.'/custom-postgres.conf',
@@ -199,9 +198,12 @@ class StartPostgresql
private function generate_init_scripts()
{
- if (is_null($this->database->init_scripts) || count($this->database->init_scripts) === 0) {
+ $this->commands[] = "rm -rf $this->configuration_dir/docker-entrypoint-initdb.d/*";
+
+ if (blank($this->database->init_scripts) || count($this->database->init_scripts) === 0) {
return;
}
+
foreach ($this->database->init_scripts as $init_script) {
$filename = data_get($init_script, 'filename');
$content = data_get($init_script, 'content');
@@ -213,10 +215,15 @@ class StartPostgresql
private function add_custom_conf()
{
- if (is_null($this->database->postgres_conf) || empty($this->database->postgres_conf)) {
+ $filename = 'custom-postgres.conf';
+ $config_file_path = "$this->configuration_dir/$filename";
+
+ if (blank($this->database->postgres_conf)) {
+ $this->commands[] = "rm -f $config_file_path";
+
return;
}
- $filename = 'custom-postgres.conf';
+
$content = $this->database->postgres_conf;
if (! str($content)->contains('listen_addresses')) {
$content .= "\nlisten_addresses = '*'";
@@ -224,6 +231,6 @@ class StartPostgresql
$this->database->save();
}
$content_base64 = base64_encode($content);
- $this->commands[] = "echo '{$content_base64}' | base64 -d | tee $this->configuration_dir/{$filename} > /dev/null";
+ $this->commands[] = "echo '{$content_base64}' | base64 -d | tee $config_file_path > /dev/null";
}
}
diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php
index bacf49f82..1beebd134 100644
--- a/app/Actions/Database/StartRedis.php
+++ b/app/Actions/Database/StartRedis.php
@@ -48,11 +48,7 @@ class StartRedis
'networks' => [
$this->database->destination->network,
],
- 'labels' => [
- 'coolify.managed' => 'true',
- 'coolify.type' => 'database',
- 'coolify.databaseId' => $this->database->id,
- ],
+ 'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD-SHELL',
diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php
index 706356930..c0e088203 100644
--- a/app/Actions/Docker/GetContainersStatus.php
+++ b/app/Actions/Docker/GetContainersStatus.php
@@ -112,7 +112,7 @@ class GetContainersStatus
$preview->update(['last_online_at' => now()]);
}
} else {
- //Notify user that this container should not be there.
+ // Notify user that this container should not be there.
}
} else {
$application = $this->applications->where('id', $applicationId)->first();
@@ -125,7 +125,7 @@ class GetContainersStatus
$application->update(['last_online_at' => now()]);
}
} else {
- //Notify user that this container should not be there.
+ // Notify user that this container should not be there.
}
}
} else {
diff --git a/app/Console/Commands/CleanupStuckedResources.php b/app/Console/Commands/CleanupStuckedResources.php
index def3d5a2c..0b5eef84d 100644
--- a/app/Console/Commands/CleanupStuckedResources.php
+++ b/app/Console/Commands/CleanupStuckedResources.php
@@ -39,6 +39,11 @@ class CleanupStuckedResources extends Command
$servers = Server::all()->filter(function ($server) {
return $server->isFunctional();
});
+ if (isCloud()) {
+ $servers = $servers->filter(function ($server) {
+ return data_get($server->team->subscription, 'stripe_invoice_paid', false) === true;
+ });
+ }
foreach ($servers as $server) {
CleanupHelperContainersJob::dispatch($server);
}
diff --git a/app/Console/Commands/Emails.php b/app/Console/Commands/Emails.php
index 33ddf3019..a022d54dc 100644
--- a/app/Console/Commands/Emails.php
+++ b/app/Console/Commands/Emails.php
@@ -183,7 +183,7 @@ class Emails extends Command
'team_id' => 0,
]);
}
- //$this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
+ // $this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
$this->sendEmail();
break;
// case 'invitation-link':
diff --git a/app/Console/Commands/HorizonManage.php b/app/Console/Commands/HorizonManage.php
new file mode 100644
index 000000000..ca2da147c
--- /dev/null
+++ b/app/Console/Commands/HorizonManage.php
@@ -0,0 +1,178 @@
+option('can-i-restart-this-worker')) {
+ return $this->isThereAJobInProgress();
+ }
+
+ if ($this->option('job-status')) {
+ return $this->getJobStatus($this->option('job-status'));
+ }
+
+ $action = select(
+ label: 'What to do?',
+ options: [
+ 'pending' => 'Pending Jobs',
+ 'running' => 'Running Jobs',
+ 'can-i-restart-this-worker' => 'Can I restart this worker?',
+ 'job-status' => 'Job Status',
+ 'workers' => 'Workers',
+ 'failed' => 'Failed Jobs',
+ 'failed-delete' => 'Failed Jobs - Delete',
+ 'purge-queues' => 'Purge Queues',
+ ]
+ );
+
+ if ($action === 'can-i-restart-this-worker') {
+ $this->isThereAJobInProgress();
+ }
+
+ if ($action === 'job-status') {
+ $jobId = text('Which job to check?');
+ $jobStatus = $this->getJobStatus($jobId);
+ $this->info('Job Status: '.$jobStatus);
+ }
+
+ if ($action === 'pending') {
+ $pendingJobs = app(JobRepository::class)->getPending();
+ $pendingJobsTable = [];
+ if (count($pendingJobs) === 0) {
+ $this->info('No pending jobs found.');
+
+ return;
+ }
+ foreach ($pendingJobs as $pendingJob) {
+ $pendingJobsTable[] = [
+ 'id' => $pendingJob->id,
+ 'name' => $pendingJob->name,
+ 'status' => $pendingJob->status,
+ 'reserved_at' => $pendingJob->reserved_at ? now()->parse($pendingJob->reserved_at)->format('Y-m-d H:i:s') : null,
+ ];
+ }
+ table($pendingJobsTable);
+ }
+
+ if ($action === 'failed') {
+ $failedJobs = app(JobRepository::class)->getFailed();
+ $failedJobsTable = [];
+ if (count($failedJobs) === 0) {
+ $this->info('No failed jobs found.');
+
+ return;
+ }
+ foreach ($failedJobs as $failedJob) {
+ $failedJobsTable[] = [
+ 'id' => $failedJob->id,
+ 'name' => $failedJob->name,
+ 'failed_at' => $failedJob->failed_at ? now()->parse($failedJob->failed_at)->format('Y-m-d H:i:s') : null,
+ ];
+ }
+ table($failedJobsTable);
+ }
+
+ if ($action === 'failed-delete') {
+ $failedJobs = app(JobRepository::class)->getFailed();
+ $failedJobsTable = [];
+ foreach ($failedJobs as $failedJob) {
+ $failedJobsTable[] = [
+ 'id' => $failedJob->id,
+ 'name' => $failedJob->name,
+ 'failed_at' => $failedJob->failed_at ? now()->parse($failedJob->failed_at)->format('Y-m-d H:i:s') : null,
+ ];
+ }
+ app(MetricsRepository::class)->clear();
+ if (count($failedJobsTable) === 0) {
+ $this->info('No failed jobs found.');
+
+ return;
+ }
+ $jobIds = multiselect(
+ label: 'Which job to delete?',
+ options: collect($failedJobsTable)->mapWithKeys(fn ($job) => [$job['id'] => $job['id'].' - '.$job['name']])->toArray(),
+ );
+ foreach ($jobIds as $jobId) {
+ Artisan::queue('horizon:forget', ['id' => $jobId]);
+ }
+ }
+
+ if ($action === 'running') {
+ $redisJobRepository = app(CustomJobRepository::class);
+ $runningJobs = $redisJobRepository->getReservedJobs();
+ $runningJobsTable = [];
+ if (count($runningJobs) === 0) {
+ $this->info('No running jobs found.');
+
+ return;
+ }
+ foreach ($runningJobs as $runningJob) {
+ $runningJobsTable[] = [
+ 'id' => $runningJob->id,
+ 'name' => $runningJob->name,
+ 'reserved_at' => $runningJob->reserved_at ? now()->parse($runningJob->reserved_at)->format('Y-m-d H:i:s') : null,
+ ];
+ }
+ table($runningJobsTable);
+ }
+
+ if ($action === 'workers') {
+ $redisJobRepository = app(CustomJobRepository::class);
+ $workers = $redisJobRepository->getHorizonWorkers();
+ $workersTable = [];
+ foreach ($workers as $worker) {
+ $workersTable[] = [
+ 'name' => $worker->name,
+ ];
+ }
+ table($workersTable);
+ }
+
+ if ($action === 'purge-queues') {
+ $getQueues = app(CustomJobRepository::class)->getQueues();
+ $queueName = select(
+ label: 'Which queue to purge?',
+ options: $getQueues,
+ );
+ $redisJobRepository = app(RedisJobRepository::class);
+ $redisJobRepository->purge($queueName);
+ }
+ }
+
+ public function isThereAJobInProgress()
+ {
+ $runningJobs = ApplicationDeploymentQueue::where('horizon_job_worker', gethostname())->where('status', ApplicationDeploymentStatus::IN_PROGRESS->value)->get();
+ $count = $runningJobs->count();
+ if ($count === 0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public function getJobStatus(string $jobId)
+ {
+ return getJobStatus($jobId);
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 2ed3ee454..8b4240412 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -91,7 +91,13 @@ class Kernel extends ConsoleKernel
private function pullImages(): void
{
- $servers = $this->allServers->whereRelation('settings', 'is_usable', true)->whereRelation('settings', 'is_reachable', true)->get();
+ if (isCloud()) {
+ $servers = $this->allServers->whereRelation('team.subscription', 'stripe_invoice_paid', true)->whereRelation('settings', 'is_usable', true)->whereRelation('settings', 'is_reachable', true)->get();
+ $own = Team::find(0)->servers;
+ $servers = $servers->merge($own);
+ } else {
+ $servers = $this->allServers->whereRelation('settings', 'is_usable', true)->whereRelation('settings', 'is_reachable', true)->get();
+ }
foreach ($servers as $server) {
if ($server->isSentinelEnabled()) {
$this->scheduleInstance->job(function () use ($server) {
@@ -124,7 +130,7 @@ class Kernel extends ConsoleKernel
private function checkResources(): void
{
if (isCloud()) {
- $servers = $this->allServers->whereHas('team.subscription')->get();
+ $servers = $this->allServers->whereRelation('team.subscription', 'stripe_invoice_paid', true)->get();
$own = Team::find(0)->servers;
$servers = $servers->merge($own);
} else {
@@ -133,14 +139,14 @@ class Kernel extends ConsoleKernel
foreach ($servers as $server) {
$serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
+ if (validate_timezone($serverTimezone) === false) {
+ $serverTimezone = config('app.timezone');
+ }
// Sentinel check
$lastSentinelUpdate = $server->sentinel_updated_at;
if (Carbon::parse($lastSentinelUpdate)->isBefore(now()->subSeconds($server->waitBeforeDoingSshCheck()))) {
// Check container status every minute if Sentinel does not activated
- if (validate_timezone($serverTimezone) === false) {
- $serverTimezone = config('app.timezone');
- }
if (isCloud()) {
$this->scheduleInstance->job(new ServerCheckJob($server))->timezone($serverTimezone)->everyFiveMinutes()->onOneServer();
} else {
@@ -148,15 +154,11 @@ class Kernel extends ConsoleKernel
}
// $this->scheduleInstance->job(new \App\Jobs\ServerCheckNewJob($server))->everyFiveMinutes()->onOneServer();
- // Check storage usage every 10 minutes if Sentinel does not activated
- $this->scheduleInstance->job(new ServerStorageCheckJob($server))->everyTenMinutes()->onOneServer();
- }
- if ($server->settings->force_docker_cleanup) {
- $this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();
- } else {
- $this->scheduleInstance->job(new DockerCleanupJob($server))->everyTenMinutes()->timezone($serverTimezone)->onOneServer();
+ $this->scheduleInstance->job(new ServerStorageCheckJob($server))->cron($server->settings->server_disk_usage_check_frequency)->timezone($serverTimezone)->onOneServer();
}
+ $this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();
+
// Cleanup multiplexed connections every hour
// $this->scheduleInstance->job(new ServerCleanupMux($server))->hourly()->onOneServer();
@@ -175,25 +177,47 @@ class Kernel extends ConsoleKernel
if ($scheduled_backups->isEmpty()) {
return;
}
+ $finalScheduledBackups = collect();
foreach ($scheduled_backups as $scheduled_backup) {
- if (is_null(data_get($scheduled_backup, 'database'))) {
+ if (blank(data_get($scheduled_backup, 'database'))) {
$scheduled_backup->delete();
continue;
}
+ $server = $scheduled_backup->server();
+ if (blank($server)) {
+ $scheduled_backup->delete();
+
+ continue;
+ }
+ if ($server->isFunctional() === false) {
+ continue;
+ }
+ if (isCloud() && data_get($server->team->subscription, 'stripe_invoice_paid', false) === false && $server->team->id !== 0) {
+ continue;
+ }
+ $finalScheduledBackups->push($scheduled_backup);
+ }
+
+ foreach ($finalScheduledBackups as $scheduled_backup) {
+ if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) {
+ $scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency];
+ }
$server = $scheduled_backup->server();
+ $serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
- if (is_null($server)) {
- continue;
+ if (validate_timezone($serverTimezone) === false) {
+ $serverTimezone = config('app.timezone');
}
if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) {
$scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency];
}
+ $serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
$this->scheduleInstance->job(new DatabaseBackupJob(
backup: $scheduled_backup
- ))->cron($scheduled_backup->frequency)->timezone($this->instanceTimezone)->onOneServer();
+ ))->cron($scheduled_backup->frequency)->timezone($serverTimezone)->onOneServer();
}
}
@@ -203,37 +227,55 @@ class Kernel extends ConsoleKernel
if ($scheduled_tasks->isEmpty()) {
return;
}
+ $finalScheduledTasks = collect();
foreach ($scheduled_tasks as $scheduled_task) {
$service = $scheduled_task->service;
$application = $scheduled_task->application;
- if (! $application && ! $service) {
+ $server = $scheduled_task->server();
+ if (blank($server)) {
$scheduled_task->delete();
continue;
}
- if ($application) {
- if (str($application->status)->contains('running') === false) {
- continue;
- }
- }
- if ($service) {
- if (str($service->status)->contains('running') === false) {
- continue;
- }
- }
- $server = $scheduled_task->server();
- if (! $server) {
+ if ($server->isFunctional() === false) {
continue;
}
+ if (isCloud() && data_get($server->team->subscription, 'stripe_invoice_paid', false) === false && $server->team->id !== 0) {
+ continue;
+ }
+
+ if (! $service && ! $application) {
+ $scheduled_task->delete();
+
+ continue;
+ }
+
+ if ($application && str($application->status)->contains('running') === false) {
+ continue;
+ }
+ if ($service && str($service->status)->contains('running') === false) {
+ continue;
+ }
+
+ $finalScheduledTasks->push($scheduled_task);
+ }
+
+ foreach ($finalScheduledTasks as $scheduled_task) {
+ $server = $scheduled_task->server();
if (isset(VALID_CRON_STRINGS[$scheduled_task->frequency])) {
$scheduled_task->frequency = VALID_CRON_STRINGS[$scheduled_task->frequency];
}
+ $serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
+
+ if (validate_timezone($serverTimezone) === false) {
+ $serverTimezone = config('app.timezone');
+ }
$this->scheduleInstance->job(new ScheduledTaskJob(
task: $scheduled_task
- ))->cron($scheduled_task->frequency)->timezone($this->instanceTimezone)->onOneServer();
+ ))->cron($scheduled_task->frequency)->timezone($serverTimezone)->onOneServer();
}
}
diff --git a/app/Contracts/CustomJobRepositoryInterface.php b/app/Contracts/CustomJobRepositoryInterface.php
new file mode 100644
index 000000000..1fbd71f46
--- /dev/null
+++ b/app/Contracts/CustomJobRepositoryInterface.php
@@ -0,0 +1,19 @@
+startsWith('/tmp/')
+ && str($scriptPath)->startsWith('/tmp/')
+ && ! str($tmpPath)->contains('..')
+ && ! str($scriptPath)->contains('..')
+ && strlen($tmpPath) > 5 // longer than just "/tmp/"
+ && strlen($scriptPath) > 5
+ ) {
+ $commands[] = "docker exec {$container} sh -c 'rm {$scriptPath}'";
+ $commands[] = "docker exec {$container} sh -c 'rm {$tmpPath}'";
+ instant_remote_process($commands, Server::find($serverId), throwError: true);
+ }
+ }
+ }
+}
diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php
index f02c4255d..5265fbb37 100644
--- a/app/Http/Controllers/Api/ApplicationsController.php
+++ b/app/Http/Controllers/Api/ApplicationsController.php
@@ -27,6 +27,9 @@ class ApplicationsController extends Controller
{
$application->makeHidden([
'id',
+ 'resourceable',
+ 'resourceable_id',
+ 'resourceable_type',
]);
if (request()->attributes->get('can_read_sensitive', false) === false) {
$application->makeHidden([
@@ -114,11 +117,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'git_repository' => ['type' => 'string', 'description' => 'The git repository URL.'],
'git_branch' => ['type' => 'string', 'description' => 'The git branch.'],
'build_pack' => ['type' => 'string', 'enum' => ['nixpacks', 'static', 'dockerfile', 'dockercompose'], 'description' => 'The build pack type.'],
@@ -185,8 +189,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -220,11 +233,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'github_app_uuid', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'github_app_uuid', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'github_app_uuid' => ['type' => 'string', 'description' => 'The Github App UUID.'],
'git_repository' => ['type' => 'string', 'description' => 'The git repository URL.'],
'git_branch' => ['type' => 'string', 'description' => 'The git branch.'],
@@ -291,8 +305,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -326,11 +349,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'private_key_uuid', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'private_key_uuid', 'git_repository', 'git_branch', 'build_pack', 'ports_exposes'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'private_key_uuid' => ['type' => 'string', 'description' => 'The private key UUID.'],
'git_repository' => ['type' => 'string', 'description' => 'The git repository URL.'],
'git_branch' => ['type' => 'string', 'description' => 'The git branch.'],
@@ -397,8 +421,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -432,11 +465,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'dockerfile'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'dockerfile'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'dockerfile' => ['type' => 'string', 'description' => 'The Dockerfile content.'],
'build_pack' => ['type' => 'string', 'enum' => ['nixpacks', 'static', 'dockerfile', 'dockercompose'], 'description' => 'The build pack type.'],
'ports_exposes' => ['type' => 'string', 'description' => 'The ports to expose.'],
@@ -487,8 +521,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -522,11 +565,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'docker_registry_image_name', 'ports_exposes'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'docker_registry_image_name', 'ports_exposes'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'docker_registry_image_name' => ['type' => 'string', 'description' => 'The docker registry image name.'],
'docker_registry_image_tag' => ['type' => 'string', 'description' => 'The docker registry image tag.'],
'ports_exposes' => ['type' => 'string', 'description' => 'The ports to expose.'],
@@ -574,8 +618,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -609,11 +662,12 @@ class ApplicationsController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['project_uuid', 'server_uuid', 'environment_name', 'docker_compose_raw'],
+ required: ['project_uuid', 'server_uuid', 'environment_name', 'environment_uuid', 'docker_compose_raw'],
properties: [
'project_uuid' => ['type' => 'string', 'description' => 'The project UUID.'],
'server_uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'The environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'The environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'The environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'docker_compose_raw' => ['type' => 'string', 'description' => 'The Docker Compose raw content.'],
'destination_uuid' => ['type' => 'string', 'description' => 'The destination UUID if the server has more than one destinations.'],
'name' => ['type' => 'string', 'description' => 'The application name.'],
@@ -627,8 +681,17 @@ class ApplicationsController extends Controller
),
responses: [
new OA\Response(
- response: 200,
+ response: 201,
description: 'Application created successfully.',
+ content: new OA\MediaType(
+ mediaType: 'application/json',
+ schema: new OA\Schema(
+ type: 'object',
+ properties: [
+ 'uuid' => ['type' => 'string'],
+ ]
+ )
+ )
),
new OA\Response(
response: 401,
@@ -647,7 +710,7 @@ class ApplicationsController extends Controller
private function create_application(Request $request, $type)
{
- $allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'is_static', 'domains', 'git_repository', 'git_branch', 'git_commit_sha', 'private_key_uuid', 'docker_registry_image_name', 'docker_registry_image_tag', 'build_pack', 'install_command', 'build_command', 'start_command', 'ports_exposes', 'ports_mappings', 'base_directory', 'publish_directory', 'health_check_enabled', 'health_check_path', 'health_check_port', 'health_check_host', 'health_check_method', 'health_check_return_code', 'health_check_scheme', 'health_check_response_text', 'health_check_interval', 'health_check_timeout', 'health_check_retries', 'health_check_start_period', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'custom_labels', 'custom_docker_run_options', 'post_deployment_command', 'post_deployment_command_container', 'pre_deployment_command', 'pre_deployment_command_container', 'manual_webhook_secret_github', 'manual_webhook_secret_gitlab', 'manual_webhook_secret_bitbucket', 'manual_webhook_secret_gitea', 'redirect', 'github_app_uuid', 'instant_deploy', 'dockerfile', 'docker_compose_location', 'docker_compose_raw', 'docker_compose_custom_start_command', 'docker_compose_custom_build_command', 'docker_compose_domains', 'watch_paths', 'use_build_server', 'static_image', 'custom_nginx_configuration'];
+ $allowedFields = ['project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'is_static', 'domains', 'git_repository', 'git_branch', 'git_commit_sha', 'private_key_uuid', 'docker_registry_image_name', 'docker_registry_image_tag', 'build_pack', 'install_command', 'build_command', 'start_command', 'ports_exposes', 'ports_mappings', 'base_directory', 'publish_directory', 'health_check_enabled', 'health_check_path', 'health_check_port', 'health_check_host', 'health_check_method', 'health_check_return_code', 'health_check_scheme', 'health_check_response_text', 'health_check_interval', 'health_check_timeout', 'health_check_retries', 'health_check_start_period', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'custom_labels', 'custom_docker_run_options', 'post_deployment_command', 'post_deployment_command_container', 'pre_deployment_command', 'pre_deployment_command_container', 'manual_webhook_secret_github', 'manual_webhook_secret_gitlab', 'manual_webhook_secret_bitbucket', 'manual_webhook_secret_gitea', 'redirect', 'github_app_uuid', 'instant_deploy', 'dockerfile', 'docker_compose_location', 'docker_compose_raw', 'docker_compose_custom_start_command', 'docker_compose_custom_build_command', 'docker_compose_domains', 'watch_paths', 'use_build_server', 'static_image', 'custom_nginx_configuration'];
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
@@ -661,7 +724,8 @@ class ApplicationsController extends Controller
'name' => 'string|max:255',
'description' => 'string|nullable',
'project_uuid' => 'string|required',
- 'environment_name' => 'string|required',
+ 'environment_name' => 'string|nullable',
+ 'environment_uuid' => 'string|nullable',
'server_uuid' => 'string|required',
'destination_uuid' => 'string',
]);
@@ -681,6 +745,11 @@ class ApplicationsController extends Controller
], 422);
}
+ $environmentUuid = $request->environment_uuid;
+ $environmentName = $request->environment_name;
+ if (blank($environmentUuid) && blank($environmentName)) {
+ return response()->json(['message' => 'You need to provide at least one of environment_name or environment_uuid.'], 422);
+ }
$serverUuid = $request->server_uuid;
$fqdn = $request->domains;
$instantDeploy = $request->instant_deploy;
@@ -713,7 +782,10 @@ class ApplicationsController extends Controller
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
- $environment = $project->environments()->where('name', $request->environment_name)->first();
+ $environment = $project->environments()->where('name', $environmentName)->first();
+ if (! $environment) {
+ $environment = $project->environments()->where('uuid', $environmentUuid)->first();
+ }
if (! $environment) {
return response()->json(['message' => 'Environment not found.'], 404);
}
@@ -730,12 +802,6 @@ class ApplicationsController extends Controller
}
$destination = $destinations->first();
if ($type === 'public') {
- if (! $request->has('name')) {
- $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
- }
- if ($request->build_pack === 'dockercompose') {
- $request->offsetSet('ports_exposes', '80');
- }
$validationRules = [
'git_repository' => 'string|required',
'git_branch' => 'string|required',
@@ -745,7 +811,7 @@ class ApplicationsController extends Controller
'docker_compose_raw' => 'string|nullable',
'docker_compose_domains' => 'array|nullable',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
return response()->json([
@@ -753,6 +819,12 @@ class ApplicationsController extends Controller
'errors' => $validator->errors(),
], 422);
}
+ if (! $request->has('name')) {
+ $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
+ }
+ if ($request->build_pack === 'dockercompose') {
+ $request->offsetSet('ports_exposes', '80');
+ }
$return = $this->validateDataApplications($request, $server);
if ($return instanceof \Illuminate\Http\JsonResponse) {
@@ -791,7 +863,7 @@ class ApplicationsController extends Controller
$application->settings->save();
}
$application->refresh();
- if (! $application->settings->is_container_label_readonly_enabled) {
+ if ($application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
}
@@ -815,14 +887,8 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
- ]));
+ ]))->setStatusCode(201);
} elseif ($type === 'private-gh-app') {
- if (! $request->has('name')) {
- $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
- }
- if ($request->build_pack === 'dockercompose') {
- $request->offsetSet('ports_exposes', '80');
- }
$validationRules = [
'git_repository' => 'string|required',
'git_branch' => 'string|required',
@@ -833,7 +899,7 @@ class ApplicationsController extends Controller
'docker_compose_location' => 'string',
'docker_compose_raw' => 'string|nullable',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
@@ -842,6 +908,14 @@ class ApplicationsController extends Controller
'errors' => $validator->errors(),
], 422);
}
+
+ if (! $request->has('name')) {
+ $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
+ }
+ if ($request->build_pack === 'dockercompose') {
+ $request->offsetSet('ports_exposes', '80');
+ }
+
$return = $this->validateDataApplications($request, $server);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
@@ -884,13 +958,13 @@ class ApplicationsController extends Controller
$application->environment_id = $environment->id;
$application->source_type = $githubApp->getMorphClass();
$application->source_id = $githubApp->id;
+ $application->save();
+ $application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
- $application->save();
- $application->refresh();
- if (! $application->settings->is_container_label_readonly_enabled) {
+ if ($application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
}
@@ -914,14 +988,8 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
- ]));
+ ]))->setStatusCode(201);
} elseif ($type === 'private-deploy-key') {
- if (! $request->has('name')) {
- $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
- }
- if ($request->build_pack === 'dockercompose') {
- $request->offsetSet('ports_exposes', '80');
- }
$validationRules = [
'git_repository' => 'string|required',
@@ -934,7 +1002,7 @@ class ApplicationsController extends Controller
'docker_compose_raw' => 'string|nullable',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
@@ -943,6 +1011,13 @@ class ApplicationsController extends Controller
'errors' => $validator->errors(),
], 422);
}
+ if (! $request->has('name')) {
+ $request->offsetSet('name', generate_application_name($request->git_repository, $request->git_branch));
+ }
+ if ($request->build_pack === 'dockercompose') {
+ $request->offsetSet('ports_exposes', '80');
+ }
+
$return = $this->validateDataApplications($request, $server);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
@@ -980,13 +1055,13 @@ class ApplicationsController extends Controller
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
+ $application->save();
+ $application->refresh();
if (isset($useBuildServer)) {
$application->settings->is_build_server_enabled = $useBuildServer;
$application->settings->save();
}
- $application->save();
- $application->refresh();
- if (! $application->settings->is_container_label_readonly_enabled) {
+ if ($application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
}
@@ -1010,16 +1085,12 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
- ]));
+ ]))->setStatusCode(201);
} elseif ($type === 'dockerfile') {
- if (! $request->has('name')) {
- $request->offsetSet('name', 'dockerfile-'.new Cuid2);
- }
-
$validationRules = [
'dockerfile' => 'string|required',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
@@ -1028,6 +1099,10 @@ class ApplicationsController extends Controller
'errors' => $validator->errors(),
], 422);
}
+ if (! $request->has('name')) {
+ $request->offsetSet('name', 'dockerfile-'.new Cuid2);
+ }
+
$return = $this->validateDataApplications($request, $server);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
@@ -1066,16 +1141,16 @@ class ApplicationsController extends Controller
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
- if (isset($useBuildServer)) {
- $application->settings->is_build_server_enabled = $useBuildServer;
- $application->settings->save();
- }
$application->git_repository = 'coollabsio/coolify';
$application->git_branch = 'main';
$application->save();
$application->refresh();
- if (! $application->settings->is_container_label_readonly_enabled) {
+ if (isset($useBuildServer)) {
+ $application->settings->is_build_server_enabled = $useBuildServer;
+ $application->settings->save();
+ }
+ if ($application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
}
@@ -1095,17 +1170,14 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
- ]));
+ ]))->setStatusCode(201);
} elseif ($type === 'dockerimage') {
- if (! $request->has('name')) {
- $request->offsetSet('name', 'docker-image-'.new Cuid2);
- }
$validationRules = [
'docker_registry_image_name' => 'string|required',
'docker_registry_image_tag' => 'string',
'ports_exposes' => 'string|regex:/^(\d+)(,\d+)*$/|required',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
@@ -1114,6 +1186,9 @@ class ApplicationsController extends Controller
'errors' => $validator->errors(),
], 422);
}
+ if (! $request->has('name')) {
+ $request->offsetSet('name', 'docker-image-'.new Cuid2);
+ }
$return = $this->validateDataApplications($request, $server);
if ($return instanceof \Illuminate\Http\JsonResponse) {
return $return;
@@ -1130,16 +1205,16 @@ class ApplicationsController extends Controller
$application->destination_id = $destination->id;
$application->destination_type = $destination->getMorphClass();
$application->environment_id = $environment->id;
- if (isset($useBuildServer)) {
- $application->settings->is_build_server_enabled = $useBuildServer;
- $application->settings->save();
- }
$application->git_repository = 'coollabsio/coolify';
$application->git_branch = 'main';
$application->save();
$application->refresh();
- if (! $application->settings->is_container_label_readonly_enabled) {
+ if (isset($useBuildServer)) {
+ $application->settings->is_build_server_enabled = $useBuildServer;
+ $application->settings->save();
+ }
+ if ($application->settings->is_container_label_readonly_enabled) {
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
$application->save();
}
@@ -1159,9 +1234,9 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($application, 'uuid'),
'domains' => data_get($application, 'domains'),
- ]));
+ ]))->setStatusCode(201);
} elseif ($type === 'dockercompose') {
- $allowedFields = ['project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'instant_deploy', 'docker_compose_raw'];
+ $allowedFields = ['project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'type', 'name', 'description', 'instant_deploy', 'docker_compose_raw'];
$extraFields = array_diff(array_keys($request->all()), $allowedFields);
if ($validator->fails() || ! empty($extraFields)) {
@@ -1183,7 +1258,7 @@ class ApplicationsController extends Controller
$validationRules = [
'docker_compose_raw' => 'string|required',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
if ($validator->fails()) {
@@ -1241,7 +1316,7 @@ class ApplicationsController extends Controller
return response()->json(serializeApiResponse([
'uuid' => data_get($service, 'uuid'),
'domains' => data_get($service, 'domains'),
- ]));
+ ]))->setStatusCode(201);
}
return response()->json(['message' => 'Invalid type.'], 400);
@@ -1551,7 +1626,7 @@ class ApplicationsController extends Controller
'docker_compose_custom_build_command' => 'string|nullable',
'custom_nginx_configuration' => 'string|nullable',
];
- $validationRules = array_merge($validationRules, sharedDataApplications());
+ $validationRules = array_merge(sharedDataApplications(), $validationRules);
$validator = customApiValidator($request->all(), $validationRules);
// Validate ports_exposes
@@ -1668,7 +1743,10 @@ class ApplicationsController extends Controller
removeUnnecessaryFieldsFromRequest($request);
$data = $request->all();
- data_set($data, 'fqdn', $domains);
+ if ($request->has('domains') && $server->isProxyShouldRun()) {
+ data_set($data, 'fqdn', $domains);
+ }
+
if ($dockerComposeDomainsJson->count() > 0) {
data_set($data, 'docker_compose_domains', json_encode($dockerComposeDomainsJson));
}
@@ -1893,8 +1971,9 @@ class ApplicationsController extends Controller
$is_preview = $request->is_preview ?? false;
$is_build_time = $request->is_build_time ?? false;
$is_literal = $request->is_literal ?? false;
+ $key = str($request->key)->trim()->replace(' ', '_')->value;
if ($is_preview) {
- $env = $application->environment_variables_preview->where('key', $request->key)->first();
+ $env = $application->environment_variables_preview->where('key', $key)->first();
if ($env) {
$env->value = $request->value;
if ($env->is_build_time != $is_build_time) {
@@ -1921,7 +2000,7 @@ class ApplicationsController extends Controller
], 404);
}
} else {
- $env = $application->environment_variables->where('key', $request->key)->first();
+ $env = $application->environment_variables->where('key', $key)->first();
if ($env) {
$env->value = $request->value;
if ($env->is_build_time != $is_build_time) {
@@ -2064,6 +2143,7 @@ class ApplicationsController extends Controller
$bulk_data = collect($bulk_data)->map(function ($item) {
return collect($item)->only(['key', 'value', 'is_preview', 'is_build_time', 'is_literal']);
});
+ $returnedEnvs = collect();
foreach ($bulk_data as $item) {
$validator = customApiValidator($item, [
'key' => 'string|required',
@@ -2085,8 +2165,9 @@ class ApplicationsController extends Controller
$is_literal = $item->get('is_literal') ?? false;
$is_multi_line = $item->get('is_multiline') ?? false;
$is_shown_once = $item->get('is_shown_once') ?? false;
+ $key = str($item->get('key'))->trim()->replace(' ', '_')->value;
if ($is_preview) {
- $env = $application->environment_variables_preview->where('key', $item->get('key'))->first();
+ $env = $application->environment_variables_preview->where('key', $key)->first();
if ($env) {
$env->value = $item->get('value');
if ($env->is_build_time != $is_build_time) {
@@ -2111,10 +2192,12 @@ class ApplicationsController extends Controller
'is_literal' => $is_literal,
'is_multiline' => $is_multi_line,
'is_shown_once' => $is_shown_once,
+ 'resourceable_type' => get_class($application),
+ 'resourceable_id' => $application->id,
]);
}
} else {
- $env = $application->environment_variables->where('key', $item->get('key'))->first();
+ $env = $application->environment_variables->where('key', $key)->first();
if ($env) {
$env->value = $item->get('value');
if ($env->is_build_time != $is_build_time) {
@@ -2139,12 +2222,15 @@ class ApplicationsController extends Controller
'is_literal' => $is_literal,
'is_multiline' => $is_multi_line,
'is_shown_once' => $is_shown_once,
+ 'resourceable_type' => get_class($application),
+ 'resourceable_id' => $application->id,
]);
}
}
+ $returnedEnvs->push($this->removeSensitiveData($env));
}
- return response()->json($this->removeSensitiveData($env))->setStatusCode(201);
+ return response()->json($returnedEnvs)->setStatusCode(201);
}
#[OA\Post(
@@ -2257,8 +2343,10 @@ class ApplicationsController extends Controller
], 422);
}
$is_preview = $request->is_preview ?? false;
+ $key = str($request->key)->trim()->replace(' ', '_')->value;
+
if ($is_preview) {
- $env = $application->environment_variables_preview->where('key', $request->key)->first();
+ $env = $application->environment_variables_preview->where('key', $key)->first();
if ($env) {
return response()->json([
'message' => 'Environment variable already exists. Use PATCH request to update it.',
@@ -2272,6 +2360,8 @@ class ApplicationsController extends Controller
'is_literal' => $request->is_literal ?? false,
'is_multiline' => $request->is_multiline ?? false,
'is_shown_once' => $request->is_shown_once ?? false,
+ 'resourceable_type' => get_class($application),
+ 'resourceable_id' => $application->id,
]);
return response()->json([
@@ -2279,7 +2369,7 @@ class ApplicationsController extends Controller
])->setStatusCode(201);
}
} else {
- $env = $application->environment_variables->where('key', $request->key)->first();
+ $env = $application->environment_variables->where('key', $key)->first();
if ($env) {
return response()->json([
'message' => 'Environment variable already exists. Use PATCH request to update it.',
@@ -2293,6 +2383,8 @@ class ApplicationsController extends Controller
'is_literal' => $request->is_literal ?? false,
'is_multiline' => $request->is_multiline ?? false,
'is_shown_once' => $request->is_shown_once ?? false,
+ 'resourceable_type' => get_class($application),
+ 'resourceable_id' => $application->id,
]);
return response()->json([
@@ -2380,7 +2472,10 @@ class ApplicationsController extends Controller
'message' => 'Application not found.',
], 404);
}
- $found_env = EnvironmentVariable::where('uuid', $request->env_uuid)->where('application_id', $application->id)->first();
+ $found_env = EnvironmentVariable::where('uuid', $request->env_uuid)
+ ->where('resourceable_type', Application::class)
+ ->where('resourceable_id', $application->id)
+ ->first();
if (! $found_env) {
return response()->json([
'message' => 'Environment variable not found.',
diff --git a/app/Http/Controllers/Api/DatabasesController.php b/app/Http/Controllers/Api/DatabasesController.php
index 917171e5c..504665f6a 100644
--- a/app/Http/Controllers/Api/DatabasesController.php
+++ b/app/Http/Controllers/Api/DatabasesController.php
@@ -523,11 +523,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'postgres_user' => ['type' => 'string', 'description' => 'PostgreSQL user'],
'postgres_password' => ['type' => 'string', 'description' => 'PostgreSQL password'],
'postgres_db' => ['type' => 'string', 'description' => 'PostgreSQL database'],
@@ -589,11 +590,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'clickhouse_admin_user' => ['type' => 'string', 'description' => 'Clickhouse admin user'],
'clickhouse_admin_password' => ['type' => 'string', 'description' => 'Clickhouse admin password'],
@@ -651,11 +653,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'dragonfly_password' => ['type' => 'string', 'description' => 'DragonFly password'],
'name' => ['type' => 'string', 'description' => 'Name of the database'],
@@ -712,11 +715,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'redis_password' => ['type' => 'string', 'description' => 'Redis password'],
'redis_conf' => ['type' => 'string', 'description' => 'Redis conf'],
@@ -774,11 +778,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'keydb_password' => ['type' => 'string', 'description' => 'KeyDB password'],
'keydb_conf' => ['type' => 'string', 'description' => 'KeyDB conf'],
@@ -836,11 +841,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'mariadb_conf' => ['type' => 'string', 'description' => 'MariaDB conf'],
'mariadb_root_password' => ['type' => 'string', 'description' => 'MariaDB root password'],
@@ -901,11 +907,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'mysql_root_password' => ['type' => 'string', 'description' => 'MySQL root password'],
'mysql_password' => ['type' => 'string', 'description' => 'MySQL password'],
@@ -966,11 +973,12 @@ class DatabasesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid'],
properties: [
'server_uuid' => ['type' => 'string', 'description' => 'UUID of the server'],
'project_uuid' => ['type' => 'string', 'description' => 'UUID of the project'],
- 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Name of the environment. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'UUID of the environment. You need to provide at least one of environment_name or environment_uuid.'],
'destination_uuid' => ['type' => 'string', 'description' => 'UUID of the destination if the server has multiple destinations'],
'mongo_conf' => ['type' => 'string', 'description' => 'MongoDB conf'],
'mongo_initdb_root_username' => ['type' => 'string', 'description' => 'MongoDB initdb root username'],
@@ -1013,7 +1021,7 @@ class DatabasesController extends Controller
public function create_database(Request $request, NewDatabaseTypes $type)
{
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'postgres_user', 'postgres_password', 'postgres_db', 'postgres_initdb_args', 'postgres_host_auth_method', 'postgres_conf', 'clickhouse_admin_user', 'clickhouse_admin_password', 'dragonfly_password', 'redis_password', 'redis_conf', 'keydb_password', 'keydb_conf', 'mariadb_conf', 'mariadb_root_password', 'mariadb_user', 'mariadb_password', 'mariadb_database', 'mongo_conf', 'mongo_initdb_root_username', 'mongo_initdb_root_password', 'mongo_initdb_database', 'mysql_root_password', 'mysql_password', 'mysql_user', 'mysql_database', 'mysql_conf'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'postgres_user', 'postgres_password', 'postgres_db', 'postgres_initdb_args', 'postgres_host_auth_method', 'postgres_conf', 'clickhouse_admin_user', 'clickhouse_admin_password', 'dragonfly_password', 'redis_password', 'redis_conf', 'keydb_password', 'keydb_conf', 'mariadb_conf', 'mariadb_root_password', 'mariadb_user', 'mariadb_password', 'mariadb_database', 'mongo_conf', 'mongo_initdb_root_username', 'mongo_initdb_root_password', 'mongo_initdb_database', 'mysql_root_password', 'mysql_password', 'mysql_user', 'mysql_database', 'mysql_conf'];
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
@@ -1039,6 +1047,11 @@ class DatabasesController extends Controller
'errors' => $errors,
], 422);
}
+ $environmentUuid = $request->environment_uuid;
+ $environmentName = $request->environment_name;
+ if (blank($environmentUuid) && blank($environmentName)) {
+ return response()->json(['message' => 'You need to provide at least one of environment_name or environment_uuid.'], 422);
+ }
$serverUuid = $request->server_uuid;
$instantDeploy = $request->instant_deploy ?? false;
if ($request->is_public && ! $request->public_port) {
@@ -1048,9 +1061,12 @@ class DatabasesController extends Controller
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
- $environment = $project->environments()->where('name', $request->environment_name)->first();
+ $environment = $project->environments()->where('name', $environmentName)->first();
if (! $environment) {
- return response()->json(['message' => 'Environment not found.'], 404);
+ $environment = $project->environments()->where('uuid', $environmentUuid)->first();
+ }
+ if (! $environment) {
+ return response()->json(['message' => 'You need to provide a valid environment_name or environment_uuid.'], 422);
}
$server = Server::whereTeamId($teamId)->whereUuid($serverUuid)->first();
if (! $server) {
@@ -1074,7 +1090,8 @@ class DatabasesController extends Controller
'description' => 'string|nullable',
'image' => 'string',
'project_uuid' => 'string|required',
- 'environment_name' => 'string|required',
+ 'environment_name' => 'string|nullable',
+ 'environment_uuid' => 'string|nullable',
'server_uuid' => 'string|required',
'destination_uuid' => 'string',
'is_public' => 'boolean',
@@ -1105,7 +1122,7 @@ class DatabasesController extends Controller
}
}
if ($type === NewDatabaseTypes::POSTGRESQL) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'postgres_user', 'postgres_password', 'postgres_db', 'postgres_initdb_args', 'postgres_host_auth_method', 'postgres_conf'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'postgres_user', 'postgres_password', 'postgres_db', 'postgres_initdb_args', 'postgres_host_auth_method', 'postgres_conf'];
$validator = customApiValidator($request->all(), [
'postgres_user' => 'string',
'postgres_password' => 'string',
@@ -1164,7 +1181,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::MARIADB) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mariadb_conf', 'mariadb_root_password', 'mariadb_user', 'mariadb_password', 'mariadb_database'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mariadb_conf', 'mariadb_root_password', 'mariadb_user', 'mariadb_password', 'mariadb_database'];
$validator = customApiValidator($request->all(), [
'clickhouse_admin_user' => 'string',
'clickhouse_admin_password' => 'string',
@@ -1220,7 +1237,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::MYSQL) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mysql_root_password', 'mysql_password', 'mysql_user', 'mysql_database', 'mysql_conf'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mysql_root_password', 'mysql_password', 'mysql_user', 'mysql_database', 'mysql_conf'];
$validator = customApiValidator($request->all(), [
'mysql_root_password' => 'string',
'mysql_password' => 'string',
@@ -1279,7 +1296,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::REDIS) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'redis_password', 'redis_conf'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'redis_password', 'redis_conf'];
$validator = customApiValidator($request->all(), [
'redis_password' => 'string',
'redis_conf' => 'string',
@@ -1335,7 +1352,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::DRAGONFLY) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'dragonfly_password'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'dragonfly_password'];
$validator = customApiValidator($request->all(), [
'dragonfly_password' => 'string',
]);
@@ -1365,7 +1382,7 @@ class DatabasesController extends Controller
'uuid' => $database->uuid,
]))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::KEYDB) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'keydb_password', 'keydb_conf'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'keydb_password', 'keydb_conf'];
$validator = customApiValidator($request->all(), [
'keydb_password' => 'string',
'keydb_conf' => 'string',
@@ -1421,7 +1438,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::CLICKHOUSE) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'clickhouse_admin_user', 'clickhouse_admin_password'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'clickhouse_admin_user', 'clickhouse_admin_password'];
$validator = customApiValidator($request->all(), [
'clickhouse_admin_user' => 'string',
'clickhouse_admin_password' => 'string',
@@ -1457,7 +1474,7 @@ class DatabasesController extends Controller
return response()->json(serializeApiResponse($payload))->setStatusCode(201);
} elseif ($type === NewDatabaseTypes::MONGODB) {
- $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mongo_conf', 'mongo_initdb_root_username', 'mongo_initdb_root_password', 'mongo_initdb_database'];
+ $allowedFields = ['name', 'description', 'image', 'public_port', 'is_public', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy', 'limits_memory', 'limits_memory_swap', 'limits_memory_swappiness', 'limits_memory_reservation', 'limits_cpus', 'limits_cpuset', 'limits_cpu_shares', 'mongo_conf', 'mongo_initdb_root_username', 'mongo_initdb_root_password', 'mongo_initdb_database'];
$validator = customApiValidator($request->all(), [
'mongo_conf' => 'string',
'mongo_initdb_root_username' => 'string',
diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php
index 1d89c82ed..b94ce9c67 100644
--- a/app/Http/Controllers/Api/ProjectController.php
+++ b/app/Http/Controllers/Api/ProjectController.php
@@ -90,11 +90,13 @@ class ProjectController extends Controller
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first()->load(['environments']);
+ $project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
+ $project->load(['environments']);
+
return response()->json(
serializeApiResponse($project),
);
@@ -102,16 +104,16 @@ class ProjectController extends Controller
#[OA\Get(
summary: 'Environment',
- description: 'Get environment by name.',
- path: '/projects/{uuid}/{environment_name}',
- operationId: 'get-environment-by-name',
+ description: 'Get environment by name or UUID.',
+ path: '/projects/{uuid}/{environment_name_or_uuid}',
+ operationId: 'get-environment-by-name-or-uuid',
security: [
['bearerAuth' => []],
],
tags: ['Projects'],
parameters: [
new OA\Parameter(name: 'uuid', in: 'path', required: true, description: 'Project UUID', schema: new OA\Schema(type: 'string')),
- new OA\Parameter(name: 'environment_name', in: 'path', required: true, description: 'Environment name', schema: new OA\Schema(type: 'string')),
+ new OA\Parameter(name: 'environment_name_or_uuid', in: 'path', required: true, description: 'Environment name or UUID', schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
@@ -141,14 +143,17 @@ class ProjectController extends Controller
if (! $request->uuid) {
return response()->json(['message' => 'UUID is required.'], 422);
}
- if (! $request->environment_name) {
- return response()->json(['message' => 'Environment name is required.'], 422);
+ if (! $request->environment_name_or_uuid) {
+ return response()->json(['message' => 'Environment name or UUID is required.'], 422);
}
$project = Project::whereTeamId($teamId)->whereUuid($request->uuid)->first();
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
- $environment = $project->environments()->whereName($request->environment_name)->first();
+ $environment = $project->environments()->whereName($request->environment_name_or_uuid)->first();
+ if (! $environment) {
+ $environment = $project->environments()->whereUuid($request->environment_name_or_uuid)->first();
+ }
if (! $environment) {
return response()->json(['message' => 'Environment not found.'], 404);
}
diff --git a/app/Http/Controllers/Api/ServicesController.php b/app/Http/Controllers/Api/ServicesController.php
index bcaba7107..03d9d209c 100644
--- a/app/Http/Controllers/Api/ServicesController.php
+++ b/app/Http/Controllers/Api/ServicesController.php
@@ -20,6 +20,9 @@ class ServicesController extends Controller
{
$service->makeHidden([
'id',
+ 'resourceable',
+ 'resourceable_id',
+ 'resourceable_type',
]);
if (request()->attributes->get('can_read_sensitive', false) === false) {
$service->makeHidden([
@@ -99,7 +102,7 @@ class ServicesController extends Controller
mediaType: 'application/json',
schema: new OA\Schema(
type: 'object',
- required: ['server_uuid', 'project_uuid', 'environment_name', 'type'],
+ required: ['server_uuid', 'project_uuid', 'environment_name', 'environment_uuid', 'type'],
properties: [
'type' => [
'description' => 'The one-click service type',
@@ -196,7 +199,8 @@ class ServicesController extends Controller
'name' => ['type' => 'string', 'maxLength' => 255, 'description' => 'Name of the service.'],
'description' => ['type' => 'string', 'nullable' => true, 'description' => 'Description of the service.'],
'project_uuid' => ['type' => 'string', 'description' => 'Project UUID.'],
- 'environment_name' => ['type' => 'string', 'description' => 'Environment name.'],
+ 'environment_name' => ['type' => 'string', 'description' => 'Environment name. You need to provide at least one of environment_name or environment_uuid.'],
+ 'environment_uuid' => ['type' => 'string', 'description' => 'Environment UUID. You need to provide at least one of environment_name or environment_uuid.'],
'server_uuid' => ['type' => 'string', 'description' => 'Server UUID.'],
'destination_uuid' => ['type' => 'string', 'description' => 'Destination UUID. Required if server has multiple destinations.'],
'instant_deploy' => ['type' => 'boolean', 'default' => false, 'description' => 'Start the service immediately after creation.'],
@@ -233,7 +237,7 @@ class ServicesController extends Controller
)]
public function create_service(Request $request)
{
- $allowedFields = ['type', 'name', 'description', 'project_uuid', 'environment_name', 'server_uuid', 'destination_uuid', 'instant_deploy'];
+ $allowedFields = ['type', 'name', 'description', 'project_uuid', 'environment_name', 'environment_uuid', 'server_uuid', 'destination_uuid', 'instant_deploy'];
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
@@ -247,7 +251,8 @@ class ServicesController extends Controller
$validator = customApiValidator($request->all(), [
'type' => 'string|required',
'project_uuid' => 'string|required',
- 'environment_name' => 'string|required',
+ 'environment_name' => 'string|nullable',
+ 'environment_uuid' => 'string|nullable',
'server_uuid' => 'string|required',
'destination_uuid' => 'string',
'name' => 'string|max:255',
@@ -269,6 +274,11 @@ class ServicesController extends Controller
'errors' => $errors,
], 422);
}
+ $environmentUuid = $request->environment_uuid;
+ $environmentName = $request->environment_name;
+ if (blank($environmentUuid) && blank($environmentName)) {
+ return response()->json(['message' => 'You need to provide at least one of environment_name or environment_uuid.'], 422);
+ }
$serverUuid = $request->server_uuid;
$instantDeploy = $request->instant_deploy ?? false;
if ($request->is_public && ! $request->public_port) {
@@ -278,7 +288,10 @@ class ServicesController extends Controller
if (! $project) {
return response()->json(['message' => 'Project not found.'], 404);
}
- $environment = $project->environments()->where('name', $request->environment_name)->first();
+ $environment = $project->environments()->where('name', $environmentName)->first();
+ if (! $environment) {
+ $environment = $project->environments()->where('uuid', $environmentUuid)->first();
+ }
if (! $environment) {
return response()->json(['message' => 'Environment not found.'], 404);
}
@@ -333,7 +346,8 @@ class ServicesController extends Controller
EnvironmentVariable::create([
'key' => $key,
'value' => $generatedValue,
- 'service_id' => $service->id,
+ 'resourceable_id' => $service->id,
+ 'resourceable_type' => $service->getMorphClass(),
'is_build_time' => false,
'is_preview' => false,
]);
@@ -345,7 +359,11 @@ class ServicesController extends Controller
}
$domains = $service->applications()->get()->pluck('fqdn')->sort();
$domains = $domains->map(function ($domain) {
- return str($domain)->beforeLast(':')->value();
+ if (count(explode(':', $domain)) > 2) {
+ return str($domain)->beforeLast(':')->value();
+ }
+
+ return $domain;
});
return response()->json([
@@ -673,7 +691,8 @@ class ServicesController extends Controller
], 422);
}
- $env = $service->environment_variables()->where('key', $request->key)->first();
+ $key = str($request->key)->trim()->replace(' ', '_')->value;
+ $env = $service->environment_variables()->where('key', $key)->first();
if (! $env) {
return response()->json(['message' => 'Environment variable not found.'], 404);
}
@@ -799,9 +818,9 @@ class ServicesController extends Controller
'errors' => $validator->errors(),
], 422);
}
-
+ $key = str($item['key'])->trim()->replace(' ', '_')->value;
$env = $service->environment_variables()->updateOrCreate(
- ['key' => $item['key']],
+ ['key' => $key],
$item
);
@@ -909,7 +928,8 @@ class ServicesController extends Controller
], 422);
}
- $existingEnv = $service->environment_variables()->where('key', $request->key)->first();
+ $key = str($request->key)->trim()->replace(' ', '_')->value;
+ $existingEnv = $service->environment_variables()->where('key', $key)->first();
if ($existingEnv) {
return response()->json([
'message' => 'Environment variable already exists. Use PATCH request to update it.',
@@ -995,7 +1015,8 @@ class ServicesController extends Controller
}
$env = EnvironmentVariable::where('uuid', $request->env_uuid)
- ->where('service_id', $service->id)
+ ->where('resourceable_type', Service::class)
+ ->where('resourceable_id', $service->id)
->first();
if (! $env) {
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 6b677fa0e..21b2b6d18 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -39,12 +39,12 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
{
use Dispatchable, ExecuteRemoteCommand, InteractsWithQueue, Queueable, SerializesModels;
+ public $tries = 1;
+
public $timeout = 3600;
public static int $batch_counter = 0;
- private int $application_deployment_queue_id;
-
private bool $newVersionIsHealthy = false;
private ApplicationDeploymentQueue $application_deployment_queue;
@@ -126,6 +126,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
private ?string $nixpacks_plan = null;
+ private Collection $nixpacks_plan_json;
+
private ?string $nixpacks_type = null;
private string $dockerfile_location = '/Dockerfile';
@@ -164,18 +166,23 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
private bool $preserveRepository = false;
- public $tries = 1;
+ public function tags()
+ {
+ // Do not remove this one, it needs to properly identify which worker is running the job
+ return ['App\Models\ApplicationDeploymentQueue:'.$this->application_deployment_queue_id];
+ }
- public function __construct(int $application_deployment_queue_id)
+ public function __construct(public int $application_deployment_queue_id)
{
$this->onQueue('high');
- $this->application_deployment_queue = ApplicationDeploymentQueue::find($application_deployment_queue_id);
+ $this->application_deployment_queue = ApplicationDeploymentQueue::find($this->application_deployment_queue_id);
+ $this->nixpacks_plan_json = collect([]);
+
$this->application = Application::find($this->application_deployment_queue->application_id);
$this->build_pack = data_get($this->application, 'build_pack');
$this->build_args = collect([]);
- $this->application_deployment_queue_id = $application_deployment_queue_id;
$this->deployment_uuid = $this->application_deployment_queue->deployment_uuid;
$this->pull_request_id = $this->application_deployment_queue->pull_request_id;
$this->commit = $this->application_deployment_queue->commit;
@@ -233,15 +240,11 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
}
}
- public function tags(): array
- {
- return ['server:'.gethostname()];
- }
-
public function handle(): void
{
$this->application_deployment_queue->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
+ 'horizon_job_worker' => gethostname(),
]);
if ($this->server->isFunctional() === false) {
$this->application_deployment_queue->addLogEntry('Server is not functional.');
@@ -1405,7 +1408,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
'project_uuid' => data_get($this->application, 'environment.project.uuid'),
'application_uuid' => data_get($this->application, 'uuid'),
'deployment_uuid' => $deployment_uuid,
- 'environment_name' => data_get($this->application, 'environment.name'),
+ 'environment_uuid' => data_get($this->application, 'environment.uuid'),
]));
}
}
@@ -1545,7 +1548,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
// Do any modifications here
$this->generate_env_variables();
- $merged_envs = $this->env_args->merge(collect(data_get($parsed, 'variables', [])));
+ $merged_envs = collect(data_get($parsed, 'variables', []))->merge($this->env_args);
$aptPkgs = data_get($parsed, 'phases.setup.aptPkgs', []);
if (count($aptPkgs) === 0) {
$aptPkgs = ['curl', 'wget'];
@@ -1570,6 +1573,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$this->elixir_finetunes();
}
$this->nixpacks_plan = json_encode($parsed, JSON_PRETTY_PRINT);
+ $this->nixpacks_plan_json = collect($parsed);
$this->application_deployment_queue->addLogEntry("Final Nixpacks plan: {$this->nixpacks_plan}", hidden: true);
if ($this->nixpacks_type === 'rust') {
// temporary: disable healthcheck for rust because the start phase does not have curl/wget
@@ -1678,7 +1682,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$this->application->custom_labels = base64_encode($labels->implode("\n"));
$this->application->save();
} else {
- if (! $this->application->settings->is_container_label_readonly_enabled) {
+ if ($this->application->settings->is_container_label_readonly_enabled) {
$labels = collect(generateLabelsApplication($this->application, $this->preview));
}
}
@@ -1690,7 +1694,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
return escapeDollarSign($value);
});
}
- $labels = $labels->merge(defaultLabels($this->application->id, $this->application->uuid, $this->pull_request_id))->toArray();
+ $labels = $labels->merge(defaultLabels($this->application->id, $this->application->uuid, $this->application->project()->name, $this->application->name, $this->application->environment->name, $this->pull_request_id))->toArray();
// Check for custom HEALTHCHECK
if ($this->application->build_pack === 'dockerfile' || $this->application->dockerfile) {
@@ -2278,18 +2282,10 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
private function generate_build_env_variables()
{
- $this->build_args = collect(["--build-arg SOURCE_COMMIT=\"{$this->commit}\""]);
- if ($this->pull_request_id === 0) {
- foreach ($this->application->build_environment_variables as $env) {
- $value = escapeshellarg($env->real_value);
- $this->build_args->push("--build-arg {$env->key}={$value}");
- }
- } else {
- foreach ($this->application->build_environment_variables_preview as $env) {
- $value = escapeshellarg($env->real_value);
- $this->build_args->push("--build-arg {$env->key}={$value}");
- }
- }
+ $variables = collect($this->nixpacks_plan_json->get('variables'));
+ $this->build_args = $variables->map(function ($value, $key) {
+ return "--build-arg {$key}={$value}";
+ });
}
private function add_build_env_variables_to_dockerfile()
@@ -2394,7 +2390,8 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
queue_next_deployment($this->application);
// If the deployment is cancelled by the user, don't update the status
if (
- $this->application_deployment_queue->status !== ApplicationDeploymentStatus::CANCELLED_BY_USER->value && $this->application_deployment_queue->status !== ApplicationDeploymentStatus::FAILED->value
+ $this->application_deployment_queue->status !== ApplicationDeploymentStatus::CANCELLED_BY_USER->value &&
+ $this->application_deployment_queue->status !== ApplicationDeploymentStatus::FAILED->value
) {
$this->application_deployment_queue->update([
'status' => $status,
diff --git a/app/Jobs/CheckAndStartSentinelJob.php b/app/Jobs/CheckAndStartSentinelJob.php
index 788db89ea..304b2a15c 100644
--- a/app/Jobs/CheckAndStartSentinelJob.php
+++ b/app/Jobs/CheckAndStartSentinelJob.php
@@ -24,7 +24,7 @@ class CheckAndStartSentinelJob implements ShouldBeEncrypted, ShouldQueue
$latestVersion = get_latest_sentinel_version();
// Check if sentinel is running
- $sentinelFound = instant_remote_process(['docker inspect coolify-sentinel'], $this->server, false);
+ $sentinelFound = instant_remote_process_with_timeout(['docker inspect coolify-sentinel'], $this->server, false, 10);
$sentinelFoundJson = json_decode($sentinelFound, true);
$sentinelStatus = data_get($sentinelFoundJson, '0.State.Status', 'exited');
if ($sentinelStatus !== 'running') {
@@ -33,7 +33,7 @@ class CheckAndStartSentinelJob implements ShouldBeEncrypted, ShouldQueue
return;
}
// If sentinel is running, check if it needs an update
- $runningVersion = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/version"'], $this->server, false);
+ $runningVersion = instant_remote_process_with_timeout(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/version"'], $this->server, false);
if (empty($runningVersion)) {
$runningVersion = '0.0.0';
}
diff --git a/app/Jobs/CleanupHelperContainersJob.php b/app/Jobs/CleanupHelperContainersJob.php
index f185ab781..0e1fcb4d7 100644
--- a/app/Jobs/CleanupHelperContainersJob.php
+++ b/app/Jobs/CleanupHelperContainersJob.php
@@ -20,11 +20,11 @@ class CleanupHelperContainersJob implements ShouldBeEncrypted, ShouldBeUnique, S
public function handle(): void
{
try {
- $containers = instant_remote_process(['docker container ps --format \'{{json .}}\' | jq -s \'map(select(.Image | contains("ghcr.io/coollabsio/coolify-helper")))\''], $this->server, false);
+ $containers = instant_remote_process_with_timeout(['docker container ps --format \'{{json .}}\' | jq -s \'map(select(.Image | contains("ghcr.io/coollabsio/coolify-helper")))\''], $this->server, false);
$containerIds = collect(json_decode($containers))->pluck('ID');
if ($containerIds->count() > 0) {
foreach ($containerIds as $containerId) {
- instant_remote_process(['docker container rm -f '.$containerId], $this->server, false);
+ instant_remote_process_with_timeout(['docker container rm -f '.$containerId], $this->server, false);
}
}
} catch (\Throwable $e) {
diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php
index 06aec5e49..577c1f11a 100644
--- a/app/Jobs/DatabaseBackupJob.php
+++ b/app/Jobs/DatabaseBackupJob.php
@@ -32,8 +32,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
public Server $server;
- public ScheduledDatabaseBackup $backup;
-
public StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|ServiceDatabase $database;
public ?string $container_name = null;
@@ -58,10 +56,9 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
public ?S3Storage $s3 = null;
- public function __construct($backup)
+ public function __construct(public ScheduledDatabaseBackup $backup)
{
$this->onQueue('high');
- $this->backup = $backup;
}
public function handle(): void
@@ -302,7 +299,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
throw new \Exception('Unsupported database type');
}
$size = $this->calculate_size();
- $this->remove_old_backups();
if ($this->backup->save_s3) {
$this->upload_to_s3();
}
@@ -326,6 +322,9 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
$this->team?->notify(new BackupFailed($this->backup, $this->database, $this->backup_output, $database));
}
}
+ if ($this->backup_log && $this->backup_log->status === 'success') {
+ removeOldBackups($this->backup);
+ }
} catch (\Throwable $e) {
throw $e;
} finally {
@@ -460,19 +459,6 @@ class DatabaseBackupJob implements ShouldBeEncrypted, ShouldQueue
return instant_remote_process(["du -b $this->backup_location | cut -f1"], $this->server, false);
}
- private function remove_old_backups(): void
- {
- if ($this->backup->number_of_backups_locally === 0) {
- $deletable = $this->backup->executions()->where('status', 'success');
- } else {
- $deletable = $this->backup->executions()->where('status', 'success')->skip($this->backup->number_of_backups_locally - 1);
- }
- foreach ($deletable->get() as $execution) {
- delete_backup_locally($execution->filename, $this->server);
- $execution->delete();
- }
- }
-
private function upload_to_s3(): void
{
try {
diff --git a/app/Jobs/PushServerUpdateJob.php b/app/Jobs/PushServerUpdateJob.php
index 24f8d1e6b..93b203fcb 100644
--- a/app/Jobs/PushServerUpdateJob.php
+++ b/app/Jobs/PushServerUpdateJob.php
@@ -19,6 +19,7 @@ use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
@@ -68,6 +69,11 @@ class PushServerUpdateJob implements ShouldBeEncrypted, ShouldQueue
public bool $foundLogDrainContainer = false;
+ public function middleware(): array
+ {
+ return [(new WithoutOverlapping($this->server->uuid))->dontRelease()];
+ }
+
public function backoff(): int
{
return isDev() ? 1 : 3;
diff --git a/app/Jobs/SendMessageToPushoverJob.php b/app/Jobs/SendMessageToPushoverJob.php
index 834a32b07..e2a94cdaa 100644
--- a/app/Jobs/SendMessageToPushoverJob.php
+++ b/app/Jobs/SendMessageToPushoverJob.php
@@ -44,7 +44,7 @@ class SendMessageToPushoverJob implements ShouldBeEncrypted, ShouldQueue
{
$response = Http::post('https://api.pushover.net/1/messages.json', $this->message->toPayload($this->token, $this->user));
if ($response->failed()) {
- throw new \RuntimeException('Pushover notification failed with ' . $response->status() . ' status code.' . $response->body());
+ throw new \RuntimeException('Pushover notification failed with '.$response->status().' status code.'.$response->body());
}
}
}
diff --git a/app/Jobs/VolumeCloneJob.php b/app/Jobs/VolumeCloneJob.php
new file mode 100644
index 000000000..f37a9704e
--- /dev/null
+++ b/app/Jobs/VolumeCloneJob.php
@@ -0,0 +1,104 @@
+onQueue('high');
+ }
+
+ public function handle()
+ {
+ try {
+ if (! $this->targetServer || $this->targetServer->id === $this->sourceServer->id) {
+ $this->cloneLocalVolume();
+ } else {
+ $this->cloneRemoteVolume();
+ }
+ } catch (\Exception $e) {
+ \Log::error("Failed to copy volume data for {$this->sourceVolume}: ".$e->getMessage());
+ throw $e;
+ }
+ }
+
+ protected function cloneLocalVolume()
+ {
+ instant_remote_process([
+ "docker volume create $this->targetVolume",
+ "docker run --rm -v $this->sourceVolume:/source -v $this->targetVolume:/target alpine sh -c 'cp -a /source/. /target/ && chown -R 1000:1000 /target'",
+ ], $this->sourceServer);
+ }
+
+ protected function cloneRemoteVolume()
+ {
+ $sourceCloneDir = "{$this->cloneDir}/{$this->sourceVolume}";
+ $targetCloneDir = "{$this->cloneDir}/{$this->targetVolume}";
+
+ try {
+ instant_remote_process([
+ "mkdir -p $sourceCloneDir",
+ "chmod 777 $sourceCloneDir",
+ "docker run --rm -v $this->sourceVolume:/source -v $sourceCloneDir:/clone alpine sh -c 'cd /source && tar czf /clone/volume-data.tar.gz .'",
+ ], $this->sourceServer);
+
+ instant_remote_process([
+ "mkdir -p $targetCloneDir",
+ "chmod 777 $targetCloneDir",
+ ], $this->targetServer);
+
+ instant_scp(
+ "$sourceCloneDir/volume-data.tar.gz",
+ "$targetCloneDir/volume-data.tar.gz",
+ $this->sourceServer,
+ $this->targetServer
+ );
+
+ instant_remote_process([
+ "docker volume create $this->targetVolume",
+ "docker run --rm -v $this->targetVolume:/target -v $targetCloneDir:/clone alpine sh -c 'cd /target && tar xzf /clone/volume-data.tar.gz && chown -R 1000:1000 /target'",
+ ], $this->targetServer);
+
+ } catch (\Exception $e) {
+ \Log::error("Failed to clone volume {$this->sourceVolume} to {$this->targetVolume}: ".$e->getMessage());
+ throw $e;
+ } finally {
+ try {
+ instant_remote_process([
+ "rm -rf $sourceCloneDir",
+ ], $this->sourceServer, false);
+ } catch (\Exception $e) {
+ \Log::warning('Failed to clean up source server clone directory: '.$e->getMessage());
+ }
+
+ try {
+ if ($this->targetServer) {
+ instant_remote_process([
+ "rm -rf $targetCloneDir",
+ ], $this->targetServer, false);
+ }
+ } catch (\Exception $e) {
+ \Log::warning('Failed to clean up target server clone directory: '.$e->getMessage());
+ }
+ }
+ }
+}
diff --git a/app/Livewire/ActivityMonitor.php b/app/Livewire/ActivityMonitor.php
index 2e36f34ee..024f53c3d 100644
--- a/app/Livewire/ActivityMonitor.php
+++ b/app/Livewire/ActivityMonitor.php
@@ -42,14 +42,8 @@ class ActivityMonitor extends Component
public function polling()
{
$this->hydrateActivity();
- // $this->setStatus(ProcessStatus::IN_PROGRESS);
$exit_code = data_get($this->activity, 'properties.exitCode');
if ($exit_code !== null) {
- // if ($exit_code === 0) {
- // // $this->setStatus(ProcessStatus::FINISHED);
- // } else {
- // // $this->setStatus(ProcessStatus::ERROR);
- // }
$this->isPollingActive = false;
if ($exit_code === 0) {
if ($this->eventToDispatch !== null) {
@@ -70,12 +64,4 @@ class ActivityMonitor extends Component
}
}
}
-
- // protected function setStatus($status)
- // {
- // $this->activity->properties = $this->activity->properties->merge([
- // 'status' => $status,
- // ]);
- // $this->activity->save();
- // }
}
diff --git a/app/Livewire/Admin/Index.php b/app/Livewire/Admin/Index.php
index 359db6329..b5f6d2929 100644
--- a/app/Livewire/Admin/Index.php
+++ b/app/Livewire/Admin/Index.php
@@ -21,16 +21,28 @@ class Index extends Component
public function mount()
{
- if (! isCloud()) {
+ if (! isCloud() && ! isDev()) {
return redirect()->route('dashboard');
}
-
- if (Auth::id() !== 0) {
+ if (Auth::id() !== 0 && ! session('impersonating')) {
return redirect()->route('dashboard');
}
$this->getSubscribers();
}
+ public function back()
+ {
+ if (session('impersonating')) {
+ session()->forget('impersonating');
+ $user = User::find(0);
+ $team_to_switch_to = $user->teams->first();
+ Auth::login($user);
+ refreshSession($team_to_switch_to);
+
+ return redirect(request()->header('Referer'));
+ }
+ }
+
public function submitSearch()
{
if ($this->search !== '') {
@@ -52,9 +64,10 @@ class Index extends Component
if (Auth::id() !== 0) {
return redirect()->route('dashboard');
}
+ session(['impersonating' => true]);
$user = User::find($user_id);
$team_to_switch_to = $user->teams->first();
- Cache::forget("team:{$user->id}");
+ // Cache::forget("team:{$user->id}");
Auth::login($user);
refreshSession($team_to_switch_to);
diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php
index eadabba7c..15eabfec5 100644
--- a/app/Livewire/Boarding/Index.php
+++ b/app/Livewire/Boarding/Index.php
@@ -9,6 +9,7 @@ use App\Models\Server;
use App\Models\Team;
use Illuminate\Support\Collection;
use Livewire\Component;
+use Visus\Cuid2\Cuid2;
class Index extends Component
{
@@ -334,6 +335,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
$this->createdProject = Project::create([
'name' => 'My first project',
'team_id' => currentTeam()->id,
+ 'uuid' => (string) new Cuid2,
]);
$this->currentState = 'create-resource';
}
@@ -346,7 +348,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
'project.resource.create',
[
'project_uuid' => $this->createdProject->uuid,
- 'environment_name' => 'production',
+ 'environment_uuid' => $this->createdProject->environments->first()->uuid,
'server' => $this->createdServer->id,
]
);
diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php
index 69ba19e40..c3cb797bf 100644
--- a/app/Livewire/Dashboard.php
+++ b/app/Livewire/Dashboard.php
@@ -8,6 +8,7 @@ use App\Models\Project;
use App\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
+use Illuminate\Support\Facades\Redirect;
use Livewire\Component;
class Dashboard extends Component
@@ -49,6 +50,20 @@ class Dashboard extends Component
])->sortBy('id')->groupBy('server_name')->toArray();
}
+ public function navigateToProject($projectUuid)
+ {
+ $project = Project::where('uuid', $projectUuid)->first();
+
+ if ($project && $project->environments->count() === 1) {
+ return Redirect::route('project.resource.index', [
+ 'project_uuid' => $projectUuid,
+ 'environment_uuid' => $project->environments->first()->uuid,
+ ]);
+ }
+
+ return Redirect::route('project.show', ['project_uuid' => $projectUuid]);
+ }
+
public function render()
{
return view('livewire.dashboard');
diff --git a/app/Livewire/Destination/New/Docker.php b/app/Livewire/Destination/New/Docker.php
index 337f1d067..0e60025e5 100644
--- a/app/Livewire/Destination/New/Docker.php
+++ b/app/Livewire/Destination/New/Docker.php
@@ -83,9 +83,7 @@ class Docker extends Component
]);
}
}
- $connectProxyToDockerNetworks = connectProxyToNetworks($this->selectedServer);
- instant_remote_process($connectProxyToDockerNetworks, $this->selectedServer, false);
- $this->dispatch('reloadWindow');
+ $this->redirect(route('destination.show', $docker->uuid));
} catch (\Throwable $e) {
return handleError($e, $this);
}
diff --git a/app/Livewire/Project/AddEmpty.php b/app/Livewire/Project/AddEmpty.php
index fd976548a..07873c059 100644
--- a/app/Livewire/Project/AddEmpty.php
+++ b/app/Livewire/Project/AddEmpty.php
@@ -5,6 +5,7 @@ namespace App\Livewire\Project;
use App\Models\Project;
use Livewire\Attributes\Validate;
use Livewire\Component;
+use Visus\Cuid2\Cuid2;
class AddEmpty extends Component
{
@@ -22,6 +23,7 @@ class AddEmpty extends Component
'name' => $this->name,
'description' => $this->description,
'team_id' => currentTeam()->id,
+ 'uuid' => (string) new Cuid2,
]);
return redirect()->route('project.show', $project->uuid);
diff --git a/app/Livewire/Project/Application/Configuration.php b/app/Livewire/Project/Application/Configuration.php
index 5261a0800..56e0caf75 100644
--- a/app/Livewire/Project/Application/Configuration.php
+++ b/app/Livewire/Project/Application/Configuration.php
@@ -3,43 +3,42 @@
namespace App\Livewire\Project\Application;
use App\Models\Application;
-use App\Models\Server;
use Livewire\Component;
class Configuration extends Component
{
+ public $currentRoute;
+
public Application $application;
+ public $project;
+
+ public $environment;
+
public $servers;
protected $listeners = ['buildPackUpdated' => '$refresh'];
public function mount()
{
+ $this->currentRoute = request()->route()->getName();
$project = currentTeam()
->projects()
->select('id', 'uuid', 'team_id')
->where('uuid', request()->route('project_uuid'))
->firstOrFail();
$environment = $project->environments()
- ->select('id', 'name', 'project_id')
- ->where('name', request()->route('environment_name'))
+ ->select('id', 'uuid', 'name', 'project_id')
+ ->where('uuid', request()->route('environment_uuid'))
->firstOrFail();
$application = $environment->applications()
->with(['destination'])
->where('uuid', request()->route('application_uuid'))
->firstOrFail();
+ $this->project = $project;
+ $this->environment = $environment;
$this->application = $application;
- if ($application->destination && $application->destination->server) {
- $mainServer = $application->destination->server;
- $this->servers = Server::ownedByCurrentTeam()
- ->select('id', 'name')
- ->where('id', '!=', $mainServer->id)
- ->get();
- } else {
- $this->servers = collect();
- }
}
public function render()
diff --git a/app/Livewire/Project/Application/Deployment/Index.php b/app/Livewire/Project/Application/Deployment/Index.php
index 4f761c2cf..b847c40ef 100644
--- a/app/Livewire/Project/Application/Deployment/Index.php
+++ b/app/Livewire/Project/Application/Deployment/Index.php
@@ -34,7 +34,7 @@ class Index extends Component
if (! $project) {
return redirect()->route('dashboard');
}
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
+ $environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
diff --git a/app/Livewire/Project/Application/Deployment/Show.php b/app/Livewire/Project/Application/Deployment/Show.php
index 04170fa28..7b2ac09d3 100644
--- a/app/Livewire/Project/Application/Deployment/Show.php
+++ b/app/Livewire/Project/Application/Deployment/Show.php
@@ -14,6 +14,8 @@ class Show extends Component
public string $deployment_uuid;
+ public string $horizon_job_status;
+
public $isKeepAliveOn = true;
protected $listeners = ['refreshQueue'];
@@ -26,7 +28,7 @@ class Show extends Component
if (! $project) {
return redirect()->route('dashboard');
}
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
+ $environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
@@ -34,25 +36,19 @@ class Show extends Component
if (! $application) {
return redirect()->route('dashboard');
}
- // $activity = Activity::where('properties->type_uuid', '=', $deploymentUuid)->first();
- // if (!$activity) {
- // return redirect()->route('project.application.deployment.index', [
- // 'project_uuid' => $project->uuid,
- // 'environment_name' => $environment->name,
- // 'application_uuid' => $application->uuid,
- // ]);
- // }
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (! $application_deployment_queue) {
return redirect()->route('project.application.deployment.index', [
'project_uuid' => $project->uuid,
- 'environment_name' => $environment->name,
+ 'environment_uuid' => $environment->uuid,
'application_uuid' => $application->uuid,
]);
}
$this->application = $application;
$this->application_deployment_queue = $application_deployment_queue;
+ $this->horizon_job_status = $this->application_deployment_queue->getHorizonJobStatus();
$this->deployment_uuid = $deploymentUuid;
+ $this->isKeepAliveOn();
}
public function refreshQueue()
@@ -60,13 +56,21 @@ class Show extends Component
$this->application_deployment_queue->refresh();
}
+ private function isKeepAliveOn()
+ {
+ if (data_get($this->application_deployment_queue, 'status') === 'finished' || data_get($this->application_deployment_queue, 'status') === 'failed') {
+ $this->isKeepAliveOn = false;
+ } else {
+ $this->isKeepAliveOn = true;
+ }
+ }
+
public function polling()
{
$this->dispatch('deploymentFinished');
$this->application_deployment_queue->refresh();
- if (data_get($this->application_deployment_queue, 'status') === 'finished' || data_get($this->application_deployment_queue, 'status') === 'failed') {
- $this->isKeepAliveOn = false;
- }
+ $this->horizon_job_status = $this->application_deployment_queue->getHorizonJobStatus();
+ $this->isKeepAliveOn();
}
public function getLogLinesProperty()
diff --git a/app/Livewire/Project/Application/DeploymentNavbar.php b/app/Livewire/Project/Application/DeploymentNavbar.php
index 6a6fa2482..87b40d4dc 100644
--- a/app/Livewire/Project/Application/DeploymentNavbar.php
+++ b/app/Livewire/Project/Application/DeploymentNavbar.php
@@ -23,7 +23,7 @@ class DeploymentNavbar extends Component
public function mount()
{
- $this->application = Application::find($this->application_deployment_queue->application_id);
+ $this->application = Application::ownedByCurrentTeam()->find($this->application_deployment_queue->application_id);
$this->server = $this->application->destination->server;
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
}
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php
index ff29b74e9..576f87801 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -153,7 +153,7 @@ class General extends Component
$this->is_preserve_repository_enabled = $this->application->settings->is_preserve_repository_enabled;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
$this->customLabels = $this->application->parseContainerLabels();
- if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) {
+ if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && $this->application->settings->is_container_label_readonly_enabled === true) {
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
$this->application->custom_labels = base64_encode($this->customLabels);
$this->application->save();
@@ -327,7 +327,7 @@ class General extends Component
}
}
- public function set_redirect()
+ public function setRedirect()
{
try {
$has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
@@ -360,10 +360,10 @@ class General extends Component
if ($warning) {
$this->dispatch('warning', __('warning.sslipdomain'));
}
- $this->resetDefaultLabels();
+ // $this->resetDefaultLabels();
if ($this->application->isDirty('redirect')) {
- $this->set_redirect();
+ $this->setRedirect();
}
$this->checkFqdns();
diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php
index 19a6145b7..0afc9123a 100644
--- a/app/Livewire/Project/Application/Heading.php
+++ b/app/Livewire/Project/Application/Heading.php
@@ -38,7 +38,7 @@ class Heading extends Component
{
$this->parameters = [
'project_uuid' => $this->application->project()->uuid,
- 'environment_name' => $this->application->environment->name,
+ 'environment_uuid' => $this->application->environment->uuid,
'application_uuid' => $this->application->uuid,
];
$lastDeployment = $this->application->get_last_successful_deployment();
@@ -94,7 +94,7 @@ class Heading extends Component
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deploymentUuid,
- 'environment_name' => $this->parameters['environment_name'],
+ 'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
@@ -136,7 +136,7 @@ class Heading extends Component
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deploymentUuid,
- 'environment_name' => $this->parameters['environment_name'],
+ 'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.php
index d42bf03d7..bdf62706c 100644
--- a/app/Livewire/Project/Application/Previews.php
+++ b/app/Livewire/Project/Application/Previews.php
@@ -171,7 +171,7 @@ class Previews extends Component
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $this->deployment_uuid,
- 'environment_name' => $this->parameters['environment_name'],
+ 'environment_uuid' => $this->parameters['environment_uuid'],
]);
} catch (\Throwable $e) {
return handleError($e, $this);
diff --git a/app/Livewire/Project/Application/Rollback.php b/app/Livewire/Project/Application/Rollback.php
index 1e58a1458..ff5db1e08 100644
--- a/app/Livewire/Project/Application/Rollback.php
+++ b/app/Livewire/Project/Application/Rollback.php
@@ -37,7 +37,7 @@ class Rollback extends Component
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'deployment_uuid' => $deployment_uuid,
- 'environment_name' => $this->parameters['environment_name'],
+ 'environment_uuid' => $this->parameters['environment_uuid'],
]);
}
diff --git a/app/Livewire/Project/CloneMe.php b/app/Livewire/Project/CloneMe.php
index 4d2bc6589..c71f6db64 100644
--- a/app/Livewire/Project/CloneMe.php
+++ b/app/Livewire/Project/CloneMe.php
@@ -2,6 +2,12 @@
namespace App\Livewire\Project;
+use App\Actions\Application\StopApplication;
+use App\Actions\Database\StartDatabase;
+use App\Actions\Database\StopDatabase;
+use App\Actions\Service\StartService;
+use App\Actions\Service\StopService;
+use App\Jobs\VolumeCloneJob;
use App\Models\Environment;
use App\Models\Project;
use App\Models\Server;
@@ -12,7 +18,7 @@ class CloneMe extends Component
{
public string $project_uuid;
- public string $environment_name;
+ public string $environment_uuid;
public int $project_id;
@@ -34,6 +40,8 @@ class CloneMe extends Component
public string $newName = '';
+ public bool $cloneVolumeData = false;
+
protected $messages = [
'selectedServer' => 'Please select a server.',
'selectedDestination' => 'Please select a server & destination.',
@@ -44,12 +52,17 @@ class CloneMe extends Component
{
$this->project_uuid = $project_uuid;
$this->project = Project::where('uuid', $project_uuid)->firstOrFail();
- $this->environment = $this->project->environments->where('name', $this->environment_name)->first();
+ $this->environment = $this->project->environments->where('uuid', $this->environment_uuid)->first();
$this->project_id = $this->project->id;
$this->servers = currentTeam()->servers;
$this->newName = str($this->project->name.'-clone-'.(string) new Cuid2)->slug();
}
+ public function toggleVolumeCloning(bool $value)
+ {
+ $this->cloneVolumeData = $value;
+ }
+
public function render()
{
return view('livewire.project.clone-me');
@@ -89,6 +102,7 @@ class CloneMe extends Component
if ($this->environment->name !== 'production') {
$project->environments()->create([
'name' => $this->environment->name,
+ 'uuid' => (string) new Cuid2,
]);
}
$environment = $project->environments->where('name', $this->environment->name)->first();
@@ -100,41 +114,160 @@ class CloneMe extends Component
$project = $this->project;
$environment = $this->project->environments()->create([
'name' => $this->newName,
+ 'uuid' => (string) new Cuid2,
]);
}
$applications = $this->environment->applications;
$databases = $this->environment->databases();
$services = $this->environment->services;
foreach ($applications as $application) {
+ $applicationSettings = $application->settings;
+
$uuid = (string) new Cuid2;
- $newApplication = $application->replicate()->fill([
+ $url = $application->fqdn;
+ if ($this->server->proxyType() !== 'NONE' && $applicationSettings->is_container_label_readonly_enabled === true) {
+ $url = generateFqdn($this->server, $uuid);
+ }
+
+ $newApplication = $application->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ 'additional_servers_count',
+ 'additional_networks_count',
+ ])->fill([
'uuid' => $uuid,
- 'fqdn' => generateFqdn($this->server, $uuid),
+ 'fqdn' => $url,
'status' => 'exited',
'environment_id' => $environment->id,
- // This is not correct, but we need to set it to something
'destination_id' => $this->selectedDestination,
]);
$newApplication->save();
- $environmentVaribles = $application->environment_variables()->get();
- foreach ($environmentVaribles as $environmentVarible) {
- $newEnvironmentVariable = $environmentVarible->replicate()->fill([
+
+ if ($newApplication->destination->server->proxyType() !== 'NONE' && $applicationSettings->is_container_label_readonly_enabled === true) {
+ $customLabels = str(implode('|coolify|', generateLabelsApplication($newApplication)))->replace('|coolify|', "\n");
+ $newApplication->custom_labels = base64_encode($customLabels);
+ $newApplication->save();
+ }
+
+ $newApplication->settings()->delete();
+ if ($applicationSettings) {
+ $newApplicationSettings = $applicationSettings->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
'application_id' => $newApplication->id,
]);
- $newEnvironmentVariable->save();
+ $newApplicationSettings->save();
}
+
+ $tags = $application->tags;
+ foreach ($tags as $tag) {
+ $newApplication->tags()->attach($tag->id);
+ }
+
+ $scheduledTasks = $application->scheduled_tasks()->get();
+ foreach ($scheduledTasks as $task) {
+ $newTask = $task->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'uuid' => (string) new Cuid2,
+ 'application_id' => $newApplication->id,
+ 'team_id' => currentTeam()->id,
+ ]);
+ $newTask->save();
+ }
+
+ $applicationPreviews = $application->previews()->get();
+ foreach ($applicationPreviews as $preview) {
+ $newPreview = $preview->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'application_id' => $newApplication->id,
+ 'status' => 'exited',
+ ]);
+ $newPreview->save();
+ }
+
$persistentVolumes = $application->persistentStorages()->get();
foreach ($persistentVolumes as $volume) {
- $newPersistentVolume = $volume->replicate()->fill([
- 'name' => $newApplication->uuid.'-'.str($volume->name)->afterLast('-'),
+ $newName = '';
+ if (str_starts_with($volume->name, $application->uuid)) {
+ $newName = str($volume->name)->replace($application->uuid, $newApplication->uuid);
+ } else {
+ $newName = $newApplication->uuid.'-'.$volume->name;
+ }
+
+ $newPersistentVolume = $volume->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'name' => $newName,
'resource_id' => $newApplication->id,
]);
$newPersistentVolume->save();
+
+ if ($this->cloneVolumeData) {
+ try {
+ StopApplication::dispatch($application, false, false);
+ $sourceVolume = $volume->name;
+ $targetVolume = $newPersistentVolume->name;
+ $sourceServer = $application->destination->server;
+ $targetServer = $newApplication->destination->server;
+
+ VolumeCloneJob::dispatch($sourceVolume, $targetVolume, $sourceServer, $targetServer, $newPersistentVolume);
+
+ queue_application_deployment(
+ deployment_uuid: (string) new Cuid2,
+ application: $application,
+ server: $sourceServer,
+ destination: $application->destination,
+ no_questions_asked: true
+ );
+ } catch (\Exception $e) {
+ \Log::error('Failed to copy volume data for '.$volume->name.': '.$e->getMessage());
+ }
+ }
+ }
+
+ $fileStorages = $application->fileStorages()->get();
+ foreach ($fileStorages as $storage) {
+ $newStorage = $storage->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resource_id' => $newApplication->id,
+ ]);
+ $newStorage->save();
+ }
+
+ $environmentVaribles = $application->environment_variables()->get();
+ foreach ($environmentVaribles as $environmentVarible) {
+ $newEnvironmentVariable = $environmentVarible->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resourceable_id' => $newApplication->id,
+ ]);
+ $newEnvironmentVariable->save();
}
}
+
foreach ($databases as $database) {
$uuid = (string) new Cuid2;
- $newDatabase = $database->replicate()->fill([
+ $newDatabase = $database->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
'uuid' => $uuid,
'status' => 'exited',
'started_at' => null,
@@ -142,51 +275,294 @@ class CloneMe extends Component
'destination_id' => $this->selectedDestination,
]);
$newDatabase->save();
+
+ $tags = $database->tags;
+ foreach ($tags as $tag) {
+ $newDatabase->tags()->attach($tag->id);
+ }
+
+ $newDatabase->persistentStorages()->delete();
+ $persistentVolumes = $database->persistentStorages()->get();
+ foreach ($persistentVolumes as $volume) {
+ $originalName = $volume->name;
+ $newName = '';
+
+ if (str_starts_with($originalName, 'postgres-data-')) {
+ $newName = 'postgres-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'mysql-data-')) {
+ $newName = 'mysql-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'redis-data-')) {
+ $newName = 'redis-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'clickhouse-data-')) {
+ $newName = 'clickhouse-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'mariadb-data-')) {
+ $newName = 'mariadb-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'mongodb-data-')) {
+ $newName = 'mongodb-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'keydb-data-')) {
+ $newName = 'keydb-data-'.$newDatabase->uuid;
+ } elseif (str_starts_with($originalName, 'dragonfly-data-')) {
+ $newName = 'dragonfly-data-'.$newDatabase->uuid;
+ } else {
+ if (str_starts_with($volume->name, $database->uuid)) {
+ $newName = str($volume->name)->replace($database->uuid, $newDatabase->uuid);
+ } else {
+ $newName = $newDatabase->uuid.'-'.$volume->name;
+ }
+ }
+
+ $newPersistentVolume = $volume->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'name' => $newName,
+ 'resource_id' => $newDatabase->id,
+ ]);
+ $newPersistentVolume->save();
+
+ if ($this->cloneVolumeData) {
+ try {
+ StopDatabase::dispatch($database);
+ $sourceVolume = $volume->name;
+ $targetVolume = $newPersistentVolume->name;
+ $sourceServer = $database->destination->server;
+ $targetServer = $newDatabase->destination->server;
+
+ VolumeCloneJob::dispatch($sourceVolume, $targetVolume, $sourceServer, $targetServer, $newPersistentVolume);
+
+ StartDatabase::dispatch($database);
+ } catch (\Exception $e) {
+ \Log::error('Failed to copy volume data for '.$volume->name.': '.$e->getMessage());
+ }
+ }
+ }
+
+ $fileStorages = $database->fileStorages()->get();
+ foreach ($fileStorages as $storage) {
+ $newStorage = $storage->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resource_id' => $newDatabase->id,
+ ]);
+ $newStorage->save();
+ }
+
+ $scheduledBackups = $database->scheduledBackups()->get();
+ foreach ($scheduledBackups as $backup) {
+ $uuid = (string) new Cuid2;
+ $newBackup = $backup->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'uuid' => $uuid,
+ 'database_id' => $newDatabase->id,
+ 'database_type' => $newDatabase->getMorphClass(),
+ 'team_id' => currentTeam()->id,
+ ]);
+ $newBackup->save();
+ }
+
$environmentVaribles = $database->environment_variables()->get();
foreach ($environmentVaribles as $environmentVarible) {
$payload = [];
- if ($database->type() === 'standalone-postgresql') {
- $payload['standalone_postgresql_id'] = $newDatabase->id;
- } elseif ($database->type() === 'standalone-redis') {
- $payload['standalone_redis_id'] = $newDatabase->id;
- } elseif ($database->type() === 'standalone-mongodb') {
- $payload['standalone_mongodb_id'] = $newDatabase->id;
- } elseif ($database->type() === 'standalone-mysql') {
- $payload['standalone_mysql_id'] = $newDatabase->id;
- } elseif ($database->type() === 'standalone-mariadb') {
- $payload['standalone_mariadb_id'] = $newDatabase->id;
- }
- $newEnvironmentVariable = $environmentVarible->replicate()->fill($payload);
+ $payload['resourceable_id'] = $newDatabase->id;
+ $payload['resourceable_type'] = $newDatabase->getMorphClass();
+ $newEnvironmentVariable = $environmentVarible->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill($payload);
$newEnvironmentVariable->save();
}
}
+
foreach ($services as $service) {
$uuid = (string) new Cuid2;
- $newService = $service->replicate()->fill([
+ $newService = $service->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
'uuid' => $uuid,
'environment_id' => $environment->id,
'destination_id' => $this->selectedDestination,
]);
$newService->save();
+
+ $tags = $service->tags;
+ foreach ($tags as $tag) {
+ $newService->tags()->attach($tag->id);
+ }
+
+ $scheduledTasks = $service->scheduled_tasks()->get();
+ foreach ($scheduledTasks as $task) {
+ $newTask = $task->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'uuid' => (string) new Cuid2,
+ 'service_id' => $newService->id,
+ 'team_id' => currentTeam()->id,
+ ]);
+ $newTask->save();
+ }
+
+ $environmentVariables = $service->environment_variables()->get();
+ foreach ($environmentVariables as $environmentVariable) {
+ $newEnvironmentVariable = $environmentVariable->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resourceable_id' => $newService->id,
+ 'resourceable_type' => $newService->getMorphClass(),
+ ]);
+ $newEnvironmentVariable->save();
+ }
+
foreach ($newService->applications() as $application) {
$application->update([
'status' => 'exited',
]);
+
+ $persistentVolumes = $application->persistentStorages()->get();
+ foreach ($persistentVolumes as $volume) {
+ $newName = '';
+ if (str_starts_with($volume->name, $application->uuid)) {
+ $newName = str($volume->name)->replace($application->uuid, $application->uuid);
+ } else {
+ $newName = $application->uuid.'-'.$volume->name;
+ }
+
+ $newPersistentVolume = $volume->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'name' => $newName,
+ 'resource_id' => $application->id,
+ ]);
+ $newPersistentVolume->save();
+
+ if ($this->cloneVolumeData) {
+ try {
+ StopService::dispatch($application, false, false);
+ $sourceVolume = $volume->name;
+ $targetVolume = $newPersistentVolume->name;
+ $sourceServer = $application->service->destination->server;
+ $targetServer = $newService->destination->server;
+
+ VolumeCloneJob::dispatch($sourceVolume, $targetVolume, $sourceServer, $targetServer, $newPersistentVolume);
+
+ StartService::dispatch($application);
+ } catch (\Exception $e) {
+ \Log::error('Failed to copy volume data for '.$volume->name.': '.$e->getMessage());
+ }
+ }
+ }
+
+ $fileStorages = $application->fileStorages()->get();
+ foreach ($fileStorages as $storage) {
+ $newStorage = $storage->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resource_id' => $application->id,
+ ]);
+ $newStorage->save();
+ }
}
+
foreach ($newService->databases() as $database) {
$database->update([
'status' => 'exited',
]);
+
+ $persistentVolumes = $database->persistentStorages()->get();
+ foreach ($persistentVolumes as $volume) {
+ $newName = '';
+ if (str_starts_with($volume->name, $database->uuid)) {
+ $newName = str($volume->name)->replace($database->uuid, $database->uuid);
+ } else {
+ $newName = $database->uuid.'-'.$volume->name;
+ }
+
+ $newPersistentVolume = $volume->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'name' => $newName,
+ 'resource_id' => $database->id,
+ ]);
+ $newPersistentVolume->save();
+
+ if ($this->cloneVolumeData) {
+ try {
+ StopService::dispatch($database->service, false, false);
+ $sourceVolume = $volume->name;
+ $targetVolume = $newPersistentVolume->name;
+ $sourceServer = $database->service->destination->server;
+ $targetServer = $newService->destination->server;
+
+ VolumeCloneJob::dispatch($sourceVolume, $targetVolume, $sourceServer, $targetServer, $newPersistentVolume);
+
+ StartService::dispatch($database->service);
+ } catch (\Exception $e) {
+ \Log::error('Failed to copy volume data for '.$volume->name.': '.$e->getMessage());
+ }
+ }
+ }
+
+ $fileStorages = $database->fileStorages()->get();
+ foreach ($fileStorages as $storage) {
+ $newStorage = $storage->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'resource_id' => $database->id,
+ ]);
+ $newStorage->save();
+ }
+
+ $scheduledBackups = $database->scheduledBackups()->get();
+ foreach ($scheduledBackups as $backup) {
+ $uuid = (string) new Cuid2;
+ $newBackup = $backup->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'uuid' => $uuid,
+ 'database_id' => $database->id,
+ 'database_type' => $database->getMorphClass(),
+ 'team_id' => currentTeam()->id,
+ ]);
+ $newBackup->save();
+ }
}
+
$newService->parse();
}
- return redirect()->route('project.resource.index', [
- 'project_uuid' => $project->uuid,
- 'environment_name' => $environment->name,
- ]);
} catch (\Exception $e) {
- return handleError($e, $this);
+ handleError($e, $this);
+
+ return;
+ } finally {
+ if (! isset($e)) {
+ return redirect()->route('project.resource.index', [
+ 'project_uuid' => $project->uuid,
+ 'environment_uuid' => $environment->uuid,
+ ]);
+ }
}
}
}
diff --git a/app/Livewire/Project/Database/Backup/Execution.php b/app/Livewire/Project/Database/Backup/Execution.php
index 564091659..4ac3b2e2c 100644
--- a/app/Livewire/Project/Database/Backup/Execution.php
+++ b/app/Livewire/Project/Database/Backup/Execution.php
@@ -22,7 +22,7 @@ class Execution extends Component
if (! $project) {
return redirect()->route('dashboard');
}
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
+ $environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
diff --git a/app/Livewire/Project/Database/Backup/Index.php b/app/Livewire/Project/Database/Backup/Index.php
index 9ff2f48d5..2df32ec7b 100644
--- a/app/Livewire/Project/Database/Backup/Index.php
+++ b/app/Livewire/Project/Database/Backup/Index.php
@@ -14,7 +14,7 @@ class Index extends Component
if (! $project) {
return redirect()->route('dashboard');
}
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
+ $environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
if (! $environment) {
return redirect()->route('dashboard');
}
@@ -31,7 +31,7 @@ class Index extends Component
) {
return redirect()->route('project.database.configuration', [
'project_uuid' => $project->uuid,
- 'environment_name' => $environment->name,
+ 'environment_uuid' => $environment->uuid,
'database_uuid' => $database->uuid,
]);
}
diff --git a/app/Livewire/Project/Database/BackupEdit.php b/app/Livewire/Project/Database/BackupEdit.php
index b3a54f0ab..0d363e983 100644
--- a/app/Livewire/Project/Database/BackupEdit.php
+++ b/app/Livewire/Project/Database/BackupEdit.php
@@ -40,8 +40,26 @@ class BackupEdit extends Component
#[Validate(['required', 'string'])]
public string $frequency = '';
- #[Validate(['required', 'integer', 'min:1'])]
- public int $numberOfBackupsLocally = 1;
+ #[Validate(['string'])]
+ public string $timezone = '';
+
+ #[Validate(['required', 'integer'])]
+ public int $databaseBackupRetentionAmountLocally = 0;
+
+ #[Validate(['required', 'integer'])]
+ public ?int $databaseBackupRetentionDaysLocally = 0;
+
+ #[Validate(['required', 'numeric', 'min:0'])]
+ public ?float $databaseBackupRetentionMaxStorageLocally = 0;
+
+ #[Validate(['required', 'integer'])]
+ public ?int $databaseBackupRetentionAmountS3 = 0;
+
+ #[Validate(['required', 'integer'])]
+ public ?int $databaseBackupRetentionDaysS3 = 0;
+
+ #[Validate(['required', 'numeric', 'min:0'])]
+ public ?float $databaseBackupRetentionMaxStorageS3 = 0;
#[Validate(['required', 'boolean'])]
public bool $saveS3 = false;
@@ -68,19 +86,30 @@ class BackupEdit extends Component
public function syncData(bool $toModel = false)
{
if ($toModel) {
- $this->customValidate();
$this->backup->enabled = $this->backupEnabled;
$this->backup->frequency = $this->frequency;
- $this->backup->number_of_backups_locally = $this->numberOfBackupsLocally;
+ $this->backup->database_backup_retention_amount_locally = $this->databaseBackupRetentionAmountLocally;
+ $this->backup->database_backup_retention_days_locally = $this->databaseBackupRetentionDaysLocally;
+ $this->backup->database_backup_retention_max_storage_locally = $this->databaseBackupRetentionMaxStorageLocally;
+ $this->backup->database_backup_retention_amount_s3 = $this->databaseBackupRetentionAmountS3;
+ $this->backup->database_backup_retention_days_s3 = $this->databaseBackupRetentionDaysS3;
+ $this->backup->database_backup_retention_max_storage_s3 = $this->databaseBackupRetentionMaxStorageS3;
$this->backup->save_s3 = $this->saveS3;
$this->backup->s3_storage_id = $this->s3StorageId;
$this->backup->databases_to_backup = $this->databasesToBackup;
$this->backup->dump_all = $this->dumpAll;
+ $this->customValidate();
$this->backup->save();
} else {
$this->backupEnabled = $this->backup->enabled;
$this->frequency = $this->backup->frequency;
- $this->numberOfBackupsLocally = $this->backup->number_of_backups_locally;
+ $this->timezone = data_get($this->backup->server(), 'settings.server_timezone', 'Instance timezone');
+ $this->databaseBackupRetentionAmountLocally = $this->backup->database_backup_retention_amount_locally;
+ $this->databaseBackupRetentionDaysLocally = $this->backup->database_backup_retention_days_locally;
+ $this->databaseBackupRetentionMaxStorageLocally = $this->backup->database_backup_retention_max_storage_locally;
+ $this->databaseBackupRetentionAmountS3 = $this->backup->database_backup_retention_amount_s3;
+ $this->databaseBackupRetentionDaysS3 = $this->backup->database_backup_retention_days_s3;
+ $this->databaseBackupRetentionMaxStorageS3 = $this->backup->database_backup_retention_max_storage_s3;
$this->saveS3 = $this->backup->save_s3;
$this->s3StorageId = $this->backup->s3_storage_id;
$this->databasesToBackup = $this->backup->databases_to_backup;
@@ -99,11 +128,29 @@ class BackupEdit extends Component
}
try {
- if ($this->delete_associated_backups_locally) {
- $this->deleteAssociatedBackupsLocally();
+ $server = null;
+ if ($this->backup->database instanceof \App\Models\ServiceDatabase) {
+ $server = $this->backup->database->service->destination->server;
+ } elseif ($this->backup->database->destination && $this->backup->database->destination->server) {
+ $server = $this->backup->database->destination->server;
}
- if ($this->delete_associated_backups_s3) {
- $this->deleteAssociatedBackupsS3();
+
+ $filenames = $this->backup->executions()
+ ->whereNotNull('filename')
+ ->where('filename', '!=', '')
+ ->where('scheduled_database_backup_id', $this->backup->id)
+ ->pluck('filename')
+ ->filter()
+ ->all();
+
+ if (! empty($filenames)) {
+ if ($this->delete_associated_backups_locally && $server) {
+ deleteBackupsLocally($filenames, $server);
+ }
+
+ if ($this->delete_associated_backups_s3 && $this->backup->s3) {
+ deleteBackupsS3($filenames, $this->backup->s3);
+ }
}
$this->backup->delete();
@@ -119,7 +166,9 @@ class BackupEdit extends Component
} else {
return redirect()->route('project.database.backup.index', $this->parameters);
}
- } catch (\Throwable $e) {
+ } catch (\Exception $e) {
+ $this->dispatch('error', 'Failed to delete backup: '.$e->getMessage());
+
return handleError($e, $this);
}
}
@@ -156,63 +205,12 @@ class BackupEdit extends Component
}
}
- private function deleteAssociatedBackupsLocally()
- {
- $executions = $this->backup->executions;
- $backupFolder = null;
-
- foreach ($executions as $execution) {
- if ($this->backup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
- $server = $this->backup->database->service->destination->server;
- } else {
- $server = $this->backup->database->destination->server;
- }
-
- if (! $backupFolder) {
- $backupFolder = dirname($execution->filename);
- }
-
- delete_backup_locally($execution->filename, $server);
- $execution->delete();
- }
-
- if (str($backupFolder)->isNotEmpty()) {
- $this->deleteEmptyBackupFolder($backupFolder, $server);
- }
- }
-
- private function deleteAssociatedBackupsS3()
- {
- //Add function to delete backups from S3
- }
-
- private function deleteAssociatedBackupsSftp()
- {
- //Add function to delete backups from SFTP
- }
-
- private function deleteEmptyBackupFolder($folderPath, $server)
- {
- $checkEmpty = instant_remote_process(["[ -z \"$(ls -A '$folderPath')\" ] && echo 'empty' || echo 'not empty'"], $server);
-
- if (trim($checkEmpty) === 'empty') {
- instant_remote_process(["rmdir '$folderPath'"], $server);
-
- $parentFolder = dirname($folderPath);
- $checkParentEmpty = instant_remote_process(["[ -z \"$(ls -A '$parentFolder')\" ] && echo 'empty' || echo 'not empty'"], $server);
-
- if (trim($checkParentEmpty) === 'empty') {
- instant_remote_process(["rmdir '$parentFolder'"], $server);
- }
- }
- }
-
public function render()
{
return view('livewire.project.database.backup-edit', [
'checkboxes' => [
['id' => 'delete_associated_backups_locally', 'label' => __('database.delete_backups_locally')],
- // ['id' => 'delete_associated_backups_s3', 'label' => 'All backups associated with this backup job from this database will be permanently deleted from the selected S3 Storage.']
+ ['id' => 'delete_associated_backups_s3', 'label' => 'All backups will be permanently deleted (associated with this backup job) from the selected S3 Storage.'],
// ['id' => 'delete_associated_backups_sftp', 'label' => 'All backups associated with this backup job from this database will be permanently deleted from the selected SFTP Storage.']
],
]);
diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php
index f91b8bfaf..7eef1a539 100644
--- a/app/Livewire/Project/Database/BackupExecutions.php
+++ b/app/Livewire/Project/Database/BackupExecutions.php
@@ -18,9 +18,9 @@ class BackupExecutions extends Component
public $setDeletableBackup;
- public $delete_backup_s3 = true;
+ public $delete_backup_s3 = false;
- public $delete_backup_sftp = true;
+ public $delete_backup_sftp = false;
public function getListeners()
{
@@ -57,23 +57,25 @@ class BackupExecutions extends Component
return;
}
- if ($execution->scheduledDatabaseBackup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
- delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
- } else {
- delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->destination->server);
- }
+ $server = $execution->scheduledDatabaseBackup->database->getMorphClass() === \App\Models\ServiceDatabase::class
+ ? $execution->scheduledDatabaseBackup->database->service->destination->server
+ : $execution->scheduledDatabaseBackup->database->destination->server;
- if ($this->delete_backup_s3) {
- // Add logic to delete from S3
- }
+ try {
+ if ($execution->filename) {
+ deleteBackupsLocally($execution->filename, $server);
- if ($this->delete_backup_sftp) {
- // Add logic to delete from SFTP
- }
+ if ($this->delete_backup_s3 && $execution->scheduledDatabaseBackup->s3) {
+ deleteBackupsS3($execution->filename, $execution->scheduledDatabaseBackup->s3);
+ }
+ }
- $execution->delete();
- $this->dispatch('success', 'Backup deleted.');
- $this->refreshBackupExecutions();
+ $execution->delete();
+ $this->dispatch('success', 'Backup deleted.');
+ $this->refreshBackupExecutions();
+ } catch (\Exception $e) {
+ $this->dispatch('error', 'Failed to delete backup: '.$e->getMessage());
+ }
}
public function download_file($exeuctionId)
@@ -83,8 +85,10 @@ class BackupExecutions extends Component
public function refreshBackupExecutions(): void
{
- if ($this->backup) {
- $this->executions = $this->backup->executions()->get();
+ if ($this->backup && $this->backup->exists) {
+ $this->executions = $this->backup->executions()->get()->toArray();
+ } else {
+ $this->executions = [];
}
}
@@ -141,7 +145,7 @@ class BackupExecutions extends Component
return view('livewire.project.database.backup-executions', [
'checkboxes' => [
['id' => 'delete_backup_s3', 'label' => 'Delete the selected backup permanently form S3 Storage'],
- ['id' => 'delete_backup_sftp', 'label' => 'Delete the selected backup permanently form SFTP Storage'],
+ // ['id' => 'delete_backup_sftp', 'label' => 'Delete the selected backup permanently form SFTP Storage'],
],
]);
}
diff --git a/app/Livewire/Project/Database/BackupNow.php b/app/Livewire/Project/Database/BackupNow.php
index 9c9c175e2..3cd360562 100644
--- a/app/Livewire/Project/Database/BackupNow.php
+++ b/app/Livewire/Project/Database/BackupNow.php
@@ -9,11 +9,9 @@ class BackupNow extends Component
{
public $backup;
- public function backup_now()
+ public function backupNow()
{
- dispatch(new DatabaseBackupJob(
- backup: $this->backup
- ));
+ DatabaseBackupJob::dispatch($this->backup);
$this->dispatch('success', 'Backup queued. It will be available in a few minutes.');
}
}
diff --git a/app/Livewire/Project/Database/Configuration.php b/app/Livewire/Project/Database/Configuration.php
index e14b27cf6..938abba54 100644
--- a/app/Livewire/Project/Database/Configuration.php
+++ b/app/Livewire/Project/Database/Configuration.php
@@ -6,23 +6,34 @@ use Livewire\Component;
class Configuration extends Component
{
+ public $currentRoute;
+
public $database;
+ public $project;
+
+ public $environment;
+
public function mount()
{
- $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
- if (! $project) {
- return redirect()->route('dashboard');
- }
- $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']);
- if (! $environment) {
- return redirect()->route('dashboard');
- }
- $database = $environment->databases()->where('uuid', request()->route('database_uuid'))->first();
- if (! $database) {
- return redirect()->route('dashboard');
- }
+ $this->currentRoute = request()->route()->getName();
+
+ $project = currentTeam()
+ ->projects()
+ ->select('id', 'uuid', 'team_id')
+ ->where('uuid', request()->route('project_uuid'))
+ ->firstOrFail();
+ $environment = $project->environments()
+ ->select('id', 'name', 'project_id', 'uuid')
+ ->where('uuid', request()->route('environment_uuid'))
+ ->firstOrFail();
+ $database = $environment->databases()
+ ->where('uuid', request()->route('database_uuid'))
+ ->firstOrFail();
+
$this->database = $database;
+ $this->project = $project;
+ $this->environment = $environment;
if (str($this->database->status)->startsWith('running') && is_null($this->database->config_hash)) {
$this->database->isConfigurationChanged(true);
$this->dispatch('configurationChanged');
diff --git a/app/Livewire/Project/Database/Import.php b/app/Livewire/Project/Database/Import.php
index 062f454b1..dc330b3af 100644
--- a/app/Livewire/Project/Database/Import.php
+++ b/app/Livewire/Project/Database/Import.php
@@ -37,6 +37,12 @@ class Import extends Component
public array $importCommands = [];
+ public bool $dumpAll = false;
+
+ public string $restoreCommandText = '';
+
+ public string $customLocation = '';
+
public string $postgresqlRestoreCommand = 'pg_restore -U $POSTGRES_USER -d $POSTGRES_DB';
public string $mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';
@@ -56,10 +62,62 @@ class Import extends Component
public function mount()
{
+ if (isDev()) {
+ $this->customLocation = '/data/coolify/pg-dump-all-1736245863.gz';
+ }
$this->parameters = get_route_parameters();
$this->getContainers();
}
+ public function updatedDumpAll($value)
+ {
+ switch ($this->resource->getMorphClass()) {
+ case \App\Models\StandaloneMariadb::class:
+ if ($value === true) {
+ $this->mariadbRestoreCommand = <<<'EOD'
+for pid in $(mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do
+ mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "KILL $pid" 2>/dev/null || true
+done && \
+mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT CONCAT('DROP DATABASE IF EXISTS \`',schema_name,'\`;') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql','performance_schema','sys');" | mariadb -u root -p$MARIADB_ROOT_PASSWORD && \
+mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS \`default\`;" && \
+(gunzip -cf $tmpPath 2>/dev/null || cat $tmpPath) | sed -e '/^CREATE DATABASE/d' -e '/^USE \`mysql\`/d' | mariadb -u root -p$MARIADB_ROOT_PASSWORD default
+EOD;
+ $this->restoreCommandText = $this->mariadbRestoreCommand.' && (gunzip -cf