diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index a624348c0..41de17b05 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -517,6 +517,10 @@ private function deploy_dockerimage_buildpack() $this->generate_image_names(); $this->prepare_builder_image(); $this->generate_compose_file(); + + // Save runtime environment variables (including empty .env file if no variables defined) + $this->save_runtime_environment_variables(); + $this->rolling_update(); } @@ -1222,9 +1226,9 @@ private function save_runtime_environment_variables() // Handle empty environment variables if ($environment_variables->isEmpty()) { - // For Docker Compose, we need to create an empty .env file + // For Docker Compose and Docker Image, we need to create an empty .env file // because we always reference it in the compose file - if ($this->build_pack === 'dockercompose') { + if ($this->build_pack === 'dockercompose' || $this->build_pack === 'dockerimage') { $this->application_deployment_queue->addLogEntry('Creating empty .env file (no environment variables defined).'); // Create empty .env file diff --git a/tests/Unit/ApplicationDeploymentEmptyEnvTest.php b/tests/Unit/ApplicationDeploymentEmptyEnvTest.php new file mode 100644 index 000000000..8649b8f9b --- /dev/null +++ b/tests/Unit/ApplicationDeploymentEmptyEnvTest.php @@ -0,0 +1,63 @@ +toBeTrue("Build pack '{$buildPack}' should require empty .env file"); + } + + foreach ($buildPacksNotRequiringEnvFile as $buildPack) { + // These build packs also use env_file but call save_runtime_environment_variables() + // after generate_compose_file(), so they handle empty env files themselves + $requiresEnvFile = ($buildPack === 'dockercompose' || $buildPack === 'dockerimage'); + expect($requiresEnvFile)->toBeFalse("Build pack '{$buildPack}' should not match the condition"); + } +}); + +it('verifies dockerimage build pack is included in empty env file creation logic', function () { + $buildPack = 'dockerimage'; + $shouldCreateEmptyEnvFile = ($buildPack === 'dockercompose' || $buildPack === 'dockerimage'); + + expect($shouldCreateEmptyEnvFile)->toBeTrue( + 'dockerimage build pack should create empty .env file when no environment variables are defined' + ); +}); + +it('verifies dockercompose build pack is included in empty env file creation logic', function () { + $buildPack = 'dockercompose'; + $shouldCreateEmptyEnvFile = ($buildPack === 'dockercompose' || $buildPack === 'dockerimage'); + + expect($shouldCreateEmptyEnvFile)->toBeTrue( + 'dockercompose build pack should create empty .env file when no environment variables are defined' + ); +}); + +it('verifies other build packs are not included in empty env file creation logic', function () { + $otherBuildPacks = ['dockerfile', 'nixpacks', 'static', 'buildpack']; + + foreach ($otherBuildPacks as $buildPack) { + $shouldCreateEmptyEnvFile = ($buildPack === 'dockercompose' || $buildPack === 'dockerimage'); + + expect($shouldCreateEmptyEnvFile)->toBeFalse( + "Build pack '{$buildPack}' should not create empty .env file in save_runtime_environment_variables()" + ); + } +});