Resolve merge conflicts

This commit is contained in:
Khushboo Verma 2024-10-27 11:30:17 +01:00
commit e2e7d6578c
13 changed files with 139 additions and 63 deletions

3
.env
View file

@ -79,7 +79,8 @@ _APP_FUNCTIONS_RUNTIMES_NETWORK=runtimes
_APP_EXECUTOR_SECRET=your-secret-key
_APP_EXECUTOR_HOST=http://proxy/v1
_APP_FUNCTIONS_RUNTIMES=php-8.0,node-18.0,python-3.9,ruby-3.1
_APP_SITES_FRAMEWORKS=sveltekit,nextjs
_APP_SITES_RUNTIMES=static-1,node-22
_APP_SITES_FRAMEWORKS=sveltekit,nextjs,static
_APP_MAINTENANCE_INTERVAL=86400
_APP_MAINTENANCE_DELAY=
_APP_MAINTENANCE_RETENTION_CACHE=2592000

View file

@ -3402,17 +3402,6 @@ $projectCollections = array_merge([
'default' => APP_FUNCTION_SPECIFICATION_DEFAULT,
'filters' => [],
],
[
'$id' => ID::custom('scopes'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => [],
'array' => true,
'filters' => [],
],
[
'$id' => ID::custom('fallbackRedirect'),
'type' => Database::VAR_STRING,
@ -3423,7 +3412,29 @@ $projectCollections = array_merge([
'default' => null,
'array' => false,
'filters' => [],
]
],
[
'$id' => ID::custom('serveRuntime'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 2048,
'signed' => true,
'required' => true,
'default' => '',
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('buildRuntime'),
'type' => Database::VAR_STRING,
'format' => '',
'size' => 2048,
'signed' => true,
'required' => true,
'default' => '',
'array' => false,
'filters' => [],
],
],
'indexes' => [
[

View file

@ -4,27 +4,76 @@
* 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']
],
];
function getVersions(array $versions, string $prefix)
{
return array_map(function ($version) use ($prefix) {
return $prefix . '-' . $version;
}, $versions);
}
return [
"sveltekit" => [
'sveltekit' => [
'key' => 'sveltekit',
'name' => 'SvelteKit',
'logo' => 'sveltekit.png',
'defaultRuntime' => 'node-20.0',
'runtimes' => [
'node-16.0',
'node-18.0',
'node-20.0'
],
'defaultServeRuntime' => 'node-22',
'serveRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node'),
'defaultBuildRuntime' => 'node-22',
'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node')
],
"nextjs" => [
'nextjs' => [
'key' => 'nextjs',
'name' => 'Next.js',
'logo' => 'nextjs.png',
'defaultRuntime' => 'node-20.0',
'runtimes' => [
'node-16.0',
'node-18.0',
'node-20.0'
'defaultServeRuntime' => 'node-22',
'serveRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node'),
'defaultBuildRuntime' => 'node-22',
'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node')
],
'static' => [
'key' => 'static',
'name' => 'Static',
'logo' => 'static.png',
'defaultServeRuntime' => 'static-1',
'serveRuntimes' => [
'static-1'
],
'defaultBuildRuntime' => 'node-22',
'buildRuntimes' => getVersions(TEMPLATE_RUNTIMES['NODE']['versions'], 'node')
]
];

View file

@ -142,23 +142,17 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
throw new AppwriteException(AppwriteException::FUNCTION_NOT_FOUND);
}
$version = $resource->getAttribute('version', 'v2');
$version = match($type) {
'function' => $resource->getAttribute('version', 'v2'),
'site' => 'v4'
};
$runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
$spec = Config::getParam('runtime-specifications')[$resource->getAttribute('specification', APP_FUNCTION_SPECIFICATION_DEFAULT)];
//todo: have runtime configs for sites
$runtime = match($type) {
'function' => (isset($runtimes[$resource->getAttribute('runtime', '')])) ? $runtimes[$resource->getAttribute('runtime', '')] : null,
'site' => [
'key' => 'static-for-now',
'name' => 'Static',
'logo' => 'node.png',
'startCommand' => null,
'version' => 'v1',
'base' => 'static:1.0',
'image' => 'static:1.0',
'supports' => [System::X86, System::ARM64, System::ARMV7, System::ARMV8]
],
'function' => $runtimes[$resource->getAttribute('runtime')] ?? null,
'site' => $runtimes[$resource->getAttribute('serveRuntime')] ?? null,
default => null
};

View file

@ -795,7 +795,7 @@ $image = $this->getParam('image', '');
<<: *x-logging
restart: unless-stopped
stop_signal: SIGINT
image: openruntimes/executor:0.6.11
image: openruntimes/executor:0.6.25
networks:
- appwrite
- runtimes

2
composer.lock generated
View file

@ -7029,5 +7029,5 @@
"platform-overrides": {
"php": "8.3"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View file

@ -162,6 +162,7 @@ services:
- _APP_FUNCTIONS_CPUS
- _APP_FUNCTIONS_MEMORY
- _APP_FUNCTIONS_RUNTIMES
- _APP_SITES_RUNTIMES
- _APP_SITES_FRAMEWORKS
- _APP_SITES_CPUS
- _APP_SITES_MEMORY
@ -880,7 +881,7 @@ services:
hostname: exc1
<<: *x-logging
stop_signal: SIGINT
image: openruntimes/executor:0.6.11
image: openruntimes/executor:0.6.25
restart: unless-stopped
networks:
- appwrite
@ -899,7 +900,7 @@ services:
- OPR_EXECUTOR_DOCKER_HUB_USERNAME=$_APP_DOCKER_HUB_USERNAME
- OPR_EXECUTOR_DOCKER_HUB_PASSWORD=$_APP_DOCKER_HUB_PASSWORD
- OPR_EXECUTOR_ENV=$_APP_ENV
- OPR_EXECUTOR_RUNTIMES=$_APP_FUNCTIONS_RUNTIMES
- OPR_EXECUTOR_RUNTIMES=$_APP_FUNCTIONS_RUNTIMES,$_APP_SITES_RUNTIMES
- OPR_EXECUTOR_SECRET=$_APP_EXECUTOR_SECRET
- OPR_EXECUTOR_RUNTIME_VERSIONS=v2,v4
- OPR_EXECUTOR_LOGGING_CONFIG=$_APP_LOGGING_CONFIG

View file

@ -570,7 +570,8 @@ class Builds extends Action
entrypoint: $deployment->getAttribute('entrypoint', 'package.json'), // TODO: change this later so that sites don't need to have an entrypoint
destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}",
variables: $vars,
command: $command
command: $command,
outputDirectory: $resource->getAttribute('outputDirectory', '')
);
} catch (\Throwable $error) {
$err = $error;
@ -808,8 +809,8 @@ class Builds extends Action
$runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
$key = $resource->getAttribute('runtime');
$runtime = match ($resource->getCollection()) {
'functions' => $runtimes[$key] ?? null,
'sites' => $runtimes['node-18.0'] ?? null, //todo: fix hardcode
'functions' => $runtimes[$resource->getAttribute('runtime')] ?? null,
'sites' => $runtimes[$resource->getAttribute('buildRuntime')] ?? null,
default => null
};
if (\is_null($runtime)) {

View file

@ -24,7 +24,6 @@ use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\Swoole\Request;
use Utopia\System\System;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Boolean;
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
@ -66,7 +65,6 @@ class CreateSite extends Base
->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('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('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)
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
@ -94,7 +92,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 $subDomain, array $scopes, 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 $fallbackRedirect, 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)
{
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
$ruleId = '';
@ -159,7 +157,6 @@ class CreateSite extends Base
'buildCommand' => $buildCommand,
'outputDirectory' => $outputDirectory,
'fallbackRedirect' => $fallbackRedirect,
'scopes' => $scopes,
'search' => implode(' ', [$siteId, $name, $framework]),
'installationId' => $installation->getId(),
'installationInternalId' => $installation->getInternalId(),
@ -169,7 +166,9 @@ class CreateSite extends Base
'providerBranch' => $providerBranch,
'providerRootDirectory' => $providerRootDirectory,
'providerSilentMode' => $providerSilentMode,
'specification' => $specification
'specification' => $specification,
'buildRuntime' => Config::getParam('frameworks', [])[$framework]['defaultBuildRuntime'],
'serveRuntime' => Config::getParam('frameworks', [])[$framework]['defaultServeRuntime'],
]));
// Git connect logic

