From 7a0e7bfb959cfbc09cdf80c65b4fef3c517fa839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 27 Oct 2024 16:15:49 +0100 Subject: [PATCH] Add runtimes to templates --- app/config/site-templates.php | 27 ++++++++++--------- .../Modules/Sites/Http/Sites/CreateSite.php | 8 +++--- .../Response/Model/TemplateFramework.php | 19 ++++++++++--- .../Utopia/Response/Model/TemplateSite.php | 3 ++- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/config/site-templates.php b/app/config/site-templates.php index 36630857b2..7be8a9cce5 100644 --- a/app/config/site-templates.php +++ b/app/config/site-templates.php @@ -2,22 +2,19 @@ const TEMPLATE_FRAMEWORKS = [ 'SVELTEKIT' => [ - 'name' => 'Svelte Kit' - ], - 'NEXTJS' => [ - 'name' => 'Next.js' + 'name' => 'Svelte Kit', + 'installCommand' => 'npm install', + 'buildCommand' => 'npm run build', + 'outputDirectory' => './build', + 'serveRuntime' => 'node-22', + 'buildRuntime' => 'node-22', ], ]; -function getFramework($framework, $installCommand, $buildCommand, $outputDirectory, $providerRootDirectory) +function getFramework(string $frameworkEnum, array $overrides) { - return [ - 'name' => $framework['name'], - 'installCommand' => $installCommand, - 'buildCommand' => $buildCommand, - 'outputDirectory' => $outputDirectory, - 'providerRootDirectory' => $providerRootDirectory - ]; + $settings = \array_merge(TEMPLATE_FRAMEWORKS[$frameworkEnum], $overrides); + return $settings; } return [ @@ -26,7 +23,11 @@ return [ 'name' => 'Personal portfolio', 'useCases' => ['starter'], 'frameworks' => [ - ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install --force', 'npm run build', './build', './') + ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], [ + 'serveRuntime' => 'static-1', + 'installCommand' => 'npm install --force', + 'providerRootDirectory' => './' + ]) ], 'vcsProvider' => 'github', 'providerRepositoryId' => 'portfolio-walter-o-brien', diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php index 9243e8574b..25593a0d0c 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php @@ -64,6 +64,8 @@ class CreateSite extends Base ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) ->param('subdomain', '', new CustomId(), 'Unique custom sub-domain. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true) + ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true) + ->param('serveRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use when serving site.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true) @@ -91,7 +93,7 @@ class CreateSite extends Base ->callback([$this, 'action']); } - public function action(string $siteId, string $name, string $framework, bool $enabled, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) + public function action(string $siteId, string $name, string $framework, bool $enabled, string $installCommand, string $buildCommand, string $outputDirectory, string $subdomain, string $buildRuntime, string $serveRuntime, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) { $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $ruleId = ''; @@ -165,8 +167,8 @@ class CreateSite extends Base 'providerRootDirectory' => $providerRootDirectory, 'providerSilentMode' => $providerSilentMode, 'specification' => $specification, - 'buildRuntime' => Config::getParam('frameworks', [])[$framework]['defaultBuildRuntime'], - 'serveRuntime' => Config::getParam('frameworks', [])[$framework]['defaultServeRuntime'], + 'buildRuntime' => $buildRuntime, + 'serveRuntime' => $serveRuntime, ])); // Git connect logic diff --git a/src/Appwrite/Utopia/Response/Model/TemplateFramework.php b/src/Appwrite/Utopia/Response/Model/TemplateFramework.php index 6a41233a05..0b9e81df35 100644 --- a/src/Appwrite/Utopia/Response/Model/TemplateFramework.php +++ b/src/Appwrite/Utopia/Response/Model/TemplateFramework.php @@ -32,14 +32,27 @@ class TemplateFramework extends Model 'type' => self::TYPE_STRING, 'description' => 'The output directory to store the build output.', 'default' => '', - 'example' => 'build', + 'example' => './build', ]) ->addRule('providerRootDirectory', [ 'type' => self::TYPE_STRING, 'description' => 'Path to site in VCS (Version Control System) repository', 'default' => '', - 'example' => 'node/starter', - ]); + 'example' => './svelte-kit/starter', + ]) + ->addRule('serveRuntime', [ + 'type' => self::TYPE_STRING, + 'description' => 'Runtime used during serve of template deployment.', + 'default' => '', + 'example' => 'static-1', + ]) + ->addRule('buildRuntime', [ + 'type' => self::TYPE_STRING, + 'description' => 'Runtime used during build step of template.', + 'default' => '', + 'example' => 'node-22', + ]) + ; } /** diff --git a/src/Appwrite/Utopia/Response/Model/TemplateSite.php b/src/Appwrite/Utopia/Response/Model/TemplateSite.php index ca02fcaf64..8129e2ca67 100644 --- a/src/Appwrite/Utopia/Response/Model/TemplateSite.php +++ b/src/Appwrite/Utopia/Response/Model/TemplateSite.php @@ -66,7 +66,8 @@ class TemplateSite extends Model 'default' => [], 'example' => [], 'array' => true - ]); + ]) + ; } /**