From 385fe303cc1ea0a3f51206ebdc5df7bbc871b408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 27 Oct 2024 15:48:39 +0100 Subject: [PATCH 1/3] Fix leftover fields and attributes --- app/config/collections.php | 11 ----- app/config/site-templates.php | 40 ++++--------------- app/controllers/api/vcs.php | 1 - .../Modules/Sites/Http/Sites/CreateSite.php | 4 +- .../Modules/Sites/Http/Sites/UpdateSite.php | 5 +-- src/Appwrite/Utopia/Response/Model/Site.php | 6 --- .../Response/Model/TemplateFramework.php | 6 --- .../Utopia/Response/Model/TemplateSite.php | 25 ------------ 8 files changed, 10 insertions(+), 88 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 4c9b28ba01..dade8230be 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -3402,17 +3402,6 @@ $projectCollections = array_merge([ 'default' => APP_FUNCTION_SPECIFICATION_DEFAULT, 'filters' => [], ], - [ - '$id' => ID::custom('fallbackRedirect'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 2048, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('serveRuntime'), 'type' => Database::VAR_STRING, diff --git a/app/config/site-templates.php b/app/config/site-templates.php index f1454433af..36630857b2 100644 --- a/app/config/site-templates.php +++ b/app/config/site-templates.php @@ -2,60 +2,36 @@ const TEMPLATE_FRAMEWORKS = [ 'SVELTEKIT' => [ - 'name' => 'sveltekit' + 'name' => 'Svelte Kit' ], 'NEXTJS' => [ - 'name' => 'nextjs' + 'name' => 'Next.js' ], ]; -function getFramework($framework, $installCommand, $buildCommand, $outputDirectory, $fallbackRedirect, $providerRootDirectory) +function getFramework($framework, $installCommand, $buildCommand, $outputDirectory, $providerRootDirectory) { return [ 'name' => $framework['name'], 'installCommand' => $installCommand, 'buildCommand' => $buildCommand, 'outputDirectory' => $outputDirectory, - 'fallbackRedirect' => $fallbackRedirect, 'providerRootDirectory' => $providerRootDirectory ]; } return [ [ - 'icon' => 'icon-lightning-bolt', 'id' => 'starter', - 'name' => 'Starter site', - 'tagline' => - 'A simple site to get started. Edit this site to explore endless possibilities with Appwrite Sites.', + 'name' => 'Personal portfolio', 'useCases' => ['starter'], 'frameworks' => [ - ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install', 'npm run build', 'build', 'index.html', 'node/starter') + ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install --force', 'npm run build', './build', './') ], - 'instructions' => 'For documentation and instructions check out file.', 'vcsProvider' => 'github', - 'providerRepositoryId' => 'templates', - 'providerOwner' => 'appwrite', - 'providerVersion' => '0.2.*', + 'providerRepositoryId' => 'portfolio-walter-o-brien', + 'providerOwner' => 'adityaoberai', + 'providerVersion' => '0.1.*', 'variables' => [], - 'scopes' => ['users.read'] ], - [ - 'icon' => 'icon-lightning-bolt', - 'id' => 'starter1', - 'name' => 'Starter1 site', - 'tagline' => - 'A simple site to get started. Edit this site to explore endless possibilities with Appwrite Sites.', - 'useCases' => ['messaging'], - 'frameworks' => [ - ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install', 'npm run build', 'build', 'index.html', 'node/starter1') - ], - 'instructions' => 'For documentation and instructions check out file.', - 'vcsProvider' => 'github', - 'providerRepositoryId' => 'templates', - 'providerOwner' => 'appwrite', - 'providerVersion' => '0.2.*', - 'variables' => [], - 'scopes' => ['users.read'] - ] ]; diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 753fd043c8..1a3b891b4c 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -204,7 +204,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId 'installCommand' => $resource->getAttribute('installCommand', ''), 'buildCommand' => $resource->getAttribute('buildCommand', ''), 'outputDirectory' => $resource->getAttribute('outputDirectory', ''), - 'fallbackRedirect' => $resource->getAttribute('fallbackRedirect', ''), 'type' => 'vcs', 'installationId' => $installationId, 'installationInternalId' => $installationInternalId, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php index 65666dddd1..cec416dab0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/CreateSite.php @@ -62,7 +62,6 @@ class CreateSite extends Base ->param('installCommand', '', new Text(8192, 0), 'Install Command.', true) ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) - ->param('fallbackRedirect', '', new Text(8192, 0), 'Fallback Redirect URL for site in case a route is not found.', 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) @@ -90,7 +89,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 $fallbackRedirect, 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 $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) { $siteId = ($siteId == 'unique()') ? ID::unique() : $siteId; @@ -135,7 +134,6 @@ class CreateSite extends Base 'installCommand' => $installCommand, 'buildCommand' => $buildCommand, 'outputDirectory' => $outputDirectory, - 'fallbackRedirect' => $fallbackRedirect, 'search' => implode(' ', [$siteId, $name, $framework]), 'installationId' => $installation->getId(), 'installationInternalId' => $installation->getInternalId(), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php index b69eea7452..2e66782b81 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/UpdateSite.php @@ -60,7 +60,6 @@ class UpdateSite extends Base ->param('installCommand', '', new Text(8192, 0), 'Install Command.', true) ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) - ->param('fallbackRedirect', '', new Text(8192, 0), 'Fallback Redirect URL for site in case a route is not found.', true) ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) //TODO: Update description of scopes ->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) @@ -84,7 +83,7 @@ class UpdateSite extends Base ->callback([$this, 'action']); } - public function action(string $siteId, string $name, string $framework, bool $enabled, string $installCommand, string $buildCommand, string $outputDirectory, string $fallbackRedirect, array $scopes, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, 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, array $scopes, string $installationId, ?string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) { // TODO: If only branch changes, re-deploy $site = $dbForProject->getDocument('sites', $siteId); @@ -175,7 +174,6 @@ class UpdateSite extends Base $site->getAttribute('buildCommand') !== $buildCommand || $site->getAttribute('installCommand') !== $installCommand || $site->getAttribute('outputDirectory') !== $outputDirectory || - $site->getAttribute('fallbackRedirect') !== $fallbackRedirect || $site->getAttribute('providerRootDirectory') !== $providerRootDirectory || $site->getAttribute('framework') !== $framework ) { @@ -205,7 +203,6 @@ class UpdateSite extends Base 'buildCommand' => $buildCommand, 'installCommand' => $installCommand, 'outputDirectory' => $outputDirectory, - 'fallbackRedirect' => $fallbackRedirect, 'scopes' => $scopes, 'installationId' => $installation->getId(), 'installationInternalId' => $installation->getInternalId(), diff --git a/src/Appwrite/Utopia/Response/Model/Site.php b/src/Appwrite/Utopia/Response/Model/Site.php index f4c16b1219..ff275e30b8 100644 --- a/src/Appwrite/Utopia/Response/Model/Site.php +++ b/src/Appwrite/Utopia/Response/Model/Site.php @@ -83,12 +83,6 @@ class Site extends Model 'default' => '', 'example' => 'build', ]) - ->addRule('fallbackRedirect', [ - 'type' => self::TYPE_STRING, - 'description' => 'The URL to redirect to if the route is not found.', //TODO: Update the description - 'default' => '', - 'example' => 'https://appwrite.io', - ]) ->addRule('installationId', [ 'type' => self::TYPE_STRING, 'description' => 'Site VCS (Version Control System) installation id.', diff --git a/src/Appwrite/Utopia/Response/Model/TemplateFramework.php b/src/Appwrite/Utopia/Response/Model/TemplateFramework.php index 8acfcf0017..6a41233a05 100644 --- a/src/Appwrite/Utopia/Response/Model/TemplateFramework.php +++ b/src/Appwrite/Utopia/Response/Model/TemplateFramework.php @@ -34,12 +34,6 @@ class TemplateFramework extends Model 'default' => '', 'example' => 'build', ]) - ->addRule('fallbackRedirect', [ - 'type' => self::TYPE_STRING, - 'description' => 'The fallback redirect for the site when a route is not found.', - 'default' => '', - 'example' => 'index.html', - ]) ->addRule('providerRootDirectory', [ 'type' => self::TYPE_STRING, 'description' => 'Path to site in VCS (Version Control System) repository', diff --git a/src/Appwrite/Utopia/Response/Model/TemplateSite.php b/src/Appwrite/Utopia/Response/Model/TemplateSite.php index 7eeff22076..ca02fcaf64 100644 --- a/src/Appwrite/Utopia/Response/Model/TemplateSite.php +++ b/src/Appwrite/Utopia/Response/Model/TemplateSite.php @@ -10,12 +10,6 @@ class TemplateSite extends Model public function __construct() { $this - ->addRule('icon', [ - 'type' => self::TYPE_STRING, - 'description' => 'Site Template Icon.', - 'default' => '', - 'example' => 'icon-lightning-bolt', - ]) ->addRule('id', [ 'type' => self::TYPE_STRING, 'description' => 'Site Template ID.', @@ -28,12 +22,6 @@ class TemplateSite extends Model 'default' => '', 'example' => 'Starter site', ]) - ->addRule('tagline', [ - 'type' => self::TYPE_STRING, - 'description' => 'Site Template Tagline.', - 'default' => '', - 'example' => 'A simple site to get started.', - ]) ->addRule('useCases', [ 'type' => self::TYPE_STRING, 'description' => 'Site use cases.', @@ -48,12 +36,6 @@ class TemplateSite extends Model 'example' => [], 'array' => true ]) - ->addRule('instructions', [ - 'type' => self::TYPE_STRING, - 'description' => 'Site Template Instructions.', - 'default' => '', - 'example' => 'For documentation and instructions check out .', - ]) ->addRule('vcsProvider', [ 'type' => self::TYPE_STRING, 'description' => 'VCS (Version Control System) Provider.', @@ -84,13 +66,6 @@ class TemplateSite extends Model 'default' => [], 'example' => [], 'array' => true - ]) - ->addRule('scopes', [ - 'type' => self::TYPE_STRING, - 'description' => 'Site scopes.', - 'default' => [], - 'example' => 'users.read', - 'array' => true, ]); } 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 2/3] 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 - ]); + ]) + ; } /** From 2f999ba3db713a53bbcc3172a3b585e82fbe9651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 27 Oct 2024 16:34:49 +0100 Subject: [PATCH 3/3] Fix crashing containers --- app/config/frameworks.php | 47 ++------- app/config/function-templates.php | 169 ++++++++++++------------------ app/config/site-templates.php | 2 +- app/config/template-runtimes.php | 36 +++++++ app/init.php | 1 + 5 files changed, 115 insertions(+), 140 deletions(-) create mode 100644 app/config/template-runtimes.php diff --git a/app/config/frameworks.php b/app/config/frameworks.php index b4f3998851..4aeebd14e5 100644 --- a/app/config/frameworks.php +++ b/app/config/frameworks.php @@ -4,40 +4,9 @@ * List of Appwrite Sites supported frameworks */ -const TEMPLATE_RUNTIMES = [ - 'NODE' => [ - 'name' => 'node', - 'versions' => ['22', '21.0', '20.0', '19.0', '18.0', '16.0', '14.5'] - ], - 'PYTHON' => [ - 'name' => 'python', - 'versions' => ['3.12', '3.11', '3.10', '3.9', '3.8'] - ], - 'DART' => [ - 'name' => 'dart', - 'versions' => ['3.5', '3.3', '3.1', '3.0', '2.19', '2.18', '2.17', '2.16', '2.16'] - ], - 'GO' => [ - 'name' => 'go', - 'versions' => ['1.23'] - ], - 'PHP' => [ - 'name' => 'php', - 'versions' => ['8.3', '8.2', '8.1', '8.0'] - ], - 'DENO' => [ - 'name' => 'deno', - 'versions' => ['2.0', '1.46', '1.40', '1.35', '1.24', '1.21'] - ], - 'BUN' => [ - 'name' => 'bun', - 'versions' => ['1.1', '1.0'] - ], - 'RUBY' => [ - 'name' => 'ruby', - 'versions' => ['3.3', '3.2', '3.1', '3.0'] - ], -]; +use Utopia\Config\Config; + +$templateRuntimes = Config::getParam('template-runtimes'); function getVersions(array $versions, string $prefix) { @@ -52,18 +21,18 @@ return [ 'name' => 'SvelteKit', 'logo' => 'sveltekit.png', 'defaultServeRuntime' => 'node-22', - 'serveRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node'), + 'serveRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node'), 'defaultBuildRuntime' => 'node-22', - 'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node') + 'buildRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node') ], 'nextjs' => [ 'key' => 'nextjs', 'name' => 'Next.js', 'logo' => 'nextjs.png', 'defaultServeRuntime' => 'node-22', - 'serveRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node'), + 'serveRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node'), 'defaultBuildRuntime' => 'node-22', - 'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node') + 'buildRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node') ], 'static' => [ 'key' => 'static', @@ -74,6 +43,6 @@ return [ 'static-1' ], 'defaultBuildRuntime' => 'node-22', - 'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node') + 'buildRuntimes' => getVersions($templateRuntimes['NODE']['versions'], 'node') ] ]; diff --git a/app/config/function-templates.php b/app/config/function-templates.php index 762c33dd9a..4de21f20c9 100644 --- a/app/config/function-templates.php +++ b/app/config/function-templates.php @@ -1,39 +1,8 @@ [ - 'name' => 'node', - 'versions' => ['22', '21.0', '20.0', '19.0', '18.0', '16.0', '14.5'] - ], - 'PYTHON' => [ - 'name' => 'python', - 'versions' => ['3.12', '3.11', '3.10', '3.9', '3.8'] - ], - 'DART' => [ - 'name' => 'dart', - 'versions' => ['3.5', '3.3', '3.1', '3.0', '2.19', '2.18', '2.17', '2.16', '2.16'] - ], - 'GO' => [ - 'name' => 'go', - 'versions' => ['1.23'] - ], - 'PHP' => [ - 'name' => 'php', - 'versions' => ['8.3', '8.2', '8.1', '8.0'] - ], - 'DENO' => [ - 'name' => 'deno', - 'versions' => ['2.0', '1.46', '1.40', '1.35', '1.24', '1.21'] - ], - 'BUN' => [ - 'name' => 'bun', - 'versions' => ['1.1', '1.0'] - ], - 'RUBY' => [ - 'name' => 'ruby', - 'versions' => ['3.3', '3.2', '3.1', '3.0'] - ], -]; +use Utopia\Config\Config; + +$templateRuntimes = Config::getParam('template-runtimes'); function getRuntimes($runtime, $commands, $entrypoint, $providerRootDirectory, $versionsDenyList = []) { @@ -62,24 +31,24 @@ return [ 'timeout' => 15, 'useCases' => ['starter'], 'runtimes' => [ - ...getRuntimes(TEMPLATE_RUNTIMES['NODE'], 'npm install', 'src/main.js', 'node/starter'), + ...getRuntimes($templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/starter'), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/starter' ), - ...getRuntimes(TEMPLATE_RUNTIMES['DART'], 'dart pub get', 'lib/main.dart', 'dart/starter'), - ...getRuntimes(TEMPLATE_RUNTIMES['GO'], '', 'main.go', 'go/starter'), + ...getRuntimes($templateRuntimes['DART'], 'dart pub get', 'lib/main.dart', 'dart/starter'), + ...getRuntimes($templateRuntimes['GO'], '', 'main.go', 'go/starter'), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/starter' ), - ...getRuntimes(TEMPLATE_RUNTIMES['DENO'], 'deno cache src/main.ts', 'src/main.ts', 'deno/starter'), - ...getRuntimes(TEMPLATE_RUNTIMES['BUN'], 'bun install', 'src/main.ts', 'bun/starter'), - ...getRuntimes(TEMPLATE_RUNTIMES['RUBY'], 'bundle install', 'lib/main.rb', 'ruby/starter'), + ...getRuntimes($templateRuntimes['DENO'], 'deno cache src/main.ts', 'src/main.ts', 'deno/starter'), + ...getRuntimes($templateRuntimes['BUN'], 'bun install', 'src/main.ts', 'bun/starter'), + ...getRuntimes($templateRuntimes['RUBY'], 'bundle install', 'lib/main.rb', 'ruby/starter'), ], 'instructions' => 'For documentation and instructions check out file.', 'vcsProvider' => 'github', @@ -101,7 +70,7 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/query-upstash-vector' @@ -145,7 +114,7 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/query-redis-labs' @@ -188,7 +157,7 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/query-neo4j-auradb' @@ -240,7 +209,7 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/query-mongo-atlas' @@ -277,7 +246,7 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/query-neon-postgres' @@ -344,25 +313,25 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/prompt-chatgpt' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/prompt_chatgpt' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/prompt-chatgpt' ), ...getRuntimes( - TEMPLATE_RUNTIMES['DART'], + $templateRuntimes['DART'], 'dart pub get', 'lib/main.dart', 'dart/prompt_chatgpt' @@ -405,19 +374,19 @@ return [ 'useCases' => ['messaging'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/discord-command-bot' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt && python src/setup.py', 'src/main.py', 'python/discord_command_bot' ), ...getRuntimes( - TEMPLATE_RUNTIMES['GO'], + $templateRuntimes['GO'], '', 'main.go', 'go/discord-command-bot' @@ -468,7 +437,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/analyze-with-perspectiveapi' @@ -504,19 +473,19 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/censor-with-redact' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/censor_with_redact' ), ...getRuntimes( - TEMPLATE_RUNTIMES['DART'], + $templateRuntimes['DART'], 'dart pub get', 'lib/main.dart', 'dart/censor_with_redact' @@ -550,7 +519,7 @@ return [ 'timeout' => 15, 'useCases' => ['utilities'], 'runtimes' => [ - ...getRuntimes(TEMPLATE_RUNTIMES['NODE'], 'npm install', 'src/main.js', 'node/generate-pdf') + ...getRuntimes($templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/generate-pdf') ], 'instructions' => 'For documentation and instructions check out file.', 'vcsProvider' => 'github', @@ -573,7 +542,7 @@ return [ 'useCases' => ['dev-tools'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/github-issue-bot' @@ -616,7 +585,7 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/url-shortener' @@ -667,19 +636,19 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/sync-with-algolia' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/sync_with_algolia' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/sync-with-algolia' @@ -748,31 +717,31 @@ return [ 'useCases' => ['databases'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/sync-with-meilisearch' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/sync-with-meilisearch' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/sync-with-meilisearch' ), ...getRuntimes( - TEMPLATE_RUNTIMES['BUN'], + $templateRuntimes['BUN'], 'bun install', 'src/main.ts', 'bun/sync-with-meilisearch' ), ...getRuntimes( - TEMPLATE_RUNTIMES['RUBY'], + $templateRuntimes['RUBY'], 'bundle install', 'lib/main.rb', 'ruby/sync-with-meilisearch' @@ -841,37 +810,37 @@ return [ 'useCases' => ['messaging'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/whatsapp-with-vonage' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/whatsapp_with_vonage' ), ...getRuntimes( - TEMPLATE_RUNTIMES['DART'], + $templateRuntimes['DART'], 'dart pub get', 'lib/main.dart', 'dart/whatsapp-with-vonage' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/whatsapp-with-vonage' ), ...getRuntimes( - TEMPLATE_RUNTIMES['BUN'], + $templateRuntimes['BUN'], 'bun install', 'src/main.ts', 'bun/whatsapp-with-vonage' ), ...getRuntimes( - TEMPLATE_RUNTIMES['RUBY'], + $templateRuntimes['RUBY'], 'bundle install', 'lib/main.rb', 'ruby/whatsapp-with-vonage' @@ -927,7 +896,7 @@ return [ 'useCases' => ['messaging'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/push-notification-with-fcm' @@ -983,19 +952,19 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/email-contact-form' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PYTHON'], + $templateRuntimes['PYTHON'], 'pip install -r requirements.txt', 'src/main.py', 'python/email_contact_form' ), ...getRuntimes( - TEMPLATE_RUNTIMES['PHP'], + $templateRuntimes['PHP'], 'composer install', 'src/index.php', 'php/email-contact-form' @@ -1066,7 +1035,7 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/subscriptions-with-stripe' @@ -1107,7 +1076,7 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/payments-with-stripe' @@ -1164,7 +1133,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/text-generation-with-huggingface' @@ -1198,7 +1167,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/language-translation-with-huggingface' @@ -1232,7 +1201,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/image-classification-with-huggingface' @@ -1290,7 +1259,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/object-detection-with-huggingface' @@ -1348,7 +1317,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/speech-recognition-with-huggingface' @@ -1406,7 +1375,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/text-to-speech-with-huggingface' @@ -1464,7 +1433,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/generate-with-replicate' @@ -1499,7 +1468,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/generate-with-together-ai' @@ -1541,7 +1510,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/chat-with-perplexity-ai' @@ -1581,7 +1550,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/generate-with-replicate' @@ -1616,7 +1585,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/sync-with-pinecone' @@ -1679,7 +1648,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/rag-with-langchain' @@ -1742,7 +1711,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/speak-with-elevenlabs' @@ -1797,7 +1766,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/speak-with-lmnt' @@ -1838,7 +1807,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/chat-with-anyscale' @@ -1879,7 +1848,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install && npm run setup', 'src/main.js', 'node/music-generation-with-huggingface' @@ -1921,7 +1890,7 @@ return [ 'useCases' => ['ai'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/generate-with-fal-ai' @@ -1956,7 +1925,7 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/subscriptions-with-lemon-squeezy' @@ -2011,7 +1980,7 @@ return [ 'useCases' => ['utilities'], 'runtimes' => [ ...getRuntimes( - TEMPLATE_RUNTIMES['NODE'], + $templateRuntimes['NODE'], 'npm install', 'src/main.js', 'node/payments-with-lemon-squeezy' diff --git a/app/config/site-templates.php b/app/config/site-templates.php index 7be8a9cce5..1d9821bb46 100644 --- a/app/config/site-templates.php +++ b/app/config/site-templates.php @@ -23,7 +23,7 @@ return [ 'name' => 'Personal portfolio', 'useCases' => ['starter'], 'frameworks' => [ - ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], [ + ...getFramework('SVELTEKIT', [ 'serveRuntime' => 'static-1', 'installCommand' => 'npm install --force', 'providerRootDirectory' => './' diff --git a/app/config/template-runtimes.php b/app/config/template-runtimes.php new file mode 100644 index 0000000000..2ba7bd390c --- /dev/null +++ b/app/config/template-runtimes.php @@ -0,0 +1,36 @@ + [ + 'name' => 'node', + 'versions' => ['22', '21.0', '20.0', '19.0', '18.0', '16.0', '14.5'] + ], + 'PYTHON' => [ + 'name' => 'python', + 'versions' => ['3.12', '3.11', '3.10', '3.9', '3.8'] + ], + 'DART' => [ + 'name' => 'dart', + 'versions' => ['3.5', '3.3', '3.1', '3.0', '2.19', '2.18', '2.17', '2.16', '2.16'] + ], + 'GO' => [ + 'name' => 'go', + 'versions' => ['1.23'] + ], + 'PHP' => [ + 'name' => 'php', + 'versions' => ['8.3', '8.2', '8.1', '8.0'] + ], + 'DENO' => [ + 'name' => 'deno', + 'versions' => ['2.0', '1.46', '1.40', '1.35', '1.24', '1.21'] + ], + 'BUN' => [ + 'name' => 'bun', + 'versions' => ['1.1', '1.0'] + ], + 'RUBY' => [ + 'name' => 'ruby', + 'versions' => ['3.3', '3.2', '3.1', '3.0'] + ], +]; diff --git a/app/init.php b/app/init.php index ea9dc5a05e..73a84c3558 100644 --- a/app/init.php +++ b/app/init.php @@ -318,6 +318,7 @@ if (!App::isProduction()) { /* * ENV vars */ +Config::load('template-runtimes', __DIR__ . '/config/template-runtimes.php'); Config::load('events', __DIR__ . '/config/events.php'); Config::load('auth', __DIR__ . '/config/auth.php'); Config::load('apis', __DIR__ . '/config/apis.php'); // List of APIs