mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Add logic to detect rendering strategy and fallback file
This commit is contained in:
parent
1394b4349c
commit
f830918c7c
3 changed files with 52 additions and 2 deletions
|
|
@ -952,7 +952,7 @@ services:
|
|||
hostname: exc1
|
||||
<<: *x-logging
|
||||
stop_signal: SIGINT
|
||||
image: openruntimes/executor:0.7.4
|
||||
image: openruntimes-executor-2
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- appwrite
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ use Utopia\Database\Exception\Structure;
|
|||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Detector\Detection\Rendering\SSG;
|
||||
use Utopia\Detector\Detection\Rendering\SSR;
|
||||
use Utopia\Detector\Detector\Rendering;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Queue\Message;
|
||||
|
|
@ -590,7 +593,7 @@ class Builds extends Action
|
|||
cpus: $cpus,
|
||||
memory: $memory,
|
||||
timeout: $timeout,
|
||||
remove: true,
|
||||
remove: false,
|
||||
entrypoint: $deployment->getAttribute('entrypoint', 'package.json'), // TODO: change this later so that sites don't need to have an entrypoint
|
||||
destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}",
|
||||
variables: $vars,
|
||||
|
|
@ -691,6 +694,28 @@ class Builds extends Action
|
|||
throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / 1048576, 2) . ' MBs.');
|
||||
}
|
||||
|
||||
$listFilesCommand = "cd /usr/local/build/" . $resource->getAttribute('outputDirectory') . " && find . -name 'node_modules' -prune -o -type f -print";
|
||||
$response = $executor->executeCommand(
|
||||
deploymentId: $deployment->getId(),
|
||||
projectId: $project->getId(),
|
||||
command: $listFilesCommand,
|
||||
timeout: 60
|
||||
);
|
||||
|
||||
$files = array_map('trim', array_filter(explode("\n", $response['output'])));
|
||||
|
||||
$detector = new Rendering($files, $resource->getAttribute('framework'));
|
||||
$detector
|
||||
->addOption(new SSR())
|
||||
->addOption(new SSG());
|
||||
$detectedRenderingStrategy = $detector->detect();
|
||||
|
||||
$renderingStrategy = $detectedRenderingStrategy->getName();
|
||||
$fallbackFile = $detectedRenderingStrategy->getFallbackFile();
|
||||
|
||||
$resource->setAttribute('adapter', $renderingStrategy);
|
||||
$resource->setAttribute('fallbackFile', $fallbackFile);
|
||||
|
||||
/** Update the build document */
|
||||
$build->setAttribute('startTime', DateTime::format((new \DateTime())->setTimestamp(floor($response['startTime']))));
|
||||
$build->setAttribute('endTime', $endTime);
|
||||
|
|
|
|||
|
|
@ -249,6 +249,31 @@ class Executor
|
|||
return $response['body'];
|
||||
}
|
||||
|
||||
public function executeCommand(
|
||||
string $deploymentId,
|
||||
string $projectId,
|
||||
string $command,
|
||||
int $timeout
|
||||
) {
|
||||
$runtimeId = "$projectId-$deploymentId-build";
|
||||
$route = "/runtimes/$runtimeId/commands";
|
||||
|
||||
$params = [
|
||||
'command' => $command,
|
||||
'timeout' => $timeout
|
||||
];
|
||||
|
||||
$response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout);
|
||||
|
||||
$status = $response['headers']['status-code'];
|
||||
if ($status >= 400) {
|
||||
$message = \is_string($response['body']) ? $response['body'] : $response['body']['message'];
|
||||
throw new \Exception($message, $status);
|
||||
}
|
||||
|
||||
return $response['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Call
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue