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) <noreply@anthropic.com>
This commit is contained in:
loks0nandClaude Opus 4.8 committed 2026-07-10 16:46:56 +01:00
1 parent 6276a5f3bd
commit b10c898e16
3 files changed
+47 -16

No files matched your search

@@ -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();
}
@@ -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?
@@ -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