From b10c898e1652bfee313bf4194f0ba312203fb907 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 8 Jul 2026 19:53:35 +0100 Subject: [PATCH] Route VCS webhook function builds through the jobs-service createGitDeployments (the GitHub push / pull-request / external-authorize build path) now takes an optional Jobs client. For function resources, when it's passed and _APP_BUILDS_BACKEND=orchestrator, the deployment is pre-declared 'waiting' with its buildPath and submitted to the jobs-service via getRepositoryPresignedUrl(owner, repo, commitHash); sites and the executor default are unchanged. The webhook already posts the "pending" commit status + PR comments, and the jobs worker posts the terminal success/failure status, so the full commit-status cycle works for webhook-triggered function builds. Threads the Jobs client from both callers (GitHub/Events/Create push + PR handlers, and Authorize/External/Update). Not verifiable locally (no GitHub App); static-checked only. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Http/GitHub/Authorize/External/Update.php | 5 ++- .../Modules/VCS/Http/GitHub/Deployment.php | 45 ++++++++++++++----- .../Modules/VCS/Http/GitHub/Events/Create.php | 13 ++++-- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php index 993740c61a..c5bdd93b26 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Authorize/External/Update.php @@ -10,6 +10,7 @@ use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; +use OpenRuntimes\Orchestrator\Jobs; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; @@ -61,6 +62,7 @@ class Update extends Action ->inject('authorization') ->inject('getProjectDB') ->inject('publisherForBuilds') + ->inject('jobs') ->inject('platform') ->callback($this->action(...)); } @@ -76,6 +78,7 @@ class Update extends Action Authorization $authorization, callable $getProjectDB, BuildPublisher $publisherForBuilds, + Jobs $jobs, array $platform ) { $installation = $dbForPlatform->getDocument('installations', $installationId); @@ -137,7 +140,7 @@ class Update extends Action ...array_filter(array_column($prFiles, 'previous_filename')) ]; - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $providerAffectedFiles, true, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $providerAffectedFiles, true, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform, $jobs); $response->noContent(); } diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php index d312cc3a56..a16ad62593 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php @@ -2,12 +2,14 @@ namespace Appwrite\Platform\Modules\VCS\Http\GitHub; +use Appwrite\Compute\Job; use Appwrite\Event\Event; use Appwrite\Event\Message\Build as BuildMessage; use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Extend\Exception; use Appwrite\Filter\BranchDomain as BranchDomainFilter; use Appwrite\Vcs\Comment; +use OpenRuntimes\Orchestrator\Jobs; use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Database; @@ -50,6 +52,7 @@ trait Deployment BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, + ?Jobs $jobs = null, ) { $errors = []; foreach ($repositories as $repository) { @@ -360,6 +363,17 @@ trait Deployment $commands[] = $resource->getAttribute('commands', ''); } + // Build function deployments on the jobs-service when the caller + // opts in ($jobs) and _APP_BUILDS_BACKEND=orchestrator. Sites stay + // on the executor. On jobs the deployment is pre-declared 'waiting' + // with its buildPath so build.sh writes onto the mounted volume. + $useJobs = $jobs !== null + && $resourceCollection === 'functions' + && System::getEnv('_APP_BUILDS_BACKEND', 'executor') === 'orchestrator'; + $buildFields = $useJobs + ? ['status' => 'waiting', 'buildPath' => Job::buildPath($projectId, $deploymentId)] + : []; + $deployment = $authorization->skip(fn () => $dbForProject->createDocument('deployments', new Document([ '$id' => $deploymentId, '$permissions' => [ @@ -367,6 +381,7 @@ trait Deployment Permission::update(Role::any()), Permission::delete(Role::any()), ], + ...$buildFields, 'resourceId' => $resourceId, 'resourceInternalId' => $resourceInternalId, 'resourceType' => $resourceCollection, @@ -557,18 +572,26 @@ trait Deployment $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } - $queueName = $this->getBuildQueueName($project, $dbForPlatform, $authorization); + if ($useJobs) { + $source = [ + 'url' => $github->getRepositoryPresignedUrl($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash), + 'subdir' => $resource->getAttribute('providerRootDirectory', ''), + ]; + $jobs->create(...Job::build($project, $resource, $deployment, $platform, $source)); + } else { + $queueName = $this->getBuildQueueName($project, $dbForPlatform, $authorization); - $publisherForBuilds->enqueue( - new BuildMessage( - project: $project, - resource: $resource, - deployment: $deployment, - type: BUILD_TYPE_DEPLOYMENT, - platform: $platform, - ), - new \Utopia\Queue\Queue($queueName) - ); + $publisherForBuilds->enqueue( + new BuildMessage( + project: $project, + resource: $resource, + deployment: $deployment, + type: BUILD_TYPE_DEPLOYMENT, + platform: $platform, + ), + new \Utopia\Queue\Queue($queueName) + ); + } Span::add("{$logBase}.build.triggered", 'true'); //TODO: Add event? diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 53f67f34b0..11e967e058 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,6 +8,7 @@ use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; +use OpenRuntimes\Orchestrator\Jobs; use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; @@ -43,6 +44,7 @@ class Create extends Action ->inject('authorization') ->inject('getProjectDB') ->inject('publisherForBuilds') + ->inject('jobs') ->inject('platform') ->callback($this->action(...)); } @@ -55,6 +57,7 @@ class Create extends Action Authorization $authorization, callable $getProjectDB, BuildPublisher $publisherForBuilds, + Jobs $jobs, array $platform ) { $this->preprocessEvent($request); @@ -79,8 +82,8 @@ class Create extends Action match ($event) { $github::EVENT_INSTALLATION => $this->handleInstallationEvent($parsedPayload, $dbForPlatform, $authorization, $getProjectDB), - $github::EVENT_PUSH => $this->handlePushEvent($parsedPayload, $githubAppId, $privateKey, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), - $github::EVENT_PULL_REQUEST => $this->handlePullRequestEvent($parsedPayload, $privateKey, $githubAppId, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform), + $github::EVENT_PUSH => $this->handlePushEvent($parsedPayload, $githubAppId, $privateKey, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform, $jobs), + $github::EVENT_PULL_REQUEST => $this->handlePullRequestEvent($parsedPayload, $privateKey, $githubAppId, $github, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform, $jobs), default => null, }; @@ -187,6 +190,7 @@ class Create extends Action BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, + ?Jobs $jobs = null, ) { $providerBranchDeleted = $parsedPayload["branchDeleted"] ?? false; $providerBranch = $parsedPayload["branch"] ?? ''; @@ -219,7 +223,7 @@ class Create extends Action // Create new deployment only on push (not committed by us) and not when branch is deleted if ($providerCommitAuthorEmail !== APP_VCS_GITHUB_EMAIL && !$providerBranchDeleted) { $providerAffectedFiles = $parsedPayload['affectedFiles'] ?? []; - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthorName, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', $providerAffectedFiles, false, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthorName, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', $providerAffectedFiles, false, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform, $jobs); } } @@ -233,6 +237,7 @@ class Create extends Action BuildPublisher $publisherForBuilds, callable $getProjectDB, array $platform, + ?Jobs $jobs = null, ) { $action = $parsedPayload["action"] ?? ''; @@ -283,7 +288,7 @@ class Create extends Action Query::orderDesc('$createdAt') ])); - $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $providerAffectedFiles, $external, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform); + $this->createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $providerAffectedFiles, $external, $dbForPlatform, $authorization, $publisherForBuilds, $getProjectDB, $platform, $jobs); } elseif ($action == "closed") { // Allowed external contributions cleanup