From 75db8946a67b66e787a37e53b9ffd4d8f65e2361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 25 Jul 2024 08:36:11 +0000 Subject: [PATCH 1/2] Fix function redeployments --- app/controllers/api/functions.php | 13 ++++++++++++- src/Appwrite/Platform/Workers/Builds.php | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index bc8e91b966..ca0d58e4fd 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1459,7 +1459,8 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/build') ->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) { + ->inject('deviceForFunctions') + ->action(function (string $functionId, string $deploymentId, string $buildId, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Device $deviceForFunctions) { $function = $dbForProject->getDocument('functions', $functionId); if ($function->isEmpty()) { @@ -1471,13 +1472,23 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/build') throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } + $path = $deployment->getAttribute('path'); + if(empty($path) || !$deviceForFunctions->exists($path)) { + throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); + } + $deploymentId = ID::unique(); + $destination = $deviceForFunctions->getPath($deploymentId . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); + $deviceForFunctions->transfer($path, $destination, $deviceForFunctions); + $deployment->removeAttribute('$internalId'); $deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([ + '$internalId' => '', '$id' => $deploymentId, 'buildId' => '', 'buildInternalId' => '', + 'path' => $destination, 'entrypoint' => $function->getAttribute('entrypoint'), 'commands' => $function->getAttribute('commands', ''), 'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]), diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index b712edd402..d026a9e54b 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -333,6 +333,7 @@ class Builds extends Action $source = $path; $build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('source', $source)); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment->setAttribute('path', $source)); $this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole); } From bce06a61787f6eff7cdae427afc328bb0623b96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 3 Aug 2024 09:14:19 +0000 Subject: [PATCH 2/2] Supply autorestart to executor --- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- src/Executor/Executor.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 16aedb47fd..c266a76f53 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -787,7 +787,7 @@ $image = $this->getParam('image', ''); <<: *x-logging restart: unless-stopped stop_signal: SIGINT - image: openruntimes/executor:0.6.2 + image: openruntimes/executor:0.6.5 networks: - appwrite - runtimes diff --git a/docker-compose.yml b/docker-compose.yml index a44e7ff006..8fbad2f652 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -873,7 +873,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.6.2 + image: openruntimes/executor:0.6.5 restart: unless-stopped networks: - appwrite diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index d6459a5ba7..bc94353fee 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -194,8 +194,7 @@ class Executor } $runtimeId = "$projectId-$deploymentId"; - $route = '/runtimes/' . $runtimeId . '/execution'; - + $route = '/runtimes/' . $runtimeId . '/executions'; // Remove after migration if ($version == 'v3') { @@ -217,6 +216,7 @@ class Executor 'version' => $version, 'runtimeEntrypoint' => $runtimeEntrypoint, 'logging' => $logging, + 'restartPolicy' => 'always' // Once utopia/orchestration has it, use DockerAPI::ALWAYS (0.13+) ]; if(!empty($body)) {