mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Preserve detected worker topology in the web upgrade installer
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d2c42084ef
commit
f97f72a07e
11 files changed
+93
-19
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
$isUpgrade ??= false;
|
||||
$lockedDatabase ??= null;
|
||||
$topology ??= 'combined';
|
||||
$vars ??= [];
|
||||
$defaultHttpPort ??= '80';
|
||||
$defaultHttpsPort ??= '443';
|
||||
@@ -57,6 +58,7 @@ $installerVersion = @filemtime(__DIR__ . '/installer/js/installer.js') ?: time()
|
||||
<?php if (!empty($lockedDatabase)) { ?>
|
||||
data-locked-database="<?php echo htmlspecialchars((string) $lockedDatabase, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
<?php } ?>
|
||||
data-topology="<?php echo htmlspecialchars((string) $topology, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
data-default-http-port="<?php echo htmlspecialchars((string) $defaultHttpPort, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
data-default-https-port="<?php echo htmlspecialchars((string) $defaultHttpsPort, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
data-default-app-domain="<?php echo htmlspecialchars((string) $defaultAppDomain, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
const getBodyDataset = () => document.body?.dataset ?? {};
|
||||
const isUpgradeMode = () => getBodyDataset().upgrade === 'true';
|
||||
const getLockedDatabase = () => getBodyDataset().lockedDatabase || '';
|
||||
const getTopology = () => {
|
||||
const topology = getBodyDataset().topology || 'combined';
|
||||
return topology === 'separate' ? 'separate' : 'combined';
|
||||
};
|
||||
const getEnabledDatabases = () => {
|
||||
const raw = getBodyDataset().enabledDatabases;
|
||||
if (!raw) return ['postgresql', 'mariadb', 'mongodb'];
|
||||
@@ -108,6 +112,7 @@
|
||||
getBodyDataset,
|
||||
isUpgradeMode,
|
||||
getLockedDatabase,
|
||||
getTopology,
|
||||
getEnabledDatabases,
|
||||
STEP_IDS,
|
||||
STATUS,
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
if (data.lockedDatabase) {
|
||||
formState.database = data.lockedDatabase;
|
||||
}
|
||||
if (data.topology === 'combined' || data.topology === 'separate') {
|
||||
formState.topology = data.topology;
|
||||
}
|
||||
if (!isUpgradeMode?.()) {
|
||||
setStateIfEmpty('database', data.defaultDatabase);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
INSTALLATION_STEPS,
|
||||
clampStep,
|
||||
isUpgradeMode,
|
||||
getEnabledDatabases
|
||||
getEnabledDatabases,
|
||||
getTopology
|
||||
} = Context;
|
||||
|
||||
const {
|
||||
@@ -106,7 +107,7 @@
|
||||
const hydrateStep1State = (root) => {
|
||||
State.setStateIfEmpty?.('appDomain', root.querySelector('#hostname')?.value);
|
||||
State.setStateIfEmpty?.('database', root.querySelector('input[name="database"]:checked')?.value);
|
||||
State.setStateIfEmpty?.('topology', root.querySelector('input[name="topology"]:checked')?.value || 'combined');
|
||||
State.setStateIfEmpty?.('topology', getTopology?.() || root.querySelector('input[name="topology"]:checked')?.value || 'combined');
|
||||
State.setStateIfEmpty?.('httpPort', root.querySelector('#http-port')?.value);
|
||||
State.setStateIfEmpty?.('httpsPort', root.querySelector('#https-port')?.value);
|
||||
State.setStateIfEmpty?.('emailCertificates', root.querySelector('#ssl-email')?.value);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
$isUpgrade ??= false;
|
||||
$lockedDatabase ??= null;
|
||||
$topology ??= 'combined';
|
||||
$selectedTopology = \in_array($topology, ['combined', 'separate'], true) ? $topology : 'combined';
|
||||
$defaultAppDomain ??= 'localhost';
|
||||
$defaultHttpPort ??= '80';
|
||||
$defaultHttpsPort ??= '443';
|
||||
@@ -106,15 +108,15 @@ $assistantOpenAIKeyValue = htmlspecialchars((string) $defaultAssistantOpenAIKey,
|
||||
<div class="input-group stack-xs">
|
||||
<label class="label-text typography-text-m-500 text-neutral-secondary">Workers and schedulers</label>
|
||||
<div class="selector-group">
|
||||
<label class="selector-card selected">
|
||||
<input type="radio" name="topology" value="combined" checked class="sr-only">
|
||||
<label class="selector-card<?php echo $selectedTopology === 'combined' ? ' selected' : ''; ?>">
|
||||
<input type="radio" name="topology" value="combined"<?php echo $selectedTopology === 'combined' ? ' checked' : ''; ?> class="sr-only">
|
||||
<div class="selector-content">
|
||||
<div class="typography-text-m-500 text-neutral-primary">Combined</div>
|
||||
<div class="typography-text-xs-400 text-neutral-secondary">One worker and one scheduler (recommended)</div>
|
||||
</div>
|
||||
</label>
|
||||
<label class="selector-card">
|
||||
<input type="radio" name="topology" value="separate" class="sr-only">
|
||||
<label class="selector-card<?php echo $selectedTopology === 'separate' ? ' selected' : ''; ?>">
|
||||
<input type="radio" name="topology" value="separate"<?php echo $selectedTopology === 'separate' ? ' checked' : ''; ?> class="sr-only">
|
||||
<div class="selector-content">
|
||||
<div class="typography-text-m-500 text-neutral-primary">Separate</div>
|
||||
<div class="typography-text-xs-400 text-neutral-secondary">One container per queue for scale-out</div>
|
||||
|
||||
@@ -44,6 +44,7 @@ class View extends Action
|
||||
$defaultHttpsPort = $config->getDefaultHttpsPort();
|
||||
$isUpgrade = $config->isUpgrade();
|
||||
$lockedDatabase = $config->getLockedDatabase();
|
||||
$topology = $config->getTopology();
|
||||
$enabledDatabases = $config->getEnabledDatabases();
|
||||
$isLocalInstall = $config->isLocal();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ final class Config
|
||||
'isLocal',
|
||||
'hostPath',
|
||||
'lockedDatabase',
|
||||
'topology',
|
||||
'enabledDatabases',
|
||||
'vars',
|
||||
];
|
||||
@@ -27,6 +28,7 @@ final class Config
|
||||
private bool $isLocal = false;
|
||||
private ?string $hostPath = null;
|
||||
private ?string $lockedDatabase = null;
|
||||
private ?string $topology = null;
|
||||
private array $enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
|
||||
private array $vars = [];
|
||||
|
||||
@@ -69,6 +71,9 @@ final class Config
|
||||
if ($this->hasValidStringValue($values, 'lockedDatabase')) {
|
||||
$this->setLockedDatabase((string) $values['lockedDatabase']);
|
||||
}
|
||||
if ($this->hasValidStringValue($values, 'topology')) {
|
||||
$this->setTopology((string) $values['topology']);
|
||||
}
|
||||
if (array_key_exists('enabledDatabases', $values) && is_array($values['enabledDatabases'])) {
|
||||
$this->setEnabledDatabases($values['enabledDatabases']);
|
||||
}
|
||||
@@ -105,6 +110,7 @@ final class Config
|
||||
'isLocal' => $this->isLocal,
|
||||
'hostPath' => $this->hostPath,
|
||||
'lockedDatabase' => $this->lockedDatabase,
|
||||
'topology' => $this->getTopology(),
|
||||
'enabledDatabases' => $this->enabledDatabases,
|
||||
];
|
||||
}
|
||||
@@ -209,6 +215,23 @@ final class Config
|
||||
$this->lockedDatabase = $value;
|
||||
}
|
||||
|
||||
public function hasTopology(): bool
|
||||
{
|
||||
return $this->topology !== null;
|
||||
}
|
||||
|
||||
public function getTopology(): string
|
||||
{
|
||||
return $this->topology ?? 'combined';
|
||||
}
|
||||
|
||||
public function setTopology(string $value): void
|
||||
{
|
||||
$this->topology = \in_array($value, ['combined', 'separate'], true)
|
||||
? $value
|
||||
: 'combined';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
|
||||
@@ -201,15 +201,11 @@ class Server
|
||||
|
||||
/**
|
||||
* Auto-detect upgrade mode by checking for existing config files.
|
||||
* Sets isUpgrade and lockedDatabase on the config when an existing
|
||||
* installation is found and these values aren't already set.
|
||||
* Sets isUpgrade, lockedDatabase, and topology on the config when an
|
||||
* existing installation is found and these values aren't already set.
|
||||
*/
|
||||
private function autoDetectUpgrade(Config $config): void
|
||||
{
|
||||
if ($config->isUpgrade()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$basePath = $config->isLocal() ? '/usr/src/code' : (getcwd() ?: '.');
|
||||
if ($config->isLocal()) {
|
||||
$composePath = $basePath . '/' . self::LOCAL_COMPOSE_FILE;
|
||||
@@ -223,16 +219,41 @@ class Server
|
||||
return;
|
||||
}
|
||||
|
||||
$config->setIsUpgrade(true);
|
||||
|
||||
if ($config->getLockedDatabase() !== null) {
|
||||
return;
|
||||
if (!$config->isUpgrade()) {
|
||||
$config->setIsUpgrade(true);
|
||||
}
|
||||
|
||||
$database = $this->detectDatabaseFromFiles($composePath, $envPath);
|
||||
if ($database !== null) {
|
||||
$config->setLockedDatabase($database);
|
||||
if ($config->getLockedDatabase() === null) {
|
||||
$database = $this->detectDatabaseFromFiles($composePath, $envPath);
|
||||
if ($database !== null) {
|
||||
$config->setLockedDatabase($database);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$config->hasTopology()) {
|
||||
$topology = $this->detectTopologyFromFiles($composePath);
|
||||
if ($topology !== null) {
|
||||
$config->setTopology($topology);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function detectTopologyFromFiles(string $composePath): ?string
|
||||
{
|
||||
$composeData = @file_get_contents($composePath);
|
||||
if ($composeData === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*appwrite-worker:\s*$/m', $composeData) === 1) {
|
||||
return 'combined';
|
||||
}
|
||||
|
||||
if (preg_match('/^\s*appwrite-worker-functions:\s*$/m', $composeData) === 1) {
|
||||
return 'separate';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function detectDatabaseFromFiles(string $composePath, string $envPath): ?string
|
||||
|
||||
@@ -361,6 +361,7 @@ class Install extends Action
|
||||
'vars' => $vars,
|
||||
'isUpgrade' => $isUpgrade,
|
||||
'lockedDatabase' => $lockedDatabase,
|
||||
'topology' => $this->topology,
|
||||
'enabledDatabases' => $enabledDatabases,
|
||||
'isLocal' => $this->isLocalInstall(),
|
||||
'hostPath' => $this->hostPath ?: null,
|
||||
|
||||
@@ -49,11 +49,24 @@ final class ViewTest extends TestCase
|
||||
$this->assertMatchesRegularExpression('/name="database" value="postgresql"[^>]*disabled/', $html);
|
||||
}
|
||||
|
||||
public function testUpgradeWithDetectedSeparateTopologyPreselectsSeparate(): void
|
||||
{
|
||||
$html = $this->render([
|
||||
'isUpgrade' => true,
|
||||
'topology' => 'separate',
|
||||
]);
|
||||
|
||||
$this->assertStringContainsString('data-topology="separate"', $html);
|
||||
$this->assertMatchesRegularExpression('/name="topology" value="separate"[^>]*checked/', $html);
|
||||
$this->assertDoesNotMatchRegularExpression('/name="topology" value="combined"[^>]*checked/', $html);
|
||||
}
|
||||
|
||||
private function render(array $values = []): string
|
||||
{
|
||||
$step = 1;
|
||||
$isUpgrade = false;
|
||||
$lockedDatabase = null;
|
||||
$topology = 'combined';
|
||||
$vars = [];
|
||||
$enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
|
||||
$csrfToken = 'test-token';
|
||||
|
||||
@@ -415,6 +415,7 @@ final class ConfigTest extends TestCase
|
||||
'isLocal',
|
||||
'hostPath',
|
||||
'lockedDatabase',
|
||||
'topology',
|
||||
'enabledDatabases',
|
||||
];
|
||||
|
||||
@@ -439,6 +440,7 @@ final class ConfigTest extends TestCase
|
||||
$this->assertFalse($array['isLocal']);
|
||||
$this->assertNull($array['hostPath']);
|
||||
$this->assertNull($array['lockedDatabase']);
|
||||
$this->assertEquals('combined', $array['topology']);
|
||||
$this->assertEquals(['postgresql', 'mariadb', 'mongodb'], $array['enabledDatabases']);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user