An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Merge remote-tracking branch 'origin/next' into env-var-descriptions
Andras Bacsaid9e39ba21121
diff --cc app/Livewire/Project/Shared/EnvironmentVariable/All.phpindex b360798ff8,55e388b78a..f250a860b8--- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php+++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php@@@ -72,69 -77,18 +77,74 @@@ class All extends Componenpublic function getEnvironmentVariablesPreviewProperty(){- if ($this->is_env_sorting_enabled === false) {- return $this->resource->environment_variables_preview()->orderBy('order')->get();+ $query = $this->resource->environment_variables_preview()+ ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END");++ if ($this->is_env_sorting_enabled) {+ $query->orderBy('key');+ } else {+ $query->orderBy('order');}- return $this->resource->environment_variables_preview;+ return $query->get();}+ public function getHardcodedEnvironmentVariablesProperty()+ {+ return $this->getHardcodedVariables(false);+ }++ public function getHardcodedEnvironmentVariablesPreviewProperty()+ {+ return $this->getHardcodedVariables(true);+ }++ protected function getHardcodedVariables(bool $isPreview)+ {+ // Only for services and docker-compose applications+ if ($this->resource->type() !== 'service' &&+ ($this->resourceClass !== 'App\Models\Application' ||+ ($this->resourceClass === 'App\Models\Application' && $this->resource->build_pack !== 'dockercompose'))) {+ return collect([]);+ }++ $dockerComposeRaw = $this->resource->docker_compose_raw ?? $this->resource->docker_compose;++ if (blank($dockerComposeRaw)) {+ return collect([]);+ }++ // Extract all hard-coded variables+ $hardcodedVars = extractHardcodedEnvironmentVariables($dockerComposeRaw);++ // Filter out magic variables (SERVICE_FQDN_*, SERVICE_URL_*, SERVICE_NAME_*)+ $hardcodedVars = $hardcodedVars->filter(function ($var) {+ $key = $var['key'];++ return ! str($key)->startsWith(['SERVICE_FQDN_', 'SERVICE_URL_', 'SERVICE_NAME_']);+ });++ // Filter out variables that exist in database (user has overridden/managed them)+ // For preview, check against preview variables; for production, check against production variables+ if ($isPreview) {+ $managedKeys = $this->resource->environment_variables_preview()->pluck('key')->toArray();+ } else {+ $managedKeys = $this->resource->environment_variables()->where('is_preview', false)->pluck('key')->toArray();+ }++ $hardcodedVars = $hardcodedVars->filter(function ($var) use ($managedKeys) {+ return ! in_array($var['key'], $managedKeys);+ });++ // Apply sorting based on is_env_sorting_enabled+ if ($this->is_env_sorting_enabled) {+ $hardcodedVars = $hardcodedVars->sortBy('key')->values();+ }+ // Otherwise keep order from docker-compose file++ return $hardcodedVars;+ }+public function getDevView(){$this->variables = $this->formatEnvironmentVariables($this->environmentVariables);diff --cc bootstrap/helpers/shared.phpindex 0437aaa700,4372ff955c..a1cecc879b--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@@ -3693,54 -3447,80 +3723,132 @@@ function verifyPasswordConfirmation(mixreturn true;}+/**+ * Extract hard-coded environment variables from docker-compose YAML.+ *+ * @param string $dockerComposeRaw Raw YAML content+ * @return \Illuminate\Support\Collection Collection of arrays with: key, value, comment, service_name+ */+function extractHardcodedEnvironmentVariables(string $dockerComposeRaw): \Illuminate\Support\Collection+{+ if (blank($dockerComposeRaw)) {+ return collect([]);+ }++ try {+ $yaml = \Symfony\Component\Yaml\Yaml::parse($dockerComposeRaw);+ } catch (\Exception $e) {+ // Malformed YAML - return empty collection+ return collect([]);+ }++ $services = data_get($yaml, 'services', []);+ if (empty($services)) {+ return collect([]);+ }++ // Extract inline comments from raw YAML+ $envComments = extractYamlEnvironmentComments($dockerComposeRaw);++ $hardcodedVars = collect([]);++ foreach ($services as $serviceName => $service) {+ $environment = collect(data_get($service, 'environment', []));++ if ($environment->isEmpty()) {+ continue;+ }++ // Convert environment variables to key-value format+ $environment = convertToKeyValueCollection($environment);++ foreach ($environment as $key => $value) {+ $hardcodedVars->push([+ 'key' => $key,+ 'value' => $value,+ 'comment' => $envComments[$key] ?? null,+ 'service_name' => $serviceName,+ ]);+ }+ }++ return $hardcodedVars;+}+++ /**+ * Downsample metrics using the Largest-Triangle-Three-Buckets (LTTB) algorithm.+ * This preserves the visual shape of the data better than simple averaging.+ *+ * @param array $data Array of [timestamp, value] pairs+ * @param int $threshold Target number of points+ * @return array Downsampled data+ */+ function downsampleLTTB(array $data, int $threshold): array+ {+ $dataLength = count($data);++ // Return unchanged if threshold >= data length, or if threshold <= 2+ // (threshold <= 2 would cause division by zero in bucket calculation)+ if ($threshold >= $dataLength || $threshold <= 2) {+ return $data;+ }++ $sampled = [];+ $sampled[] = $data[0]; // Always keep first point++ $bucketSize = ($dataLength - 2) / ($threshold - 2);++ $a = 0; // Index of previous selected point++ for ($i = 0; $i < $threshold - 2; $i++) {+ // Calculate bucket range+ $bucketStart = (int) floor(($i + 1) * $bucketSize) + 1;+ $bucketEnd = (int) floor(($i + 2) * $bucketSize) + 1;+ $bucketEnd = min($bucketEnd, $dataLength - 1);++ // Calculate average point for next bucket (used as reference)+ $nextBucketStart = (int) floor(($i + 2) * $bucketSize) + 1;+ $nextBucketEnd = (int) floor(($i + 3) * $bucketSize) + 1;+ $nextBucketEnd = min($nextBucketEnd, $dataLength - 1);++ $avgX = 0;+ $avgY = 0;+ $nextBucketCount = $nextBucketEnd - $nextBucketStart + 1;++ if ($nextBucketCount > 0) {+ for ($j = $nextBucketStart; $j <= $nextBucketEnd; $j++) {+ $avgX += $data[$j][0];+ $avgY += $data[$j][1];+ }+ $avgX /= $nextBucketCount;+ $avgY /= $nextBucketCount;+ }++ // Find point in current bucket with largest triangle area+ $maxArea = -1;+ $maxAreaIndex = $bucketStart;++ $pointAX = $data[$a][0];+ $pointAY = $data[$a][1];++ for ($j = $bucketStart; $j <= $bucketEnd; $j++) {+ // Triangle area calculation+ $area = abs(+ ($pointAX - $avgX) * ($data[$j][1] - $pointAY) -+ ($pointAX - $data[$j][0]) * ($avgY - $pointAY)+ ) * 0.5;++ if ($area > $maxArea) {+ $maxArea = $area;+ $maxAreaIndex = $j;+ }+ }++ $sampled[] = $data[$maxAreaIndex];+ $a = $maxAreaIndex;+ }++ $sampled[] = $data[$dataLength - 1]; // Always keep last point++ return $sampled;+ }