From fcca1577420bb03f2efa765788fb4daef7deb2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:02:09 +0200 Subject: [PATCH 1/5] Fix detection at scale --- composer.lock | 12 ++++++------ .../Platform/Modules/Functions/Workers/Builds.php | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index f719710677..3f34311413 100644 --- a/composer.lock +++ b/composer.lock @@ -3736,16 +3736,16 @@ }, { "name": "utopia-php/detector", - "version": "0.2.4", + "version": "0.2.6", "source": { "type": "git", "url": "https://github.com/utopia-php/detector.git", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd" + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/detector/zipball/a564381108518ce6d18b6ab441f1448bd8355afd", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd", + "url": "https://api.github.com/repos/utopia-php/detector/zipball/2b2744be7ea028307dc9352eeec109cd1f9ab2d3", + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3", "shasum": "" }, "require": { @@ -3775,9 +3775,9 @@ ], "support": { "issues": "https://github.com/utopia-php/detector/issues", - "source": "https://github.com/utopia-php/detector/tree/0.2.4" + "source": "https://github.com/utopia-php/detector/tree/0.2.6" }, - "time": "2026-02-17T11:26:34+00:00" + "time": "2026-07-01T14:00:11+00:00" }, { "name": "utopia-php/di", diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index feba4797ab..210e63ff21 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -729,7 +729,7 @@ class Builds extends Action } else { $outputDirectory = $deployment->getAttribute('buildOutput') ?? $resource->getAttribute('outputDirectory'); if ($resource->getCollection() === 'sites') { - $command = $this->prepareSiteBuildCommand($command, $outputDirectory ?? ''); + $command = $this->prepareSiteBuildCommand($command, $outputDirectory ?? '', $resource->getAttribute('framework', '')); } $command = 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh ' . \trim(\escapeshellarg($command)); @@ -1379,7 +1379,7 @@ class Builds extends Action return \substr(\hash('sha256', \json_encode($hashContext, JSON_THROW_ON_ERROR)), 0, 48); } - protected function prepareSiteBuildCommand(string $command, string $outputDirectory): string + protected function prepareSiteBuildCommand(string $command, string $outputDirectory, string $framework): string { $listFilesCommand = 'echo "{APPWRITE_DETECTION_SEPARATOR_START}" && cd /usr/local/build'; @@ -1387,7 +1387,11 @@ class Builds extends Action $listFilesCommand .= ' && cd ' . \escapeshellarg($outputDirectory); } - $listFilesCommand .= ' && find . -name \'node_modules\' -prune -o -type f -print && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; + foreach (SSR::FRAMEWORK_FILES[$framework] ?? [] as $file) { + $listFilesCommand .= ' && ( [ -e ' . \escapeshellarg($file) . ' ] && echo ' . \escapeshellarg($file) . ' || true )'; + } + + $listFilesCommand .= ' && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; if (empty($command)) { return $listFilesCommand; From 32edfd521c20c86312ae95fa4b50a39a8cfc0e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:02:16 +0200 Subject: [PATCH 2/5] Fix start command starting in wrong folder --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 1a7cfa70ae..61a07a6106 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -554,7 +554,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S } if (!empty($deployment->getAttribute('startCommand', ''))) { - $startCommand = 'cd /usr/local/server/src/function/ && ' . str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); + $startCommand = \str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); } $runtimeEntrypoint = match ($version) { From 0622d7f5b7580f967651b0f02cb408d144762251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:05:11 +0200 Subject: [PATCH 3/5] Revert wrong change --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 61a07a6106..1a7cfa70ae 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -554,7 +554,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S } if (!empty($deployment->getAttribute('startCommand', ''))) { - $startCommand = \str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); + $startCommand = 'cd /usr/local/server/src/function/ && ' . str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); } $runtimeEntrypoint = match ($version) { From c4d5ce154c9b919f68f8c52e652e37e773eb640f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 7 Jul 2026 12:37:17 +0200 Subject: [PATCH 4/5] Update unit tests --- tests/unit/Functions/BuildsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index 36515d2f5b..ff64b80c15 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -45,20 +45,20 @@ final class BuildsTest extends TestCase public function testSiteBuildCommandAppendsDetectionFileListing(): void { - $command = $this->callBuilds('prepareSiteBuildCommand', 'npm run build', './dist folder'); + $command = $this->callBuilds('prepareSiteBuildCommand', 'npm run build', './dist folder', 'astro'); $this->assertStringStartsWith('npm run build && echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && cd \'./dist folder\'', (string) $command); - $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -print', (string) $command); + $this->assertStringContainsString('( [ -e \'server/entry.mjs\' ] && echo \'server/entry.mjs\' || true )', (string) $command); $this->assertStringEndsWith('echo "{APPWRITE_DETECTION_SEPARATOR_END}"', $command); } public function testSiteBuildCommandCanBeOnlyDetectionFileListing(): void { - $command = $this->callBuilds('prepareSiteBuildCommand', '', ''); + $command = $this->callBuilds('prepareSiteBuildCommand', '', '', 'sveltekit'); $this->assertStringStartsWith('echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); - $this->assertStringContainsString('cd /usr/local/build && find .', (string) $command); + $this->assertStringContainsString('cd /usr/local/build && ( [ -e \'handler.js\' ] && echo \'handler.js\' || true )', (string) $command); } public function testSplitSiteDetectionLogsRemovesDetectionBlock(): void From 93feb38b6721bf734868a06a86b91062a9c99402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 7 Jul 2026 12:50:23 +0200 Subject: [PATCH 5/5] Fix static html detection --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 3 +++ tests/unit/Functions/BuildsTest.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 210e63ff21..00357211e9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1391,6 +1391,9 @@ class Builds extends Action $listFilesCommand .= ' && ( [ -e ' . \escapeshellarg($file) . ' ] && echo ' . \escapeshellarg($file) . ' || true )'; } + // Static fallback detection only needs to distinguish 0, 1, or 2+ HTML files, so cap the output + $listFilesCommand .= ' && find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2'; + $listFilesCommand .= ' && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; if (empty($command)) { diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index ff64b80c15..00880dcc1e 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -50,6 +50,7 @@ final class BuildsTest extends TestCase $this->assertStringStartsWith('npm run build && echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && cd \'./dist folder\'', (string) $command); $this->assertStringContainsString('( [ -e \'server/entry.mjs\' ] && echo \'server/entry.mjs\' || true )', (string) $command); + $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2', (string) $command); $this->assertStringEndsWith('echo "{APPWRITE_DETECTION_SEPARATOR_END}"', $command); } @@ -59,6 +60,7 @@ final class BuildsTest extends TestCase $this->assertStringStartsWith('echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && ( [ -e \'handler.js\' ] && echo \'handler.js\' || true )', (string) $command); + $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2', (string) $command); } public function testSplitSiteDetectionLogsRemovesDetectionBlock(): void