Skip to content

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.

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

Andras Bacsaia7f491170a9f
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index a413559669..c80d31ab3e 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -2196,7 +2196,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$this->create_workdir();
$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,
'save' => 'commit_message',
]
@@ -2462,7 +2462,9 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$coolify_envs = $this->generate_coolify_env_variables(forBuildTime: true);
$coolify_envs->each(function ($value, $key) {
- $this->env_args->put($key, $value);
+ if (! is_null($value) && $value !== '') {
+ $this->env_args->put($key, $value);
+ }
});
// For build process, include only environment variables where is_buildtime = true
diff --git a/openapi.json b/openapi.json
index 69f5ef53d0..849dee3631 100644
--- a/openapi.json
+++ b/openapi.json
@@ -3339,6 +3339,15 @@
"schema": {
"type": "string"
}
+ },
+ {
+ "name": "docker_cleanup",
+ "in": "query",
+ "description": "Perform docker cleanup (prune networks, volumes, etc.).",
+ "schema": {
+ "type": "boolean",
+ "default": true
+ }
}
],
"responses": {
@@ -5864,6 +5873,15 @@
"schema": {
"type": "string"
}
+ },
+ {
+ "name": "docker_cleanup",
+ "in": "query",
+ "description": "Perform docker cleanup (prune networks, volumes, etc.).",
+ "schema": {
+ "type": "boolean",
+ "default": true
+ }
}
],
"responses": {
@@ -10561,6 +10579,15 @@
"schema": {
"type": "string"
}
+ },
+ {
+ "name": "docker_cleanup",
+ "in": "query",
+ "description": "Perform docker cleanup (prune networks, volumes, etc.).",
+ "schema": {
+ "type": "boolean",
+ "default": true
+ }
}
],
"responses": {
diff --git a/openapi.yaml b/openapi.yaml
index fab3df54e6..226295cdba 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -2111,6 +2111,13 @@ paths:
required: true
schema:
type: string
+ -
+ name: docker_cleanup
+ in: query
+ description: 'Perform docker cleanup (prune networks, volumes, etc.).'
+ schema:
+ type: boolean
+ default: true
responses:
'200':
description: 'Stop application.'
@@ -3806,6 +3813,13 @@ paths:
required: true
schema:
type: string
+ -
+ name: docker_cleanup
+ in: query
+ description: 'Perform docker cleanup (prune networks, volumes, etc.).'
+ schema:
+ type: boolean
+ default: true
responses:
'200':
description: 'Stop database.'
@@ -6645,6 +6659,13 @@ paths:
required: true
schema:
type: string
+ -
+ name: docker_cleanup
+ in: query
+ description: 'Perform docker cleanup (prune networks, volumes, etc.).'
+ schema:
+ type: boolean
+ default: true
responses:
'200':
description: 'Stop service.'
diff --git a/tests/Unit/ApplicationDeploymentNixpacksNullEnvTest.php b/tests/Unit/ApplicationDeploymentNixpacksNullEnvTest.php
index bd925444a5..c2a8d46fa9 100644
--- a/tests/Unit/ApplicationDeploymentNixpacksNullEnvTest.php
+++ b/tests/Unit/ApplicationDeploymentNixpacksNullEnvTest.php
@@ -236,6 +236,48 @@ it('handles all environment variables being null or empty', function () {
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 () {
// Mock application with nixpacks build pack
$mockApplication = Mockery::mock(Application::class);