fix(deployment): filter null and empty environment variables from nixpacks plan

When application->fqdn is null, COOLIFY_FQDN and COOLIFY_URL are set to null.
These null values cause nixpacks to fail parsing the config with
"invalid type: null, expected a string".

Filter out null and empty string values when generating environment variables
for the nixpacks plan JSON. Fixes #6830.
This commit is contained in:
Andras Bacsai 2026-03-11 13:41:34 +01:00
parent eb96c9550b
commit a7f491170a
4 changed files with 94 additions and 2 deletions

View file

@ -2196,7 +2196,7 @@ private function clone_repository()
$this->create_workdir(); $this->create_workdir();
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "cd {$this->workdir} && git log -1 ".escapeshellarg($this->commit)." --pretty=%B"), executeInDocker($this->deployment_uuid, "cd {$this->workdir} && git log -1 ".escapeshellarg($this->commit).' --pretty=%B'),
'hidden' => true, 'hidden' => true,
'save' => 'commit_message', 'save' => 'commit_message',
] ]
@ -2462,7 +2462,9 @@ private function generate_env_variables()
$coolify_envs = $this->generate_coolify_env_variables(forBuildTime: true); $coolify_envs = $this->generate_coolify_env_variables(forBuildTime: true);
$coolify_envs->each(function ($value, $key) { $coolify_envs->each(function ($value, $key) {
if (! is_null($value) && $value !== '') {
$this->env_args->put($key, $value); $this->env_args->put($key, $value);
}
}); });
// For build process, include only environment variables where is_buildtime = true // For build process, include only environment variables where is_buildtime = true

View file

@ -3339,6 +3339,15 @@
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
{
"name": "docker_cleanup",
"in": "query",
"description": "Perform docker cleanup (prune networks, volumes, etc.).",
"schema": {
"type": "boolean",
"default": true
}
} }
], ],
"responses": { "responses": {
@ -5864,6 +5873,15 @@
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
{
"name": "docker_cleanup",
"in": "query",
"description": "Perform docker cleanup (prune networks, volumes, etc.).",
"schema": {
"type": "boolean",
"default": true
}
} }
], ],
"responses": { "responses": {
@ -10561,6 +10579,15 @@
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
{
"name": "docker_cleanup",
"in": "query",
"description": "Perform docker cleanup (prune networks, volumes, etc.).",
"schema": {
"type": "boolean",
"default": true
}
} }
], ],
"responses": { "responses": {

View file

@ -2111,6 +2111,13 @@ paths:
required: true required: true
schema: schema:
type: string type: string
-
name: docker_cleanup
in: query
description: 'Perform docker cleanup (prune networks, volumes, etc.).'
schema:
type: boolean
default: true
responses: responses:
'200': '200':
description: 'Stop application.' description: 'Stop application.'
@ -3806,6 +3813,13 @@ paths:
required: true required: true
schema: schema:
type: string type: string
-
name: docker_cleanup
in: query
description: 'Perform docker cleanup (prune networks, volumes, etc.).'
schema:
type: boolean
default: true
responses: responses:
'200': '200':
description: 'Stop database.' description: 'Stop database.'
@ -6645,6 +6659,13 @@ paths:
required: true required: true
schema: schema:
type: string type: string
-
name: docker_cleanup
in: query
description: 'Perform docker cleanup (prune networks, volumes, etc.).'
schema:
type: boolean
default: true
responses: responses:
'200': '200':
description: 'Stop service.' description: 'Stop service.'

View file

@ -236,6 +236,48 @@
expect($envArgs)->toBe(''); expect($envArgs)->toBe('');
}); });
it('filters out null coolify env variables from env_args used in nixpacks plan JSON', function () {
// This test verifies the fix for GitHub issue #6830:
// When application->fqdn is null, COOLIFY_FQDN/COOLIFY_URL get set to null
// in generate_coolify_env_variables(). The generate_env_variables() method
// merges these into env_args which become the nixpacks plan JSON "variables".
// Nixpacks requires all variable values to be strings, so null causes:
// "Error: Failed to parse Nixpacks config file - invalid type: null, expected a string"
// Simulate the coolify env collection with null values (as produced when fqdn is null)
$coolify_envs = collect([
'COOLIFY_URL' => null,
'COOLIFY_FQDN' => null,
'COOLIFY_BRANCH' => 'main',
'COOLIFY_RESOURCE_UUID' => 'abc123',
'COOLIFY_CONTAINER_NAME' => '',
]);
// Apply the same filtering logic used in generate_env_variables()
$env_args = collect([]);
$coolify_envs->each(function ($value, $key) use ($env_args) {
if (! is_null($value) && $value !== '') {
$env_args->put($key, $value);
}
});
// Null values must NOT be present — they cause nixpacks JSON parse errors
expect($env_args->has('COOLIFY_URL'))->toBeFalse();
expect($env_args->has('COOLIFY_FQDN'))->toBeFalse();
expect($env_args->has('COOLIFY_CONTAINER_NAME'))->toBeFalse();
// Non-null values must be preserved
expect($env_args->get('COOLIFY_BRANCH'))->toBe('main');
expect($env_args->get('COOLIFY_RESOURCE_UUID'))->toBe('abc123');
// The resulting array must be safe for json_encode into nixpacks config
$json = json_encode(['variables' => $env_args->toArray()], JSON_PRETTY_PRINT);
$parsed = json_decode($json, true);
foreach ($parsed['variables'] as $value) {
expect($value)->toBeString();
}
});
it('preserves environment variables with zero values', function () { it('preserves environment variables with zero values', function () {
// Mock application with nixpacks build pack // Mock application with nixpacks build pack
$mockApplication = Mockery::mock(Application::class); $mockApplication = Mockery::mock(Application::class);