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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: ensure .env file exists for docker compose and auto-inject in payloads
Andras Bacsai712d60c75b5d
diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.phpindex dfef6a566d..50011c74f7 100644--- a/app/Actions/Service/StartService.php+++ b/app/Actions/Service/StartService.php@@ -22,6 +22,10 @@ class StartService$service->isConfigurationChanged(save: true);$commands[] = 'cd '.$service->workdir();$commands[] = "echo 'Saved configuration files to {$service->workdir()}.'";+ // Ensure .env file exists before docker compose tries to load it+ // This is defensive programming - saveComposeConfigs() already creates it,+ // but we guarantee it here in case of any edge cases or manual deployments+ $commands[] = 'touch .env';if ($pullLatestImages) {$commands[] = "echo 'Pulling images.'";$commands[] = 'docker compose pull';diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex ea8cdff954..0fd007e9a5 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -3029,6 +3029,12 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");private function start_by_compose_file(){+ // Ensure .env file exists before docker compose tries to load it (defensive programming)+ $this->execute_remote_command(+ ["touch {$this->workdir}/.env", 'hidden' => true],+ ["touch {$this->configuration_dir}/.env", 'hidden' => true],+ );+if ($this->application->build_pack === 'dockerimage') {$this->application_deployment_queue->addLogEntry('Pulling latest images from the registry.');$this->execute_remote_command(diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.phpindex a210aa1cc2..9b17e6810f 100644--- a/bootstrap/helpers/parsers.php+++ b/bootstrap/helpers/parsers.php@@ -1300,6 +1300,9 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?intif ($depends_on->count() > 0) {$payload['depends_on'] = $depends_on;}+ // Auto-inject .env file so Coolify environment variables are available inside containers+ // This makes Applications behave consistently with manual .env file usage+ $payload['env_file'] = ['.env'];if ($isPullRequest) {$serviceName = addPreviewDeploymentSuffix($serviceName, $pullRequestId);}@@ -2279,6 +2282,9 @@ function serviceParser(Service $resource): Collectionif ($depends_on->count() > 0) {$payload['depends_on'] = $depends_on;}+ // Auto-inject .env file so Coolify environment variables are available inside containers+ // This makes Services behave consistently with Applications+ $payload['env_file'] = ['.env'];$parsedServices->put($serviceName, $payload);}