From 353092ba0045a1e1cfd178758c7011e3ef78802f Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 26 Feb 2024 00:05:00 +0530 Subject: [PATCH] Remove create build endpoint --- app/config/collections.php | 11 --- app/controllers/api/functions.php | 91 ++++++----------------- app/controllers/api/vcs.php | 22 ++++++ docs/references/functions/create-build.md | 1 - src/Appwrite/Platform/Workers/Builds.php | 1 + 5 files changed, 45 insertions(+), 81 deletions(-) delete mode 100644 docs/references/functions/create-build.md diff --git a/app/config/collections.php b/app/config/collections.php index 2d5aa5945a..3bc58eff56 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2590,17 +2590,6 @@ $projectCollections = array_merge([ '$id' => ID::custom('builds'), 'name' => 'Builds', 'attributes' => [ - [ - '$id' => ID::custom('creationTime'), - 'type' => Database::VAR_DATETIME, - 'format' => '', - 'size' => 0, - 'signed' => false, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => ['datetime'], - ], [ '$id' => ID::custom('startTime'), 'type' => Database::VAR_DATETIME, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 5b933f6aad..ad89409968 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -116,6 +116,28 @@ $redeployVcs = function (Request $request, Document $function, Document $project 'activate' => true, ])); + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) @@ -1188,7 +1210,6 @@ App::post('/v1/functions/:functionId/deployments') $build = $dbForProject->createDocument('builds', new Document([ '$id' => $buildId, '$permissions' => [], - 'creationTime' => DateTime::now(), 'startTime' => null, 'deploymentInternalId' => $deployment->getInternalId(), 'deploymentId' => $deployment->getId(), @@ -1430,74 +1451,6 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId') $response->noContent(); }); -App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') - ->groups(['api', 'functions']) - ->desc('Create build') - ->label('scope', 'functions.write') - ->label('event', 'functions.[functionId].deployments.[deploymentId].update') - ->label('audits.event', 'deployment.update') - ->label('audits.resource', 'function/{request.functionId}') - ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) - ->label('sdk.namespace', 'functions') - ->label('sdk.method', 'createBuild') - ->label('sdk.description', '/docs/references/functions/create-build.md') - ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) - ->label('sdk.response.model', Response::MODEL_NONE) - ->param('functionId', '', new UID(), 'Function ID.') - ->param('deploymentId', '', new UID(), 'Deployment ID.') - ->param('buildId', '', new UID(), 'Build unique ID.') - ->inject('request') - ->inject('response') - ->inject('dbForProject') - ->inject('project') - ->inject('queueForEvents') - ->inject('queueForBuilds') - ->action(function (string $functionId, string $deploymentId, string $buildId, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds) { - - $function = $dbForProject->getDocument('functions', $functionId); - - if ($function->isEmpty()) { - throw new Exception(Exception::FUNCTION_NOT_FOUND); - } - - $deployment = $dbForProject->getDocument('deployments', $deploymentId); - - if ($deployment->isEmpty()) { - throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); - } - - $build = Authorization::skip(fn () => $dbForProject->getDocument('builds', $buildId)); - - if ($build->isEmpty()) { - throw new Exception(Exception::BUILD_NOT_FOUND); - } - - $deploymentId = ID::unique(); - - $deployment->removeAttribute('$internalId'); - $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ - '$id' => $deploymentId, - 'buildId' => '', - 'buildInternalId' => '', - 'entrypoint' => $function->getAttribute('entrypoint'), - 'commands' => $function->getAttribute('commands', ''), - 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), - ])); - - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($function) - ->setDeployment($deployment) - ->setProject($project) - ->trigger(); - - $queueForEvents - ->setParam('functionId', $function->getId()) - ->setParam('deploymentId', $deployment->getId()); - - $response->noContent(); - }); - App::patch('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId') ->groups(['api', 'functions']) ->desc('Update build status to cancelled') diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 1b0c993e11..58f4cec245 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -234,6 +234,28 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } + $buildId = ID::unique(); + $build = $dbForProject->createDocument('builds', new Document([ + '$id' => $buildId, + '$permissions' => [], + 'startTime' => null, + 'deploymentInternalId' => $deployment->getInternalId(), + 'deploymentId' => $deployment->getId(), + 'status' => 'waiting', + 'path' => '', + 'runtime' => $function->getAttribute('runtime'), + 'source' => $deployment->getAttribute('path', ''), + 'sourceType' => '', + 'logs' => '', + 'endTime' => null, + 'duration' => 0, + 'size' => 0 + ])); + + $deployment->setAttribute('buildId', $build->getId()); + $deployment->setAttribute('buildInternalId', $build->getInternalId()); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + $queueForBuilds ->setType(BUILD_TYPE_DEPLOYMENT) ->setResource($function) diff --git a/docs/references/functions/create-build.md b/docs/references/functions/create-build.md deleted file mode 100644 index 31a288a35a..0000000000 --- a/docs/references/functions/create-build.md +++ /dev/null @@ -1 +0,0 @@ -Create a new build for an Appwrite Function deployment. This endpoint can be used to retry a failed build. \ No newline at end of file diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index 0bc7b53ab2..866b7fcf5d 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -154,6 +154,7 @@ class Builds extends Action $build->setAttribute('status', 'processing'); $build->setAttribute('startTime', $startTime); + $build->setAttribute('sourceType', strtolower($deviceFunctions->getType())); $build = $dbForProject->updateDocument('builds', $buildId, $build); $source = $deployment->getAttribute('path', '');