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.

✨ Populate docker_compose_domains for dockercompose apps

Tobias Thiele7f46b2ed7123
diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php
index 77f4e626f9..f72d77ae63 100644
--- a/app/Http/Controllers/Api/ApplicationsController.php
+++ b/app/Http/Controllers/Api/ApplicationsController.php
@@ -1229,7 +1229,7 @@ class ApplicationsController extends Controller
$request->offsetUnset('docker_compose_domains');
}
if ($dockerComposeDomainsJson->count() > 0) {
- $application->docker_compose_domains = $dockerComposeDomainsJson;
+ $application->docker_compose_domains = json_encode($dockerComposeDomainsJson);
}
$repository_url_parsed = Url::fromString($request->git_repository);
$git_host = $repository_url_parsed->getHost();
@@ -1461,7 +1461,7 @@ class ApplicationsController extends Controller
$request->offsetUnset('docker_compose_domains');
}
if ($dockerComposeDomainsJson->count() > 0) {
- $application->docker_compose_domains = $dockerComposeDomainsJson;
+ $application->docker_compose_domains = json_encode($dockerComposeDomainsJson);
}
$application->fqdn = $fqdn;
$application->git_repository = str($gitRepository)->trim()->toString();
@@ -1665,7 +1665,7 @@ class ApplicationsController extends Controller
$request->offsetUnset('docker_compose_domains');
}
if ($dockerComposeDomainsJson->count() > 0) {
- $application->docker_compose_domains = $dockerComposeDomainsJson;
+ $application->docker_compose_domains = json_encode($dockerComposeDomainsJson);
}
$application->fqdn = $fqdn;
$application->private_key_id = $privateKey->id;
diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php
index 7518512830..aac075746f 100644
--- a/bootstrap/helpers/parsers.php
+++ b/bootstrap/helpers/parsers.php
@@ -504,6 +504,28 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int
'is_preview' => false,
]);
}
+
+ // Also populate docker_compose_domains for dockercompose apps (mirrors Path 1 at lines 601-627)
+ if ($resource->build_pack === 'dockercompose') {
+ $normalizedFqdnFor = str($fqdnFor)->replace('-', '_')->replace('.', '_')->value();
+ $serviceExists = false;
+ foreach ($services as $serviceNameKey => $svc) {
+ if (str($serviceNameKey)->replace('-', '_')->replace('.', '_')->value() === $normalizedFqdnFor) {
+ $serviceExists = true;
+ break;
+ }
+ }
+ if ($serviceExists) {
+ $domains = collect(json_decode(data_get($resource, 'docker_compose_domains'))) ?? collect([]);
+ $domainExists = data_get($domains->get($normalizedFqdnFor), 'domain');
+ if (is_null($domainExists)) {
+ $domainValue = $fqdn;
+ $domains->put($normalizedFqdnFor, ['domain' => $domainValue]);
+ $resource->docker_compose_domains = $domains->toJson();
+ $resource->save();
+ }
+ }
+ }
}
}
diff --git a/tests/Feature/ApplicationParserDockerComposeDomainsTest.php b/tests/Feature/ApplicationParserDockerComposeDomainsTest.php
new file mode 100644
index 0000000000..3d8ab15fba
--- /dev/null
+++ b/tests/Feature/ApplicationParserDockerComposeDomainsTest.php
@@ -0,0 +1,144 @@
+<?php
+
+use App\Models\Application;
+use App\Models\Environment;
+use App\Models\PrivateKey;
+use App\Models\Project;
+use App\Models\Server;
+use App\Models\ServerSetting;
+use App\Models\StandaloneDocker;
+use App\Models\Team;
+use App\Models\User;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use phpseclib3\Crypt\EC;
+
+uses(RefreshDatabase::class);
+
+beforeEach(function () {
+ $this->user = User::factory()->create();
+ $this->team = Team::factory()->create();
+ $this->user->teams()->attach($this->team);
+
+ $this->project = Project::factory()->create(['team_id' => $this->team->id]);
+ $this->environment = Environment::factory()->create([
+ 'project_id' => $this->project->id,
+ ]);
+
+ $ecKey = EC::createKey('Ed25519');
+ $privateKeyContent = $ecKey->toString('OpenSSH');
+
+ $privateKey = PrivateKey::create([
+ 'name' => 'test-key',
+ 'private_key' => $privateKeyContent,
+ 'team_id' => $this->team->id,
+ ]);
+
+ $this->server = Server::factory()->create([
+ 'team_id' => $this->team->id,
+ 'private_key_id' => $privateKey->id,
+ ]);
+
+ ServerSetting::create([
+ 'server_id' => $this->server->id,
+ 'wildcard_domain' => 'http://127.0.0.1.sslip.io',
+ ]);
+
+ $this->destination = StandaloneDocker::factory()->create([
+ 'server_id' => $this->server->id,
+ 'network' => 'test-network-'.fake()->uuid(),
+ ]);
+});
+
+test('applicationParser populates docker_compose_domains for KEY-based SERVICE_FQDN variables', function () {
+ $dockerCompose = <<<'YAML'
+services:
+ backend:
+ image: myapp/backend:latest
+ environment:
+ - SERVICE_FQDN_BACKEND_8000=${BACKEND_URL}
+ frontend:
+ image: myapp/frontend:latest
+ environment:
+ - SERVICE_FQDN_FRONTEND=${FRONTEND_URL}
+YAML;
+
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => StandaloneDocker::class,
+ 'build_pack' => 'dockercompose',
+ 'docker_compose_raw' => $dockerCompose,
+ 'fqdn' => null,
+ 'docker_compose_domains' => null,
+ ]);
+
+ applicationParser($application);
+
+ $application->refresh();
+
+ $domains = json_decode($application->docker_compose_domains, true);
+
+ expect($domains)->not->toBeNull()
+ ->and($domains)->toBeArray()
+ ->and($domains)->toHaveKey('backend')
+ ->and($domains['backend'])->toHaveKey('domain')
+ ->and($domains['backend']['domain'])->not->toBeEmpty();
+});
+
+test('applicationParser populates docker_compose_domains for KEY-based SERVICE_FQDN without port', function () {
+ $dockerCompose = <<<'YAML'
+services:
+ frontend:
+ image: myapp/frontend:latest
+ environment:
+ - SERVICE_FQDN_FRONTEND=${FRONTEND_URL}
+YAML;
+
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => StandaloneDocker::class,
+ 'build_pack' => 'dockercompose',
+ 'docker_compose_raw' => $dockerCompose,
+ 'fqdn' => null,
+ 'docker_compose_domains' => null,
+ ]);
+
+ applicationParser($application);
+
+ $application->refresh();
+
+ $domains = json_decode($application->docker_compose_domains, true);
+
+ expect($domains)->not->toBeNull()
+ ->and($domains)->toHaveKey('frontend')
+ ->and($domains['frontend'])->toHaveKey('domain');
+});
+
+test('applicationParser does not populate docker_compose_domains for non-dockercompose build_pack', function () {
+ $dockerCompose = <<<'YAML'
+services:
+ backend:
+ image: myapp/backend:latest
+ environment:
+ - SERVICE_FQDN_BACKEND_8000=${BACKEND_URL}
+YAML;
+
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id,
+ 'destination_type' => StandaloneDocker::class,
+ 'build_pack' => 'dockerfile',
+ 'docker_compose_raw' => $dockerCompose,
+ 'fqdn' => null,
+ 'docker_compose_domains' => null,
+ ]);
+
+ applicationParser($application);
+
+ $application->refresh();
+
+ // For non-dockercompose, docker_compose_domains should remain empty
+ $domains = json_decode($application->docker_compose_domains, true);
+ expect($domains)->toBeNull();
+});