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
fix(deploy): keep build helper containers out of --add-host (#11781)
Brandon Bridgesc72808980463
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 3a24d8bd50..4c8b6ca3e9 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -307,6 +307,43 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue}}+ /**+ * Build the --add-host flags for the containers on the destination network.+ *+ * Build helper containers are named after their deployment uuid and only live for the+ * duration of that deployment. BuildKit keys every RUN layer on the --add-host set,+ * so letting one in gives the next build a different set and forces a full rebuild.+ */+ private function addHostFlags(Collection $containers): string+ {+ $containers = $containers->sort()->values();+ $buildHelperNames = ApplicationDeploymentQueue::query()+ ->whereIn('deployment_uuid', $containers->pluck('Name')->filter())+ ->pluck('deployment_uuid');++ $ips = collect([]);+ foreach ($containers as $container) {+ $containerName = data_get($container, 'Name');+ if ($containerName === 'coolify-proxy') {+ continue;+ }+ if (isGeneratedContainerName($containerName)) {+ continue;+ }+ if ($buildHelperNames->contains($containerName)) {+ continue;+ }+ $containerIp = data_get($container, 'IPv4Address');+ if ($containerName && $containerIp) {+ $ips->put($containerName, str($containerIp)->before('/')->value());+ }+ }++ return $ips->map(function ($ip, $name) {+ return "--add-host $name:$ip";+ })->implode(' ');+ }+public function handle(): void{// Check if deployment was cancelled before we even started@@ -347,28 +384,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueueif (! is_null($allContainers)) {$allContainers = format_docker_command_output_to_json($allContainers);- $ips = collect([]);- if (count($allContainers) > 0) {- $allContainers = $allContainers[0];- $allContainers = collect($allContainers)->sort()->values();- foreach ($allContainers as $container) {- $containerName = data_get($container, 'Name');- if ($containerName === 'coolify-proxy') {- continue;- }- if (isGeneratedContainerName($containerName)) {- continue;- }- $containerIp = data_get($container, 'IPv4Address');- if ($containerName && $containerIp) {- $containerIp = str($containerIp)->before('/');- $ips->put($containerName, $containerIp->value());- }- }- }- $this->addHosts = $ips->map(function ($ip, $name) {- return "--add-host $name:$ip";- })->implode(' ');+ $this->addHosts = count($allContainers) > 0 ? $this->addHostFlags(collect($allContainers[0])) : '';}if ($this->application->dockerfile_target_build) {diff --git a/tests/Feature/ApplicationDeploymentAddHostsTest.php b/tests/Feature/ApplicationDeploymentAddHostsTest.phpnew file mode 100644index 0000000000..f57ac02e35--- /dev/null+++ b/tests/Feature/ApplicationDeploymentAddHostsTest.php@@ -0,0 +1,36 @@+<?php++use App\Jobs\ApplicationDeploymentJob;+use App\Models\ApplicationDeploymentQueue;+use Illuminate\Foundation\Testing\RefreshDatabase;++uses(RefreshDatabase::class);++function addHostFlagsFor(array $containers): string+{+ $job = (new ReflectionClass(ApplicationDeploymentJob::class))->newInstanceWithoutConstructor();++ return (new ReflectionMethod(ApplicationDeploymentJob::class, 'addHostFlags'))->invoke($job, collect($containers));+}++it('keeps build helper containers of other deployments out of --add-host', function () {+ ApplicationDeploymentQueue::create(['application_id' => '1', 'deployment_uuid' => 'k0s8g4wc4c8gkkso0gk4cgww']);++ $flags = addHostFlagsFor([+ 'a' => ['Name' => 'redis-db', 'IPv4Address' => '10.0.1.5/24'],+ 'b' => ['Name' => 'k0s8g4wc4c8gkkso0gk4cgww', 'IPv4Address' => '10.0.1.9/24'],+ 'c' => ['Name' => 'coolify-proxy', 'IPv4Address' => '10.0.1.2/24'],+ 'd' => ['Name' => 'app-uuid-20260908T141530', 'IPv4Address' => '10.0.1.7/24'],+ ]);++ expect($flags)->toBe('--add-host redis-db:10.0.1.5');+});++it('keeps the --add-host set stable whether or not a build helper is running', function () {+ ApplicationDeploymentQueue::create(['application_id' => '1', 'deployment_uuid' => 'helper-deployment-uuid']);+ $database = ['Name' => 'postgres-main', 'IPv4Address' => '10.0.1.3/24'];++ expect(addHostFlagsFor([$database, ['Name' => 'helper-deployment-uuid', 'IPv4Address' => '10.0.1.4/24']]))+ ->toBe(addHostFlagsFor([$database]))+ ->toBe('--add-host postgres-main:10.0.1.3');+});