mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(previews): keep compose preview data out of production pending changes
Closes #12284
This commit is contained in:
@@ -2018,6 +2018,10 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
|
||||
$serviceEnvKey = str(normalizeComposeServiceName((string) $forServiceName))->upper();
|
||||
$coolifyEnvironments->put('SERVICE_URL_'.$serviceEnvKey, $coolifyUrl->__toString());
|
||||
$coolifyEnvironments->put('SERVICE_FQDN_'.$serviceEnvKey, $coolifyFqdn);
|
||||
// A preview uses its own domains; the stored variables belong to the main application.
|
||||
if ($isPullRequest) {
|
||||
continue;
|
||||
}
|
||||
$resource->environment_variables()->updateOrCreate([
|
||||
'resourceable_type' => Application::class,
|
||||
'resourceable_id' => $resource->id,
|
||||
@@ -2034,7 +2038,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
|
||||
'value' => $coolifyFqdn,
|
||||
'is_preview' => false,
|
||||
]);
|
||||
} else {
|
||||
} elseif (! $isPullRequest) {
|
||||
$resource->environment_variables()->where('resourceable_type', Application::class)
|
||||
->where('resourceable_id', $resource->id)
|
||||
->where('key', 'LIKE', "SERVICE_FQDN_{$serviceNameFormatted}%")
|
||||
@@ -2099,7 +2103,7 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
|
||||
if ($environment->count() > 0) {
|
||||
$environment = $environment->filter(function ($value, $key) {
|
||||
return ! str($key)->startsWith('SERVICE_FQDN_');
|
||||
})->map(function ($value, $key) use ($resource) {
|
||||
})->map(function ($value, $key) use ($resource, $isPullRequest) {
|
||||
// Preserve empty strings and null values with correct Docker Compose semantics:
|
||||
// - Empty string: Variable is set to "" (e.g., HTTP_PROXY="" means "no proxy")
|
||||
// - Null: Variable is unset/removed from container environment (may inherit from host)
|
||||
@@ -2107,8 +2111,9 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
|
||||
// User explicitly wants variable unset - respect that
|
||||
// NEVER override from database - null means "inherit from environment"
|
||||
// Keep as null (will be excluded from container environment)
|
||||
} elseif ($value === '') {
|
||||
// Empty string - allow database override for backward compatibility
|
||||
} elseif ($value === '' && ! ($isPullRequest && str($key)->startsWith('SERVICE_URL_'))) {
|
||||
// Empty string - allow database override for backward compatibility.
|
||||
// The stored service URLs belong to the main application, so a preview does not use them.
|
||||
$dbEnv = $resource->environment_variables()->where('key', $key)->first();
|
||||
// Only use database override if it exists AND has a non-empty value
|
||||
if ($dbEnv && str($dbEnv->value)->isNotEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user