mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Use the Deployments service in the builds worker instead of the jobs client directly
Registers a worker-scoped deployments resource (functions-only, no request-based backend switch needed) and swaps the worker's direct JobsClient::create() + DeploymentsJobs::payload()/buildPath() calls for Deployments::createFromUrl(), matching how the HTTP endpoints dispatch builds. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
11550cf07f
commit
d53dcc519b
2 files changed
+23
-17
No files matched your search
@@ -6,7 +6,9 @@ use Appwrite\Event\Publisher\Func as FunctionPublisher;
|
||||
use Appwrite\Event\Publisher\Notification as NotificationPublisher;
|
||||
use Appwrite\Event\Realtime;
|
||||
use Appwrite\Event\Webhook;
|
||||
use Appwrite\Service\Deployments\Jobs as DeploymentsJobs;
|
||||
use Appwrite\Usage\Context;
|
||||
use OpenRuntimes\Orchestrator\Jobs;
|
||||
use Utopia\Audit\Adapter\Database as AdapterDatabase;
|
||||
use Utopia\Audit\Audit as UtopiaAudit;
|
||||
use Utopia\Cache\Cache;
|
||||
@@ -186,6 +188,14 @@ return function (Container $container): void {
|
||||
return new TelemetryDevice($telemetry, getDevice(APP_STORAGE_CACHE . '/app-' . $project->getId()));
|
||||
}, ['project', 'telemetry']);
|
||||
|
||||
// Workers only ever build functions on the jobs-service backend (sites
|
||||
// always build on the executor via the Builds worker directly), so
|
||||
// unlike the HTTP-side 'deployments' resource this doesn't need to pick
|
||||
// a backend per-request.
|
||||
$container->set('deployments', function (Jobs $jobs, Database $dbForProject, Document $project, array $platform) {
|
||||
return new DeploymentsJobs($jobs, $dbForProject, $project, $platform);
|
||||
}, ['jobs', 'dbForProject', 'project', 'platform']);
|
||||
|
||||
$container->set('logError', function (Registry $register, Document $project) {
|
||||
return function (Throwable $error, string $namespace, string $action, ?array $extras = null) use ($register, $project) {
|
||||
$logger = $register->get('logger');
|
||||
|
||||
@@ -12,7 +12,7 @@ use Appwrite\Event\Realtime;
|
||||
use Appwrite\Event\Webhook;
|
||||
use Appwrite\Extend\Exception as AppwriteException;
|
||||
use Appwrite\Filter\BranchDomain as BranchDomainFilter;
|
||||
use Appwrite\Service\Deployments\Jobs as DeploymentsJobs;
|
||||
use Appwrite\Service\Deployments;
|
||||
use Appwrite\Usage\Build as BuildUsage;
|
||||
use Appwrite\Usage\Context;
|
||||
use Appwrite\Utopia\Response\Model\Deployment;
|
||||
@@ -21,7 +21,6 @@ use Exception;
|
||||
use Executor\Exception as ExecutorException;
|
||||
use Executor\Exception\Timeout as ExecutorTimeout;
|
||||
use Executor\Executor;
|
||||
use OpenRuntimes\Orchestrator\Jobs as JobsClient;
|
||||
use Swoole\Coroutine as Co;
|
||||
use Utopia\Cache\Cache;
|
||||
use Utopia\Config\Config;
|
||||
@@ -100,7 +99,7 @@ class Builds extends Action
|
||||
->inject('deviceForFiles')
|
||||
->inject('log')
|
||||
->inject('executor')
|
||||
->inject('jobs')
|
||||
->inject('deployments')
|
||||
->inject('plan')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
@@ -127,7 +126,7 @@ class Builds extends Action
|
||||
Device $deviceForFiles,
|
||||
Log $log,
|
||||
Executor $executor,
|
||||
JobsClient $jobs,
|
||||
Deployments $deployments,
|
||||
array $plan
|
||||
): void {
|
||||
$payload = $message->getPayload();
|
||||
@@ -172,7 +171,7 @@ class Builds extends Action
|
||||
$getIsResourceBlocked,
|
||||
$log,
|
||||
$executor,
|
||||
$jobs,
|
||||
$deployments,
|
||||
$plan,
|
||||
$platform,
|
||||
(int) ($payload['timeout'] ?? System::getEnv('_APP_COMPUTE_BUILD_TIMEOUT', 900))
|
||||
@@ -209,7 +208,7 @@ class Builds extends Action
|
||||
callable $getIsResourceBlocked,
|
||||
Log $log,
|
||||
Executor $executor,
|
||||
JobsClient $jobs,
|
||||
Deployments $deployments,
|
||||
array $plan,
|
||||
array $platform,
|
||||
int $timeout
|
||||
@@ -527,20 +526,17 @@ class Builds extends Action
|
||||
// On the jobs backend the only build reaching this worker is the
|
||||
// template-into-repo push above (a git *write* the jobs-service
|
||||
// artifact system has no primitive for). With the commit pushed,
|
||||
// hand the build to the jobs-service like any other VCS commit:
|
||||
// source from the presigned tarball, output onto the mounted
|
||||
// builds volume, progress via callbacks to the jobs worker.
|
||||
// hand the build to the jobs-service like any other VCS commit,
|
||||
// via the same Deployments service the HTTP endpoints use.
|
||||
if ($resource->getCollection() === 'functions'
|
||||
&& System::getEnv('_APP_BUILDS_BACKEND', 'executor') === 'orchestrator') {
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([
|
||||
'buildPath' => DeploymentsJobs::buildPath($project->getId(), $deploymentId),
|
||||
]));
|
||||
|
||||
$ref = $deployment->getAttribute('providerCommitHash') ?: $branchName;
|
||||
$jobs->create(...DeploymentsJobs::payload($project, $resource, $deployment, $platform, [
|
||||
'url' => $github->getRepositoryPresignedUrl($cloneOwner, $cloneRepository, $ref),
|
||||
'subdir' => $resource->getAttribute('providerRootDirectory', ''),
|
||||
]));
|
||||
$deployments->createFromUrl(
|
||||
$resource,
|
||||
$deployment,
|
||||
$github->getRepositoryPresignedUrl($cloneOwner, $cloneRepository, $ref),
|
||||
$resource->getAttribute('providerRootDirectory', ''),
|
||||
);
|
||||
|
||||
Console::execute('rm -rf ' . \escapeshellarg('/tmp/builds/' . $deploymentId), '', $stdout, $stderr);
|
||||
|
||||
|
||||
Reference in new issue
Block a user