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.

Changes auto-committed by Conductor

Andras Bacsaid8c89a1abf7e
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index a624348c0f..41de17b059 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -517,6 +517,10 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$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 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
// 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 0000000000..8649b8f9bc
--- /dev/null
+++ b/tests/Unit/ApplicationDeploymentEmptyEnvTest.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Test to verify that empty .env files are created for build packs that require them.
+ *
+ * This test verifies the fix for the issue where deploying a Docker image without
+ * environment variables would fail because Docker Compose expects a .env file
+ * when env_file: ['.env'] is specified in the compose file.
+ *
+ * The fix ensures that for 'dockerimage' and 'dockercompose' build packs,
+ * an empty .env file is created even when there are no environment variables defined.
+ */
+it('determines which build packs require empty .env file creation', function () {
+ // Build packs that set env_file: ['.env'] in the generated compose file
+ // and thus require an empty .env file even when no environment variables are defined
+ $buildPacksRequiringEnvFile = ['dockerimage', 'dockercompose'];
+
+ // Build packs that don't use env_file in the compose file
+ $buildPacksNotRequiringEnvFile = ['dockerfile', 'nixpacks', 'static'];
+
+ foreach ($buildPacksRequiringEnvFile as $buildPack) {
+ // Verify the condition matches our fix
+ $requiresEnvFile = ($buildPack === 'dockercompose' || $buildPack === 'dockerimage');
+ expect($requiresEnvFile)->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()"
+ );
+ }
+});