Merge pull request #8883 from appwrite/feat-sites-logs-styled

Feat: Styled&timestamped logs
This commit is contained in:
Matej Bačo 2024-10-28 14:35:30 +01:00 committed by GitHub
commit 7c9f396b40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 53 additions and 29 deletions

View file

@ -4042,9 +4042,9 @@ $projectCollections = array_merge([
'size' => 1000000,
'signed' => true,
'required' => false,
'default' => '',
'array' => false,
'filters' => [],
'default' => [],
'array' => true,
'filters' => ['json'],
],
[
'$id' => ID::custom('sourceType'),

View file

@ -19,7 +19,6 @@ return [
'sveltekit' => [
'key' => 'sveltekit',
'name' => 'SvelteKit',
'logo' => 'sveltekit.png',
'defaultServeRuntime' => 'node-22',
'serveRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node'),
'defaultBuildRuntime' => 'node-22',
@ -28,7 +27,6 @@ return [
'nextjs' => [
'key' => 'nextjs',
'name' => 'Next.js',
'logo' => 'nextjs.png',
'defaultServeRuntime' => 'node-22',
'serveRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node'),
'defaultBuildRuntime' => 'node-22',
@ -37,7 +35,6 @@ return [
'static' => [
'key' => 'static',
'name' => 'Static',
'logo' => 'static.png',
'defaultServeRuntime' => 'static-1',
'serveRuntimes' => [
'static-1'

View file

@ -2,7 +2,8 @@
const TEMPLATE_FRAMEWORKS = [
'SVELTEKIT' => [
'name' => 'Svelte Kit',
'key' => 'sveltekit',
'name' => 'SvelteKit',
'installCommand' => 'npm install',
'buildCommand' => 'npm run build',
'outputDirectory' => './build',
@ -19,7 +20,7 @@ function getFramework(string $frameworkEnum, array $overrides)
return [
[
'id' => 'starter',
'key' => 'starter',
'name' => 'Personal portfolio',
'useCases' => ['starter'],
'frameworks' => [

View file

@ -797,7 +797,7 @@ $image = $this->getParam('image', '');
<<: *x-logging
restart: unless-stopped
stop_signal: SIGINT
image: openruntimes/executor:0.6.26
image: openruntimes/executor:0.7.0
networks:
- appwrite
- runtimes

View file

@ -879,7 +879,7 @@ services:
hostname: exc1
<<: *x-logging
stop_signal: SIGINT
image: openruntimes/executor:0.6.26
image: openruntimes/executor:0.7.0
restart: unless-stopped
networks:
- appwrite

View file

@ -175,7 +175,7 @@ class Builds extends Action
'runtime' => $resource->getAttribute('runtime'),
'source' => $deployment->getAttribute('path', ''),
'sourceType' => strtolower($deviceForFunctions->getType()),
'logs' => '',
'logs' => [],
'endTime' => null,
'duration' => 0,
'size' => 0
@ -610,9 +610,29 @@ class Builds extends Action
return;
}
$logs = \mb_substr($logs, 0, null, 'UTF-8'); // Get only valid UTF8 part - removes leftover half-multibytes causing SQL errors
// Get only valid UTF8 part - removes leftover half-multibytes causing SQL errors
$logs = \mb_substr($logs, 0, null, 'UTF-8');
$build = $build->setAttribute('logs', $build->getAttribute('logs', '') . $logs);
$currentChunks = $build->getAttribute('logs', []);
// Parse styled&timestamped logs
$streamChunks = [];
$streamLogs = \str_replace("\\n", "{APPWRITE_LINEBREAK_PLACEHOLDER}", $logs);
foreach (\explode("\n", $streamLogs) as $streamLog) {
if (empty($streamLog)) {
continue;
}
$streamLog = \str_replace("{APPWRITE_LINEBREAK_PLACEHOLDER}", "\n", $streamLog);
$streamParts = \explode(" ", $streamLog, 2);
$currentChunks[] = [
'timestamp' => $streamParts[0] ?? '',
'content' => $streamParts[1] ?? ''
];
}
$build = $build->setAttribute('logs', $currentChunks);
$build = $dbForProject->updateDocument('builds', $build->getId(), $build);
/**
@ -666,7 +686,7 @@ class Builds extends Action
$build->setAttribute('status', 'ready');
$build->setAttribute('path', $response['path']);
$build->setAttribute('size', $response['size']);
$build->setAttribute('logs', $response['output']);
// $build->setAttribute('logs', $response['output']); // TODO: Figure out how to write them all at the end
$build = $dbForProject->updateDocument('builds', $buildId, $build);
@ -744,7 +764,14 @@ class Builds extends Action
$build->setAttribute('endTime', $endTime);
$build->setAttribute('duration', \intval(\ceil($durationEnd - $durationStart)));
$build->setAttribute('status', 'failed');
$build->setAttribute('logs', $th->getMessage());
$datetime = new \DateTime();
$build->setAttribute('logs', [
[
'timestamp' => $datetime->format('Y-m-d\TH:i:s.vP'),
'content' => "[31m" . $th->getMessage() . "[0m"
]
]);
$build = $dbForProject->updateDocument('builds', $buildId, $build);

View file

@ -50,7 +50,6 @@ class ListFrameworks extends Base
continue;
}
$framework['$id'] = $id;
$allowed[] = $framework;
}

View file

@ -10,12 +10,6 @@ class Framework extends Model
public function __construct()
{
$this
->addRule('$id', [
'type' => self::TYPE_STRING,
'description' => 'Framework ID.',
'default' => '',
'example' => 'sveltekit',
])
->addRule('key', [
'type' => self::TYPE_STRING,
'description' => 'Parent framework key.',

View file

@ -10,12 +10,18 @@ class TemplateFramework extends Model
public function __construct()
{
$this
->addRule('name', [
'type' => self::TYPE_STRING,
'description' => 'Framework Name.',
'default' => '',
'example' => 'sveltekit',
])
->addRule('key', [
'type' => self::TYPE_STRING,
'description' => 'Parent framework key.',
'default' => '',
'example' => 'sveltekit',
])
->addRule('name', [
'type' => self::TYPE_STRING,
'description' => 'Framework Name.',
'default' => '',
'example' => 'SvelteKit'
])
->addRule('installCommand', [
'type' => self::TYPE_STRING,
'description' => 'The install command used to install the dependencies.',

View file

@ -10,7 +10,7 @@ class TemplateSite extends Model
public function __construct()
{
$this
->addRule('id', [
->addRule('key', [
'type' => self::TYPE_STRING,
'description' => 'Site Template ID.',
'default' => '',