diff --git a/app/controllers/general.php b/app/controllers/general.php index 5beac9e1e8..d30c70be42 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -511,28 +511,27 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw 'function' => $deployment->getAttribute('entrypoint', ''), 'site' => '', }; + $source = $deployment->getAttribute('buildPath', ''); + $extension = str_ends_with($source, '.tar') ? 'tar' : 'tar.gz'; - if ($type === 'function') { - $runtimeEntrypoint = match ($version) { - 'v2' => '', - default => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $runtime['startCommand'] . '"' - }; - } elseif ($type === 'site') { + $startCommand = $runtime['startCommand']; + if ($type === 'site') { $frameworks = Config::getParam('frameworks', []); $framework = $frameworks[$resource->getAttribute('framework', '')] ?? null; - $startCommand = $runtime['startCommand']; - if (!is_null($framework)) { $adapter = ($framework['adapters'] ?? [])[$deployment->getAttribute('adapter', '')] ?? null; if (!is_null($adapter) && isset($adapter['startCommand'])) { $startCommand = $adapter['startCommand']; } } - - $runtimeEntrypoint = 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $startCommand . '"'; } + $runtimeEntrypoint = match ($version) { + 'v2' => '', + default => "cp /tmp/code.$extension /mnt/code/code.$extension && nohup helpers/start.sh \"$startCommand\"", + }; + $entrypoint = match ($type) { 'function' => $deployment->getAttribute('entrypoint', ''), 'site' => '', @@ -545,7 +544,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw variables: $vars, timeout: $resource->getAttribute('timeout', 30), image: $runtime['image'], - source: $deployment->getAttribute('buildPath', ''), + source: $source, entrypoint: $entrypoint, version: $version, path: $path, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index fd1b2076a8..71ff730b98 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -386,7 +386,9 @@ class Create extends Base try { $version = $function->getAttribute('version', 'v2'); $command = $runtime['startCommand']; - $command = $version === 'v2' ? '' : 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $command . '"'; + $source = $deployment->getAttribute('buildPath', ''); + $extension = str_ends_with($source, '.tar') ? 'tar' : 'tar.gz'; + $command = $version === 'v2' ? '' : "cp /tmp/code.$extension /mnt/code/code.$extension && nohup helpers/start.sh \"$command\""; $executionResponse = $executor->createExecution( projectId: $project->getId(), deploymentId: $deployment->getId(), @@ -394,7 +396,7 @@ class Create extends Base variables: $vars, timeout: $function->getAttribute('timeout', 0), image: $runtime['image'], - source: $deployment->getAttribute('buildPath', ''), + source: $source, entrypoint: $deployment->getAttribute('entrypoint', ''), version: $version, path: $path, diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index c8c68a58ba..843cb4a5b9 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -519,7 +519,9 @@ class Functions extends Action try { $version = $function->getAttribute('version', 'v2'); $command = $runtime['startCommand']; - $command = $version === 'v2' ? '' : 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $command . '"'; + $source = $deployment->getAttribute('buildPath', ''); + $extension = str_ends_with($source, '.tar') ? 'tar' : 'tar.gz'; + $command = $version === 'v2' ? '' : "cp /tmp/code.$extension /mnt/code/code.$extension && nohup helpers/start.sh \"$command\""; $executionResponse = $executor->createExecution( projectId: $project->getId(), deploymentId: $deploymentId, @@ -527,7 +529,7 @@ class Functions extends Action variables: $vars, timeout: $function->getAttribute('timeout', 0), image: $runtime['image'], - source: $deployment->getAttribute('buildPath', ''), + source: $source, entrypoint: $deployment->getAttribute('entrypoint', ''), version: $version, path: $path,