View file

@ -34,17 +34,30 @@ class Framework extends Model
'default' => '',
'example' => 'sveltekit.png',
])
->addRule('defaultRuntime', [
->addRule('defaultServeRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Default runtime version.',
'default' => '',
'example' => 'node-20.0',
'example' => 'static-1',
])
->addRule('runtimes', [
->addRule('serveRuntimes', [
'type' => self::TYPE_STRING,
'description' => 'List of supported runtime versions.',
'default' => '',
'example' => 'node-16.0',
'example' => 'static-1',
'array' => true,
])
->addRule('defaultBuildRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Default runtime version.',
'default' => '',
'example' => 'node-22',
])
->addRule('buildRuntimes', [
'type' => self::TYPE_STRING,
'description' => 'List of supported runtime versions.',
'default' => '',
'example' => 'node-21.0',
'array' => true,
])
;

View file

@ -61,7 +61,7 @@ class Func extends Model
])
->addRule('runtime', [
'type' => self::TYPE_STRING,
'description' => 'Function execution runtime.',
'description' => 'Function execution and build runtime.',
'default' => '',
'example' => 'python-3.8',
])

View file

@ -58,13 +58,6 @@ class Site extends Model
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('scopes', [
'type' => self::TYPE_STRING,
'description' => 'Allowed permission scopes.',
'default' => [],
'example' => 'users.read',
'array' => true,
])
->addRule('vars', [
'type' => Response::MODEL_VARIABLE,
'description' => 'Site variables.',
@ -132,6 +125,18 @@ class Site extends Model
'default' => APP_SITE_SPECIFICATION_DEFAULT,
'example' => APP_SITE_SPECIFICATION_DEFAULT,
])
->addRule('buildRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Site build runtime.',
'default' => '',
'example' => 'node-22',
])
->addRule('serveRuntime', [
'type' => self::TYPE_STRING,
'description' => 'Site serve runtime.',
'default' => '',
'example' => 'static-1',
])
;
}

View file

@ -67,6 +67,7 @@ class Executor
string $destination = '',
array $variables = [],
string $command = null,
string $outputDirectory = ''
) {
$runtimeId = "$projectId-$deploymentId-build";
$route = "/runtimes";
@ -90,6 +91,7 @@ class Executor
'memory' => $memory,
'version' => $version,
'timeout' => $timeout,
'outputDirectory' => $outputDirectory
];
$response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout);