diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php index c0e088203..091268043 100644 --- a/app/Actions/Docker/GetContainersStatus.php +++ b/app/Actions/Docker/GetContainersStatus.php @@ -208,7 +208,6 @@ class GetContainersStatus $foundServices[] = "$service->id-$service->name"; $statusFromDb = $service->status; if ($statusFromDb !== $containerStatus) { - // ray('Updating status: ' . $containerStatus); $service->update(['status' => $containerStatus]); } else { $service->update(['last_online_at' => now()]); diff --git a/app/Console/Commands/CloudCleanupSubscriptions.php b/app/Console/Commands/CloudCleanupSubscriptions.php index 9dc6e24f5..ab676c927 100644 --- a/app/Console/Commands/CloudCleanupSubscriptions.php +++ b/app/Console/Commands/CloudCleanupSubscriptions.php @@ -50,7 +50,7 @@ class CloudCleanupSubscriptions extends Command } else { $subscription = $stripe->subscriptions->retrieve(data_get($team, 'subscription.stripe_subscription_id'), []); $status = data_get($subscription, 'status'); - if ($status === 'active' || $status === 'past_due') { + if ($status === 'active') { $team->subscription->update([ 'stripe_invoice_paid' => true, 'stripe_trial_already_ended' => false, diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php index ff926bf70..4762a04b9 100644 --- a/app/Http/Controllers/Api/ApplicationsController.php +++ b/app/Http/Controllers/Api/ApplicationsController.php @@ -1291,11 +1291,6 @@ class ApplicationsController extends Controller $dockerCompose = base64_decode($request->docker_compose_raw); $dockerComposeRaw = Yaml::dump(Yaml::parse($dockerCompose), 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); - // $isValid = validateComposeFile($dockerComposeRaw, $server_id); - // if ($isValid !== 'OK') { - // return $this->dispatch('error', "Invalid docker-compose file.\n$isValid"); - // } - $service = new Service; removeUnnecessaryFieldsFromRequest($request); $service->fill($request->all()); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 522683efa..14a2950af 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -54,7 +54,7 @@ class Controller extends BaseController 'email' => Str::lower($arrayOfRequest['email']), ]); $type = set_transanctional_email_settings(); - if (! $type) { + if (blank($type)) { return response()->json(['message' => 'Transactional emails are not active'], 400); } $request->validate([Fortify::email() => 'required|email']); diff --git a/app/Http/Controllers/Webhook/Bitbucket.php b/app/Http/Controllers/Webhook/Bitbucket.php index b629daf54..33d8f8532 100644 --- a/app/Http/Controllers/Webhook/Bitbucket.php +++ b/app/Http/Controllers/Webhook/Bitbucket.php @@ -49,7 +49,7 @@ class Bitbucket extends Controller $full_name = data_get($payload, 'repository.full_name'); $commit = data_get($payload, 'push.changes.0.new.target.hash'); - if (!$branch) { + if (! $branch) { return response([ 'status' => 'failed', 'message' => 'Nothing to do. No branch found in the request.', diff --git a/app/Http/Controllers/Webhook/Gitea.php b/app/Http/Controllers/Webhook/Gitea.php index cc53f2034..dbdd0b27d 100644 --- a/app/Http/Controllers/Webhook/Gitea.php +++ b/app/Http/Controllers/Webhook/Gitea.php @@ -202,7 +202,6 @@ class Gitea extends Controller if ($found) { $found->delete(); $container_name = generateApplicationContainerName($application, $pull_request_id); - // ray('Stopping container: ' . $container_name); instant_remote_process(["docker rm -f $container_name"], $application->destination->server); $return_payloads->push([ 'application' => $application->name, diff --git a/app/Http/Controllers/Webhook/Github.php b/app/Http/Controllers/Webhook/Github.php index ac1d4ded2..882f2be8b 100644 --- a/app/Http/Controllers/Webhook/Github.php +++ b/app/Http/Controllers/Webhook/Github.php @@ -208,7 +208,6 @@ class Github extends Controller if ($found) { $found->delete(); $container_name = generateApplicationContainerName($application, $pull_request_id); - // ray('Stopping container: ' . $container_name); instant_remote_process(["docker rm -f $container_name"], $application->destination->server); $return_payloads->push([ 'application' => $application->name, diff --git a/app/Http/Controllers/Webhook/Gitlab.php b/app/Http/Controllers/Webhook/Gitlab.php index d8dcc0c3b..cf6874b8c 100644 --- a/app/Http/Controllers/Webhook/Gitlab.php +++ b/app/Http/Controllers/Webhook/Gitlab.php @@ -227,7 +227,6 @@ class Gitlab extends Controller if ($found) { $found->delete(); $container_name = generateApplicationContainerName($application, $pull_request_id); - // ray('Stopping container: ' . $container_name); instant_remote_process(["docker rm -f $container_name"], $application->destination->server); $return_payloads->push([ 'application' => $application->name, diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index c28f22742..530136378 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -19,6 +19,7 @@ use App\Notifications\Application\DeploymentFailed; use App\Notifications\Application\DeploymentSuccess; use App\Traits\ExecuteRemoteCommand; use Carbon\Carbon; +use Exception; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldBeEncrypted; use Illuminate\Contracts\Queue\ShouldQueue; @@ -1207,7 +1208,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue if ($this->application->custom_healthcheck_found) { $this->application_deployment_queue->addLogEntry('Custom healthcheck found, skipping default healthcheck.'); } - // ray('New container name: ', $this->container_name); if ($this->container_name) { $counter = 1; $this->application_deployment_queue->addLogEntry('Waiting for healthcheck to pass on the new container.'); @@ -1410,7 +1410,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue continue; } - // ray('Deploying to additional destination: ', $server->name); $deployment_uuid = new Cuid2; queue_application_deployment( deployment_uuid: $deployment_uuid, @@ -2023,6 +2022,8 @@ LABEL coolify.deploymentId={$this->deployment_uuid} COPY . . RUN rm -f /usr/share/nginx/html/nginx.conf RUN rm -f /usr/share/nginx/html/Dockerfile +RUN rm -f /usr/share/nginx/html/docker-compose.yaml +RUN rm -f /usr/share/nginx/html/.env COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); if (str($this->application->custom_nginx_configuration)->isNotEmpty()) { $nginx_config = base64_encode($this->application->custom_nginx_configuration); diff --git a/app/Jobs/StripeProcessJob.php b/app/Jobs/StripeProcessJob.php index d61c738f4..f1c5bc1a8 100644 --- a/app/Jobs/StripeProcessJob.php +++ b/app/Jobs/StripeProcessJob.php @@ -73,19 +73,21 @@ class StripeProcessJob implements ShouldQueue } $subscription = Subscription::where('team_id', $teamId)->first(); if ($subscription) { - send_internal_notification('Old subscription activated for team: '.$teamId); + // send_internal_notification('Old subscription activated for team: '.$teamId); $subscription->update([ 'stripe_subscription_id' => $subscriptionId, 'stripe_customer_id' => $customerId, 'stripe_invoice_paid' => true, + 'stripe_past_due' => false, ]); } else { - send_internal_notification('New subscription for team: '.$teamId); + // send_internal_notification('New subscription for team: '.$teamId); Subscription::create([ 'team_id' => $teamId, 'stripe_subscription_id' => $subscriptionId, 'stripe_customer_id' => $customerId, 'stripe_invoice_paid' => true, + 'stripe_past_due' => false, ]); } break; @@ -100,6 +102,7 @@ class StripeProcessJob implements ShouldQueue if ($subscription) { $subscription->update([ 'stripe_invoice_paid' => true, + 'stripe_past_due' => false, ]); } else { throw new \RuntimeException("No subscription found for customer: {$customerId}"); @@ -119,9 +122,7 @@ class StripeProcessJob implements ShouldQueue } if (! $subscription->stripe_invoice_paid) { SubscriptionInvoiceFailedJob::dispatch($team); - send_internal_notification('Invoice payment failed: '.$customerId); - } else { - send_internal_notification('Invoice payment failed but already paid: '.$customerId); + // send_internal_notification('Invoice payment failed: '.$customerId); } break; case 'payment_intent.payment_failed': @@ -136,7 +137,7 @@ class StripeProcessJob implements ShouldQueue return; } - send_internal_notification('Subscription payment failed for customer: '.$customerId); + // send_internal_notification('Subscription payment failed for customer: '.$customerId); break; case 'customer.subscription.created': $customerId = data_get($data, 'customer'); @@ -158,7 +159,7 @@ class StripeProcessJob implements ShouldQueue } $subscription = Subscription::where('team_id', $teamId)->first(); if ($subscription) { - send_internal_notification("Subscription already exists for team: {$teamId}"); + // send_internal_notification("Subscription already exists for team: {$teamId}"); throw new \RuntimeException("Subscription already exists for team: {$teamId}"); } else { Subscription::create([ @@ -182,7 +183,7 @@ class StripeProcessJob implements ShouldQueue $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); if (! $subscription) { if ($status === 'incomplete_expired') { - send_internal_notification('Subscription incomplete expired'); + // send_internal_notification('Subscription incomplete expired'); throw new \RuntimeException('Subscription incomplete expired'); } if ($teamId) { @@ -224,9 +225,33 @@ class StripeProcessJob implements ShouldQueue ]); } } + if ($status === 'past_due') { + if ($subscription->stripe_subscription_id === $subscriptionId) { + $subscription->update([ + 'stripe_past_due' => true, + ]); + send_internal_notification('Past Due: '.$customerId.'Subscription ID: '.$subscriptionId); + } + } + if ($status === 'unpaid') { + if ($subscription->stripe_subscription_id === $subscriptionId) { + $subscription->update([ + 'stripe_invoice_paid' => false, + ]); + send_internal_notification('Unpaid: '.$customerId.'Subscription ID: '.$subscriptionId); + } + $team = data_get($subscription, 'team'); + if ($team) { + $team->subscriptionEnded(); + } else { + send_internal_notification('Subscription unpaid but no team found in Coolify for customer: '.$customerId); + throw new \RuntimeException("No team found in Coolify for customer: {$customerId}"); + } + } if ($status === 'active') { if ($subscription->stripe_subscription_id === $subscriptionId) { $subscription->update([ + 'stripe_past_due' => false, 'stripe_invoice_paid' => true, ]); } diff --git a/app/Livewire/Help.php b/app/Livewire/Help.php index f51527fbe..913710588 100644 --- a/app/Livewire/Help.php +++ b/app/Livewire/Help.php @@ -36,7 +36,7 @@ class Help extends Component $type = set_transanctional_email_settings($settings); // Sending feedback through Cloud API - if ($type === false) { + if (blank($type)) { $url = 'https://app.coolify.io/api/feedback'; Http::post($url, [ 'content' => 'User: `'.auth()->user()?->email.'` with subject: `'.$this->subject.'` has the following problem: `'.$this->description.'`', diff --git a/app/Livewire/MonacoEditor.php b/app/Livewire/MonacoEditor.php index 42d276e64..53ca1d386 100644 --- a/app/Livewire/MonacoEditor.php +++ b/app/Livewire/MonacoEditor.php @@ -2,7 +2,7 @@ namespace App\Livewire; -//use Livewire\Component; +// use Livewire\Component; use Illuminate\View\Component; use Visus\Cuid2\Cuid2; diff --git a/app/Livewire/Project/New/DockerCompose.php b/app/Livewire/Project/New/DockerCompose.php index 27975eaa2..2f51094d1 100644 --- a/app/Livewire/Project/New/DockerCompose.php +++ b/app/Livewire/Project/New/DockerCompose.php @@ -52,12 +52,6 @@ class DockerCompose extends Component 'dockerComposeRaw' => 'required', ]); $this->dockerComposeRaw = Yaml::dump(Yaml::parse($this->dockerComposeRaw), 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); - - $isValid = validateComposeFile($this->dockerComposeRaw, $server_id); - if ($isValid !== 'OK') { - return $this->dispatch('error', "Invalid docker-compose file.\n$isValid"); - } - $project = Project::where('uuid', $this->parameters['project_uuid'])->first(); $environment = $project->load(['environments'])->environments->where('uuid', $this->parameters['environment_uuid'])->first(); diff --git a/app/Livewire/Project/Service/EditCompose.php b/app/Livewire/Project/Service/EditCompose.php index dc043e65a..b5f208941 100644 --- a/app/Livewire/Project/Service/EditCompose.php +++ b/app/Livewire/Project/Service/EditCompose.php @@ -31,12 +31,22 @@ class EditCompose extends Component public function refreshEnvs() { - $this->service = Service::find($this->serviceId); + $this->service = Service::ownedByCurrentTeam()->find($this->serviceId); } public function mount() { - $this->service = Service::find($this->serviceId); + $this->service = Service::ownedByCurrentTeam()->find($this->serviceId); + } + + public function validateCompose() + { + $isValid = validateComposeFile($this->service->docker_compose_raw, $this->service->server_id); + if ($isValid !== 'OK') { + $this->dispatch('error', "Invalid docker-compose file.\n$isValid"); + } else { + $this->dispatch('success', 'Docker compose is valid.'); + } } public function saveEditedCompose() diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.php index 2c751aa92..368598466 100644 --- a/app/Livewire/Project/Service/StackForm.php +++ b/app/Livewire/Project/Service/StackForm.php @@ -63,7 +63,7 @@ class StackForm extends Component public function saveCompose($raw) { $this->service->docker_compose_raw = $raw; - $this->submit(notify: false); + $this->submit(notify: true); } public function instantSave() @@ -76,10 +76,6 @@ class StackForm extends Component { try { $this->validate(); - $isValid = validateComposeFile($this->service->docker_compose_raw, $this->service->server->id); - if ($isValid !== 'OK') { - throw new \Exception("Invalid docker-compose file.\n$isValid"); - } $this->service->save(); $this->service->saveExtraFields($this->fields); $this->service->parse(); diff --git a/app/Livewire/Project/Shared/ScheduledTask/Add.php b/app/Livewire/Project/Shared/ScheduledTask/Add.php index adfd59217..8ab5f9f27 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/Add.php +++ b/app/Livewire/Project/Shared/ScheduledTask/Add.php @@ -2,15 +2,22 @@ namespace App\Livewire\Project\Shared\ScheduledTask; +use App\Models\ScheduledTask; use Illuminate\Support\Collection; +use Livewire\Attributes\Locked; use Livewire\Component; class Add extends Component { public $parameters; + #[Locked] + public string $id; + + #[Locked] public string $type; + #[Locked] public Collection $containerNames; public string $name; @@ -21,8 +28,6 @@ class Add extends Component public ?string $container = ''; - protected $listeners = ['clearScheduledTask' => 'clear']; - protected $rules = [ 'name' => 'required|string', 'command' => 'required|string', @@ -60,18 +65,42 @@ class Add extends Component $this->container = $this->subServiceName; } } - $this->dispatch('saveScheduledTask', [ - 'name' => $this->name, - 'command' => $this->command, - 'frequency' => $this->frequency, - 'container' => $this->container, - ]); + $this->saveScheduledTask(); $this->clear(); } catch (\Exception $e) { return handleError($e, $this); } } + public function saveScheduledTask() + { + try { + $task = new ScheduledTask(); + $task->name = $this->name; + $task->command = $this->command; + $task->frequency = $this->frequency; + $task->container = $this->container; + $task->team_id = currentTeam()->id; + + switch ($this->type) { + case 'application': + $task->application_id = $this->id; + break; + case 'standalone-postgresql': + $task->standalone_postgresql_id = $this->id; + break; + case 'service': + $task->service_id = $this->id; + break; + } + $task->save(); + $this->dispatch('refreshTasks'); + $this->dispatch('success', 'Scheduled task added.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function clear() { $this->name = ''; diff --git a/app/Livewire/Project/Shared/ScheduledTask/All.php b/app/Livewire/Project/Shared/ScheduledTask/All.php index 6ab8426f3..1782f3f27 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/All.php +++ b/app/Livewire/Project/Shared/ScheduledTask/All.php @@ -4,20 +4,22 @@ namespace App\Livewire\Project\Shared\ScheduledTask; use App\Models\ScheduledTask; use Illuminate\Support\Collection; +use Livewire\Attributes\Locked; +use Livewire\Attributes\On; use Livewire\Component; class All extends Component { + #[Locked] public $resource; + #[Locked] + public array $parameters; + public Collection $containerNames; public ?string $variables = null; - public array $parameters; - - protected $listeners = ['refreshTasks', 'saveScheduledTask' => 'submit']; - public function mount() { $this->parameters = get_route_parameters(); @@ -35,37 +37,10 @@ class All extends Component } } + #[On('refreshTasks')] public function refreshTasks() { $this->resource->refresh(); } - public function submit($data) - { - try { - $task = new ScheduledTask; - $task->name = $data['name']; - $task->command = $data['command']; - $task->frequency = $data['frequency']; - $task->container = $data['container']; - $task->team_id = currentTeam()->id; - - switch ($this->resource->type()) { - case 'application': - $task->application_id = $this->resource->id; - break; - case 'standalone-postgresql': - $task->standalone_postgresql_id = $this->resource->id; - break; - case 'service': - $task->service_id = $this->resource->id; - break; - } - $task->save(); - $this->refreshTasks(); - $this->dispatch('success', 'Scheduled task added.'); - } catch (\Throwable $e) { - return handleError($e, $this); - } - } } diff --git a/app/Livewire/Project/Shared/ScheduledTask/Show.php b/app/Livewire/Project/Shared/ScheduledTask/Show.php index 171ba3bb2..6d9c6982a 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/Show.php +++ b/app/Livewire/Project/Shared/ScheduledTask/Show.php @@ -133,9 +133,9 @@ class Show extends Component $this->task->delete(); if ($this->type === 'application') { - return redirect()->route('project.application.configuration', $this->parameters, $this->task->name); + return redirect()->route('project.application.scheduled-tasks.show', $this->parameters); } else { - return redirect()->route('project.service.configuration', $this->parameters, $this->task->name); + return redirect()->route('project.service.scheduled-tasks.show', $this->parameters); } } catch (\Exception $e) { return handleError($e); diff --git a/app/Livewire/Project/Shared/Webhooks.php b/app/Livewire/Project/Shared/Webhooks.php index aab1fdc47..57c65c4dd 100644 --- a/app/Livewire/Project/Shared/Webhooks.php +++ b/app/Livewire/Project/Shared/Webhooks.php @@ -29,8 +29,6 @@ class Webhooks extends Component public function mount() { - // ray()->clearAll(); - // ray()->showQueries(); $this->deploywebhook = generateDeployWebhook($this->resource); $this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github'); diff --git a/app/Livewire/Server/Proxy/Deploy.php b/app/Livewire/Server/Proxy/Deploy.php index 4f9d41092..f823ff3d4 100644 --- a/app/Livewire/Server/Proxy/Deploy.php +++ b/app/Livewire/Server/Proxy/Deploy.php @@ -105,7 +105,6 @@ class Deploy extends Component $startTime = Carbon::now()->getTimestamp(); while ($process->running()) { - ray('running'); if (Carbon::now()->getTimestamp() - $startTime >= $timeout) { $this->forceStopContainer($containerName); break; diff --git a/app/Livewire/SettingsEmail.php b/app/Livewire/SettingsEmail.php index 058f080e4..15e68306f 100644 --- a/app/Livewire/SettingsEmail.php +++ b/app/Livewire/SettingsEmail.php @@ -36,7 +36,7 @@ class SettingsEmail extends Component public ?int $smtpPort = null; #[Validate(['nullable', 'string', 'in:starttls,tls,none'])] - public ?string $smtpEncryption = null; + public ?string $smtpEncryption = 'starttls'; #[Validate(['nullable', 'string'])] public ?string $smtpUsername = null; diff --git a/app/Livewire/Source/Github/Change.php b/app/Livewire/Source/Github/Change.php index fc597748e..20f52c322 100644 --- a/app/Livewire/Source/Github/Change.php +++ b/app/Livewire/Source/Github/Change.php @@ -101,7 +101,6 @@ class Change extends Component // ]); // } - // ray($runners_by_repository); // } public function mount() diff --git a/app/Models/Server.php b/app/Models/Server.php index 187685d66..828500c40 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Stringable; use OpenApi\Attributes as OA; @@ -24,6 +25,7 @@ use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; use Spatie\SchemalessAttributes\SchemalessAttributesTrait; use Spatie\Url\Url; use Symfony\Component\Yaml\Yaml; +use Visus\Cuid2\Cuid2; #[OA\Schema( description: 'Server model', @@ -101,11 +103,13 @@ class Server extends BaseModel 'server_id' => $server->id, ]); } else { - StandaloneDocker::create([ + $standaloneDocker = new StandaloneDocker([ 'name' => 'coolify', + 'uuid' => (string) new Cuid2, 'network' => 'coolify', 'server_id' => $server->id, ]); + $standaloneDocker->saveQuietly(); } } if (! isset($server->proxy->redirect_enabled)) { @@ -437,10 +441,6 @@ class Server extends BaseModel "mkdir -p $dynamic_config_path", "echo '$base64' | base64 -d | tee $file > /dev/null", ], $this); - - if (config('app.env') === 'local') { - // ray($yaml); - } } } elseif ($this->proxyType() === 'CADDY') { $file = "$dynamic_config_path/coolify.caddy"; @@ -709,22 +709,6 @@ $schema://$host { ]; } - public function getContainersWithSentinel(): Collection - { - $sentinel_found = instant_remote_process(['docker inspect coolify-sentinel'], $this, false); - $sentinel_found = json_decode($sentinel_found, true); - $status = data_get($sentinel_found, '0.State.Status', 'exited'); - if ($status === 'running') { - $containers = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/containers"'], $this, false); - if (is_null($containers)) { - return collect([]); - } - $containers = data_get(json_decode($containers, true), 'containers', []); - - return collect($containers); - } - } - public function loadAllContainers(): Collection { if ($this->isFunctional()) { @@ -970,10 +954,8 @@ $schema://$host { } }); if ($supported->count() === 1) { - // ray('supported'); return str($supported->first()); } else { - // ray('not supported'); return false; } } @@ -1042,7 +1024,7 @@ $schema://$host { $unreachableNotificationSent = (bool) $this->unreachable_notification_sent; $isReachable = (bool) $this->settings->is_reachable; - \Log::debug('Server reachability check', [ + Log::debug('Server reachability check', [ 'server_id' => $this->id, 'is_reachable' => $isReachable, 'notification_sent' => $unreachableNotificationSent, @@ -1054,7 +1036,7 @@ $schema://$host { $this->save(); if ($unreachableNotificationSent === true) { - \Log::debug('Server is now reachable, sending notification', [ + Log::debug('Server is now reachable, sending notification', [ 'server_id' => $this->id, ]); $this->sendReachableNotification(); @@ -1064,7 +1046,7 @@ $schema://$host { } $this->increment('unreachable_count'); - \Log::debug('Incremented unreachable count', [ + Log::debug('Incremented unreachable count', [ 'server_id' => $this->id, 'new_count' => $this->unreachable_count, ]); @@ -1072,7 +1054,7 @@ $schema://$host { if ($this->unreachable_count === 1) { $this->settings->is_reachable = true; $this->settings->save(); - \Log::debug('First unreachable attempt, marking as reachable', [ + Log::debug('First unreachable attempt, marking as reachable', [ 'server_id' => $this->id, ]); @@ -1083,7 +1065,7 @@ $schema://$host { $failedChecks = 0; for ($i = 0; $i < 3; $i++) { $status = $this->serverStatus(); - \Log::debug('Additional reachability check', [ + Log::debug('Additional reachability check', [ 'server_id' => $this->id, 'attempt' => $i + 1, 'status' => $status, @@ -1095,7 +1077,7 @@ $schema://$host { } if ($failedChecks === 3 && ! $unreachableNotificationSent) { - \Log::debug('Server confirmed unreachable after 3 attempts, sending notification', [ + Log::debug('Server confirmed unreachable after 3 attempts, sending notification', [ 'server_id' => $this->id, ]); $this->sendUnreachableNotification(); diff --git a/app/Models/Team.php b/app/Models/Team.php index 467cf45bc..6796b22ad 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -93,6 +93,15 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, Sen return $servers >= $serverLimit; } + public function subscriptionPastOverDue() + { + if (isCloud()) { + return $this->subscription?->stripe_past_due; + } + + return false; + } + public function serverOverflow() { if ($this->serverLimit() < $this->servers->count()) { @@ -185,6 +194,7 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, Sen 'stripe_cancel_at_period_end' => false, 'stripe_invoice_paid' => false, 'stripe_trial_already_ended' => false, + 'stripe_past_due' => false, ]); foreach ($this->servers as $server) { $server->settings()->update([ diff --git a/app/Notifications/Application/DeploymentSuccess.php b/app/Notifications/Application/DeploymentSuccess.php index c6bbf43ac..9b59d9162 100644 --- a/app/Notifications/Application/DeploymentSuccess.php +++ b/app/Notifications/Application/DeploymentSuccess.php @@ -44,7 +44,7 @@ class DeploymentSuccess extends CustomEmailNotification if (str($this->fqdn)->explode(',')->count() > 1) { $this->fqdn = str($this->fqdn)->explode(',')->first(); } - $this->deployment_url = base_url()."/project/{$this->project_uuid}/environments/{$this->environment_uuid}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}"; + $this->deployment_url = base_url()."/project/{$this->project_uuid}/environment/{$this->environment_uuid}/application/{$this->application->uuid}/deployment/{$this->deployment_uuid}"; } public function via(object $notifiable): array diff --git a/app/Notifications/Application/StatusChanged.php b/app/Notifications/Application/StatusChanged.php index 34c5ed747..fab5487ef 100644 --- a/app/Notifications/Application/StatusChanged.php +++ b/app/Notifications/Application/StatusChanged.php @@ -34,7 +34,7 @@ class StatusChanged extends CustomEmailNotification if (str($this->fqdn)->explode(',')->count() > 1) { $this->fqdn = str($this->fqdn)->explode(',')->first(); } - $this->resource_url = base_url()."/project/{$this->project_uuid}/environments/{$this->environment_uuid}/application/{$this->resource->uuid}"; + $this->resource_url = base_url()."/project/{$this->project_uuid}/environment/{$this->environment_uuid}/application/{$this->resource->uuid}"; } public function via(object $notifiable): array diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index 98536d346..b8589cd8e 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -50,11 +50,9 @@ class EmailChannel if ($emailSettings->use_instance_email_settings) { $type = set_transanctional_email_settings(); - if (! $type) { + if (blank($type)) { throw new Exception('No email settings found.'); } - config()->set('mail.default', $type); - return; } diff --git a/app/Notifications/Channels/TransactionalEmailChannel.php b/app/Notifications/Channels/TransactionalEmailChannel.php index 761780231..114d1f6ed 100644 --- a/app/Notifications/Channels/TransactionalEmailChannel.php +++ b/app/Notifications/Channels/TransactionalEmailChannel.php @@ -35,7 +35,7 @@ class TransactionalEmailChannel private function bootConfigs(): void { $type = set_transanctional_email_settings(); - if (! $type) { + if (blank($type)) { throw new Exception('No email settings found.'); } } diff --git a/app/Notifications/Dto/PushoverMessage.php b/app/Notifications/Dto/PushoverMessage.php index 0efd1d526..abf6f1b7a 100644 --- a/app/Notifications/Dto/PushoverMessage.php +++ b/app/Notifications/Dto/PushoverMessage.php @@ -40,7 +40,7 @@ class PushoverMessage if ($buttonUrl && str_contains($buttonUrl, 'http://localhost')) { $buttonUrl = str_replace('http://localhost', config('app.url'), $buttonUrl); } - $payload['message'] .= " " . $text . ''; + $payload['message'] .= " ".$text.''; } Log::info('Pushover message', $payload); diff --git a/app/Notifications/TransactionalEmails/ResetPassword.php b/app/Notifications/TransactionalEmails/ResetPassword.php index 3938a8da7..4593ddb0d 100644 --- a/app/Notifications/TransactionalEmails/ResetPassword.php +++ b/app/Notifications/TransactionalEmails/ResetPassword.php @@ -3,6 +3,7 @@ namespace App\Notifications\TransactionalEmails; use App\Models\InstanceSettings; +use Exception; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; @@ -35,8 +36,8 @@ class ResetPassword extends Notification public function via($notifiable) { $type = set_transanctional_email_settings(); - if (! $type) { - throw new \Exception('No email settings found.'); + if (blank($type)) { + throw new Exception('No email settings found.'); } return ['mail']; diff --git a/app/Traits/HasNotificationSettings.php b/app/Traits/HasNotificationSettings.php index ef858d0b6..bb088896a 100644 --- a/app/Traits/HasNotificationSettings.php +++ b/app/Traits/HasNotificationSettings.php @@ -4,9 +4,9 @@ namespace App\Traits; use App\Notifications\Channels\DiscordChannel; use App\Notifications\Channels\EmailChannel; +use App\Notifications\Channels\PushoverChannel; use App\Notifications\Channels\SlackChannel; use App\Notifications\Channels\TelegramChannel; -use App\Notifications\Channels\PushoverChannel; use Illuminate\Database\Eloquent\Model; trait HasNotificationSettings diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index 73d5389ae..d5283898e 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -91,8 +91,6 @@ function next_queuable(string $server_id, string $application_id): bool $server = Server::find($server_id); $concurrent_builds = $server->settings->concurrent_builds; - // ray("serverId:{$server->id}", "concurrentBuilds:{$concurrent_builds}", "deployments:{$deployments->count()}", "sameApplicationDeployments:{$same_application_deployments->count()}")->green(); - if ($deployments->count() > $concurrent_builds) { return false; } diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 696f6a8c4..80e19d80f 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -778,7 +778,6 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null) } } } - ray($payload); $compose_options->put('deploy', [ 'resources' => [ 'reservations' => [ @@ -829,26 +828,29 @@ function generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker function validateComposeFile(string $compose, int $server_id): string|Throwable { - return 'OK'; + $uuid = Str::random(18); + $server = Server::ownedByCurrentTeam()->find($server_id); try { - $uuid = Str::random(10); - $server = Server::findOrFail($server_id); + if (! $server) { + throw new \Exception('Server not found'); + } $base64_compose = base64_encode($compose); - $output = instant_remote_process([ + instant_remote_process([ "echo {$base64_compose} | base64 -d | tee /tmp/{$uuid}.yml > /dev/null", - "docker compose -f /tmp/{$uuid}.yml config", + "chmod 600 /tmp/{$uuid}.yml", + "docker compose -f /tmp/{$uuid}.yml config --no-interpolate --no-path-resolution -q", + "rm /tmp/{$uuid}.yml", ], $server); - ray($output); return 'OK'; } catch (\Throwable $e) { - ray($e); - return $e->getMessage(); } finally { - instant_remote_process([ - "rm /tmp/{$uuid}.yml", - ], $server); + if (filled($server)) { + instant_remote_process([ + "rm /tmp/{$uuid}.yml", + ], $server, throwError: false); + } } } diff --git a/bootstrap/helpers/notifications.php b/bootstrap/helpers/notifications.php index 46f0ebca7..b0345df7e 100644 --- a/bootstrap/helpers/notifications.php +++ b/bootstrap/helpers/notifications.php @@ -28,7 +28,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null { $settings = instanceSettings(); $type = set_transanctional_email_settings($settings); - if (! $type) { + if (blank($type)) { throw new Exception('No email settings found.'); } if ($cc) { @@ -54,15 +54,19 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null } } -function set_transanctional_email_settings(?InstanceSettings $settings = null): ?string // +function set_transanctional_email_settings(?InstanceSettings $settings = null): ?string // returns null|resend|smtp and defaults to array based on mail.php config { if (! $settings) { $settings = instanceSettings(); } - config()->set('mail.from.address', data_get($settings, 'smtp_from_address')); - config()->set('mail.from.name', data_get($settings, 'smtp_from_name')); + if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) { + return null; + } + if (data_get($settings, 'resend_enabled')) { config()->set('mail.default', 'resend'); + config()->set('mail.from.address', data_get($settings, 'smtp_from_address')); + config()->set('mail.from.name', data_get($settings, 'smtp_from_name')); config()->set('resend.api_key', data_get($settings, 'resend_api_key')); return 'resend'; @@ -76,6 +80,8 @@ function set_transanctional_email_settings(?InstanceSettings $settings = null): }; if (data_get($settings, 'smtp_enabled')) { + config()->set('mail.from.address', data_get($settings, 'smtp_from_address')); + config()->set('mail.from.name', data_get($settings, 'smtp_from_name')); config()->set('mail.default', 'smtp'); config()->set('mail.mailers.smtp', [ 'transport' => 'smtp', @@ -91,6 +97,4 @@ function set_transanctional_email_settings(?InstanceSettings $settings = null): return 'smtp'; } - - return null; } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 3fba7edb7..17ddcbda0 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -748,6 +748,7 @@ function parseCommandFromMagicEnvVariable(Str|string $key): Stringable { $value = str($key); $count = substr_count($value->value(), '_'); + $command = null; if ($count === 2) { if ($value->startsWith('SERVICE_FQDN') || $value->startsWith('SERVICE_URL')) { // SERVICE_FQDN_UMAMI @@ -800,7 +801,6 @@ function parseEnvVariable(Str|string $value) } else { // SERVICE_BASE64_64_UMAMI $command = $value->after('SERVICE_')->beforeLast('_'); - ray($command); } } } @@ -952,7 +952,6 @@ function validate_dns_entry(string $fqdn, Server $server) $type = \PurplePixie\PhpDns\DNSTypes::NAME_A; foreach ($dns_servers as $dns_server) { try { - ray("Checking $host on $dns_server"); $query = new DNSQuery($dns_server); $results = $query->query($host, $type); if ($results === false || $query->hasError()) { @@ -961,13 +960,10 @@ function validate_dns_entry(string $fqdn, Server $server) foreach ($results as $result) { if ($result->getType() == $type) { if (ip_match($result->getData(), $cloudflare_ips->toArray(), $match)) { - ray("Found match in Cloudflare IPs: $match"); $found_matching_ip = true; break; } if ($result->getData() === $ip) { - ray($host.' has IP address '.$result->getData()); - ray($result->getString()); $found_matching_ip = true; break; } @@ -977,7 +973,6 @@ function validate_dns_entry(string $fqdn, Server $server) } catch (\Exception) { } } - ray("Found match: $found_matching_ip"); return $found_matching_ip; } @@ -1331,7 +1326,6 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null); if ((is_null($isDirectory) || ! $isDirectory) && is_null($content)) { // if isDirectory is not set (or false) & content is also not set, we assume it is a directory - ray('setting isDirectory to true'); $isDirectory = true; } } @@ -1499,7 +1493,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal $serviceLabels->push("$removedLabelName=$removedLabel"); } } - $containerName = "$serviceName-{$resource->uuid}"; // Decide if the service is a database @@ -1662,7 +1655,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } if (is_null($isDirectory) && is_null($content)) { // if isDirectory is not set & content is also not set, we assume it is a directory - ray('setting isDirectory to true'); $isDirectory = true; } } @@ -2529,9 +2521,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal } } } - if ($collectedPorts->count() > 0) { - ray($collectedPorts->implode(',')); - } $definedNetworkExists = $topLevelNetworks->contains(function ($value, $_) use ($definedNetwork) { return $value == $definedNetwork; }); @@ -2956,7 +2945,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int } $parsedServices = collect([]); - // ray()->clearAll(); $allMagicEnvironments = collect([]); foreach ($services as $serviceName => $service) { @@ -3016,7 +3004,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $environment = $environment->merge($buildArgs); // convert environment variables to one format - $environment = convertComposeEnvironmentToArray($environment); + $environment = convertToKeyValueCollection($environment); // Add Coolify defined environments $allEnvironments = $resource->environment_variables()->get(['key', 'value']); @@ -3197,7 +3185,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $buildArgs = collect(data_get($service, 'build.args', [])); $environment = $environment->merge($buildArgs); - $environment = convertComposeEnvironmentToArray($environment); + $environment = convertToKeyValueCollection($environment); $coolifyEnvironments = collect([]); $isDatabase = isDatabaseImage(data_get_str($service, 'image')); @@ -3934,7 +3922,7 @@ function add_coolify_default_environment_variables(StandaloneRedis|StandalonePos } } -function convertComposeEnvironmentToArray($environment) +function convertToKeyValueCollection($environment) { $convertedServiceVariables = collect([]); if (isAssociativeArray($environment)) { diff --git a/config/chunk-upload.php b/config/chunk-upload.php index a0baf8139..e577eb858 100644 --- a/config/chunk-upload.php +++ b/config/chunk-upload.php @@ -1,4 +1,5 @@ [ - 'version' => '4.0.0-beta.396', + 'version' => '4.0.0-beta.398', 'helper_version' => '1.0.7', 'realtime_version' => '1.0.6', 'self_hosted' => env('SELF_HOSTED', true), diff --git a/config/database.php b/config/database.php index 6f4acbfd2..a40987de8 100644 --- a/config/database.php +++ b/config/database.php @@ -38,7 +38,7 @@ return [ 'pgsql' => [ 'driver' => 'pgsql', 'url' => env('DATABASE_URL'), - 'host' => env('DB_HOST', 'postgres'), + 'host' => env('DB_HOST', 'coolify-db'), 'port' => env('DB_PORT', '5432'), 'database' => env('DB_DATABASE', 'coolify'), 'username' => env('DB_USERNAME', 'coolify'), diff --git a/config/debugbar.php b/config/debugbar.php index daeea96b6..4bc660fff 100644 --- a/config/debugbar.php +++ b/config/debugbar.php @@ -234,7 +234,7 @@ return [ ], 'views' => [ 'timeline' => false, // Add the views to the timeline (Experimental) - 'data' => false, //true for all data, 'keys' for only names, false for no parameters. + 'data' => false, // true for all data, 'keys' for only names, false for no parameters. 'group' => 50, // Group duplicate views. Pass value to auto-group, or true/false to force 'exclude_paths' => [ // Add the paths which you don't want to appear in the views 'vendor/filament', // Exclude Filament components by default diff --git a/config/mail.php b/config/mail.php index 26af507d9..5b647944b 100644 --- a/config/mail.php +++ b/config/mail.php @@ -13,7 +13,7 @@ return [ | */ - 'default' => env('MAIL_MAILER', null), + 'default' => env('MAIL_MAILER', 'array'), /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2025_02_27_125249_add_index_to_scheduled_task_executions.php b/database/migrations/2025_02_27_125249_add_index_to_scheduled_task_executions.php new file mode 100644 index 000000000..45c6b581d --- /dev/null +++ b/database/migrations/2025_02_27_125249_add_index_to_scheduled_task_executions.php @@ -0,0 +1,38 @@ +index(['scheduled_task_id', 'created_at'], 'scheduled_task_executions_task_id_created_at_index'); + }); + + Schema::table('scheduled_database_backup_executions', function (Blueprint $table) { + $table->index( + ['scheduled_database_backup_id', 'created_at'], + 'scheduled_db_backup_executions_backup_id_created_at_index' + ); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('scheduled_task_executions', function (Blueprint $table) { + $table->dropIndex('scheduled_task_executions_task_id_created_at_index'); + }); + Schema::table('scheduled_database_backup_executions', function (Blueprint $table) { + $table->dropIndex('scheduled_db_backup_executions_backup_id_created_at_index'); + }); + } +}; diff --git a/database/migrations/2025_03_01_112617_add_stripe_past_due.php b/database/migrations/2025_03_01_112617_add_stripe_past_due.php new file mode 100644 index 000000000..6edb4f698 --- /dev/null +++ b/database/migrations/2025_03_01_112617_add_stripe_past_due.php @@ -0,0 +1,28 @@ +boolean('stripe_past_due')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('subscriptions', function (Blueprint $table) { + $table->dropColumn('stripe_past_due'); + }); + } +}; diff --git a/other/nightly/docker-compose.prod.yml b/other/nightly/docker-compose.prod.yml index 2e46438bd..23a65cca6 100644 --- a/other/nightly/docker-compose.prod.yml +++ b/other/nightly/docker-compose.prod.yml @@ -61,7 +61,7 @@ services: retries: 10 timeout: 2s soketi: - image: 'ghcr.io/coollabsio/coolify-realtime:1.0.5' + image: 'ghcr.io/coollabsio/coolify-realtime:1.0.6' ports: - "${SOKETI_PORT:-6001}:6001" - "6002:6002" diff --git a/other/nightly/versions.json b/other/nightly/versions.json index fa0e454d7..8d1c91433 100644 --- a/other/nightly/versions.json +++ b/other/nightly/versions.json @@ -1,10 +1,10 @@ { "coolify": { "v4": { - "version": "4.0.0-beta.382" + "version": "4.0.0-beta.397" }, "nightly": { - "version": "4.0.0-beta.383" + "version": "4.0.0-beta.398" }, "helper": { "version": "1.0.7" diff --git a/resources/views/livewire/layout-popups.blade.php b/resources/views/livewire/layout-popups.blade.php index 53c8ab1d6..c639b4627 100644 --- a/resources/views/livewire/layout-popups.blade.php +++ b/resources/views/livewire/layout-popups.blade.php @@ -79,6 +79,16 @@ + @if (currentTeam()->subscriptionPastOverDue()) + +
WARNING: Your subscription is in over-due. If your latest + payment is not paid within a week, all automations will + be deactivated. Visit /subscription to check your subscription status or pay your + invoice (or check your email for the invoice). +
+
+ @endif @if (currentTeam()->serverOverflow())
WARNING: The number of active servers exceeds the limit diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php index 81c628998..3e6bcd1c6 100644 --- a/resources/views/livewire/project/service/configuration.blade.php +++ b/resources/views/livewire/project/service/configuration.blade.php @@ -176,7 +176,9 @@
Persistent storage to preserve data between deployments.
If you would like to add a volume, you must add it to - your compose file (Service Stack tab).
+ your compose file (General tab). @foreach ($applications as $application) diff --git a/resources/views/livewire/project/service/edit-compose.blade.php b/resources/views/livewire/project/service/edit-compose.blade.php index beaccac91..df0b857b5 100644 --- a/resources/views/livewire/project/service/edit-compose.blade.php +++ b/resources/views/livewire/project/service/edit-compose.blade.php @@ -20,27 +20,29 @@
- -
-
- Switch - Textarea +
+ +
+
-
-
-
- Show Deployable Compose -
-
- Show Source - Compose -
+
+
+ Show Deployable Compose +
+
+ Show Source + Compose
- + @if (blank($service->service_type)) + + Validate + + @endif + Save
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php index b37137923..550b43c20 100644 --- a/resources/views/livewire/project/service/file-storage.blade.php +++ b/resources/views/livewire/project/service/file-storage.blade.php @@ -21,15 +21,6 @@ ]" confirmationText="{{ $fs_path }}" confirmationLabel="Please confirm the execution of the actions by entering the Filepath below" shortConfirmationLabel="Filepath" :confirmWithPassword="false" step2ButtonText="Convert to file" /> - @else - - @endif - @if ($fileStorage->is_directory) @else + @endif - - @if (!$fileStorage->is_based_on_git) + {{-- @if (!$fileStorage->is_based_on_git)
This storage will be deleted. It is not reversible. Please @@ -58,7 +54,7 @@ label="Permanently delete file from the server?"> @endif - @endif + @endif --}}
@if (!$fileStorage->is_directory) @if (data_get($resource, 'settings.is_preserve_repository_enabled')) @@ -75,6 +71,5 @@ Save @endif @endif -
diff --git a/resources/views/livewire/project/shared/scheduled-task/all.blade.php b/resources/views/livewire/project/shared/scheduled-task/all.blade.php index 034954810..296b60dc8 100644 --- a/resources/views/livewire/project/shared/scheduled-task/all.blade.php +++ b/resources/views/livewire/project/shared/scheduled-task/all.blade.php @@ -3,9 +3,9 @@

Scheduled Tasks

@if ($resource->type() == 'application') - + @elseif ($resource->type() == 'service') - + @endif
diff --git a/resources/views/livewire/settings/index.blade.php b/resources/views/livewire/settings/index.blade.php index 2bf2402a2..8b1c6cfed 100644 --- a/resources/views/livewire/settings/index.blade.php +++ b/resources/views/livewire/settings/index.blade.php @@ -132,12 +132,12 @@

Confirmation Settings

@if ($disable_two_step_confirmation) -
+
@else -
+