mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Report sourceSize for remote-source jobs builds via a stat artifact
Templates and VCS deployments fetch their source in the sidecar (codeload / presigned tarball), so unlike the uploaded-tarball path Appwrite never sees the source and can't size it — leaving sourceSize (and totalSize) at 0, which fails the template E2E size assertions on the orchestrator backend. Add a stat artifact over the downloaded archive (remote-source builds only) and subscribe to the orchestrator.job.artifact callback; the worker records the reported size as the deployment's sourceSize. sourceSize and totalSize are both recomputed on this callback and in finalize so the two agree regardless of callback ordering. Note: reads the size flat or nested under 'stat' and keys the artifact on id 'sourceSize' — the orchestrator's stat-callback payload shape is still settling. Only closes the sourceSize gap (tests using main/commit refs); the version-range tag case (0.3.*) still needs range resolution in utopia-php/vcs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9cacea05d5
commit
545abe046b
2 files changed
+43
-1
No files matched your search
@@ -6,6 +6,7 @@ use Ahc\Jwt\JWT;
|
||||
use Appwrite\Deployment\Token;
|
||||
use OpenRuntimes\Orchestrator\Enum\CallbackEvent;
|
||||
use OpenRuntimes\Orchestrator\Model\Artifact\DownloadArtifact;
|
||||
use OpenRuntimes\Orchestrator\Model\Artifact\StatArtifact;
|
||||
use OpenRuntimes\Orchestrator\Model\Artifact\UnarchiveArtifact;
|
||||
use OpenRuntimes\Orchestrator\Model\Callback;
|
||||
use OpenRuntimes\Orchestrator\Model\Volume;
|
||||
@@ -73,6 +74,11 @@ final class Job
|
||||
$sourceArtifacts = [
|
||||
new DownloadArtifact(id: 'source', in: $source['url'], out: 'source.tar.gz'),
|
||||
new UnarchiveArtifact(id: 'extract', in: 'source.tar.gz', out: 'source', subdir: $subdir !== '' ? $subdir : null),
|
||||
// Appwrite never sees the remote source (the sidecar fetches it),
|
||||
// so unlike the uploaded-tarball path it can't size it. Stat the
|
||||
// downloaded archive so the orchestrator reports its byte size in
|
||||
// an artifact callback, which the worker records as sourceSize.
|
||||
new StatArtifact(id: 'sourceSize', in: 'source.tar.gz', depends: 'source'),
|
||||
];
|
||||
} else {
|
||||
// Presigned source-download URL (GET, no request-body cap), fetched by
|
||||
@@ -128,7 +134,11 @@ final class Job
|
||||
],
|
||||
'callback' => new Callback(
|
||||
url: "{$endpoint}/v1/jobs/event?" . \http_build_query(['project' => $projectId]),
|
||||
events: [CallbackEvent::Log, CallbackEvent::Exit],
|
||||
// Artifact callbacks only carry the source-size stat, which exists
|
||||
// only for remote-source builds (templates / VCS).
|
||||
events: $source !== null
|
||||
? [CallbackEvent::Log, CallbackEvent::Artifact, CallbackEvent::Exit]
|
||||
: [CallbackEvent::Log, CallbackEvent::Exit],
|
||||
key: System::getEnv('_APP_JOBS_SECRET', ''),
|
||||
),
|
||||
];
|
||||
|
||||
@@ -113,6 +113,7 @@ class Jobs extends Action
|
||||
|
||||
$deployment = match ($event->event) {
|
||||
'orchestrator.job.log' => $this->onLog($dbForProject, $deployment, $event->data),
|
||||
'orchestrator.job.artifact' => $this->onArtifact($dbForProject, $deployment, $event->data),
|
||||
'orchestrator.job.exit' => $this->onExit($dbForProject, $dbForPlatform, $project, $deployment, (int) ($event->data['exitCode'] ?? 0), $usage, $publisherForUsage, $deviceForBuilds, $github),
|
||||
default => $deployment,
|
||||
};
|
||||
@@ -157,6 +158,37 @@ class Jobs extends Action
|
||||
return $dbForProject->updateDocument('deployments', $deployment->getId(), new Document($update));
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a reported artifact size. Remote-source builds (templates / VCS)
|
||||
* fetch the source in the sidecar, so Appwrite can't size it the way the
|
||||
* uploaded-tarball path does — the job stats the downloaded archive and the
|
||||
* orchestrator reports its size here, which becomes the deployment's
|
||||
* sourceSize. This arrives before the exit callback, so finalize folds it
|
||||
* into totalSize.
|
||||
*/
|
||||
private function onArtifact(Database $dbForProject, Document $deployment, array $data): Document
|
||||
{
|
||||
if (($data['id'] ?? '') !== 'sourceSize') {
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
// The stat callback payload shape is still settling upstream; accept the
|
||||
// size flat or nested under 'stat'.
|
||||
$stat = \is_array($data['stat'] ?? null) ? $data['stat'] : $data;
|
||||
$size = (int) ($stat['size'] ?? $stat['bytes'] ?? 0);
|
||||
if ($size <= 0) {
|
||||
return $deployment;
|
||||
}
|
||||
|
||||
// Recompute totalSize too: this callback can land either side of exit
|
||||
// (they arrive out of order), and finalize likewise derives totalSize
|
||||
// from the current sourceSize — so whichever runs last, the two agree.
|
||||
return $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([
|
||||
'sourceSize' => $size,
|
||||
'totalSize' => $size + (int) $deployment->getAttribute('buildSize', 0),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the build-command exit into a terminal outcome. The output is
|
||||
* already on the mounted builds volume, so a zero exit enforces the size
|
||||
|
||||
Reference in new issue
Block a user