mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge remote-tracking branch 'origin/1.8.x' into feat-expose-sequence
This commit is contained in:
@@ -87,6 +87,8 @@ abstract class Migration
|
||||
'1.7.0' => 'V22',
|
||||
'1.7.1' => 'V22',
|
||||
'1.7.2' => 'V22',
|
||||
'1.7.3' => 'V22',
|
||||
'1.7.4' => 'V22',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ use Utopia\Database\Exception\Conflict;
|
||||
use Utopia\Database\Exception\Structure;
|
||||
use Utopia\Database\Exception\Timeout;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\System\System;
|
||||
|
||||
class V22 extends Migration
|
||||
{
|
||||
@@ -324,7 +325,9 @@ class V22 extends Migration
|
||||
4. Fill "trigger" with "manual"
|
||||
5. Fill "deploymentResourceType". If "resourceType" is "function", set "deploymentResourceType" to "function"
|
||||
6. Fill "search" with "{$id} {domain}"
|
||||
7. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup
|
||||
7. Set "region" to project region
|
||||
8. Fill "owner" with "Appwrite" if "domain" ends with "functions" or "sites"
|
||||
9. Fill "deploymentId" and "deploymentInternalId". If "deploymentResourceType" is "function", get project DB, and find function with ID "resourceId". Then fill rule's "deploymentId" with function's "deployment", and "deploymentId" as backup
|
||||
*/
|
||||
|
||||
$deploymentResourceType = null;
|
||||
@@ -346,14 +349,29 @@ class V22 extends Migration
|
||||
->setAttribute('deploymentResourceType', $document->getAttribute('deploymentResourceType', $deploymentResourceType))
|
||||
->setAttribute('search', \implode(' ', [$document->getId(), $document->getAttribute('domain', '')]));
|
||||
|
||||
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\"");
|
||||
$document->setAttribute('region', System::getEnv('_APP_REGION', 'default'));
|
||||
break;
|
||||
}
|
||||
|
||||
$document->setAttribute('region', $project->getAttribute('region', System::getEnv('_APP_REGION', 'default')));
|
||||
|
||||
$domain = $document->getAttribute('domain', '');
|
||||
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
|
||||
$owner = $document->getAttribute('owner', '');
|
||||
if (
|
||||
empty($owner) &&
|
||||
(!empty($functionsDomain) && \str_ends_with($domain, $functionsDomain)) ||
|
||||
(!empty($sitesDomain) && \str_ends_with($domain, $sitesDomain))
|
||||
) {
|
||||
$document->setAttribute('owner', 'Appwrite');
|
||||
}
|
||||
|
||||
if ($deploymentResourceType === 'function') {
|
||||
$project = $this->dbForProject->getDocument('projects', $document->getAttribute('projectId'));
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
Console::warning("Project \"{$document->getAttribute('projectId')}\" not found for rule \"{$document->getId()}\"");
|
||||
break;
|
||||
}
|
||||
|
||||
$dbForOwnerProject = ($this->getProjectDB)($project);
|
||||
$function = $dbForOwnerProject->getDocument('functions', $resourceId);
|
||||
|
||||
|
||||
@@ -89,8 +89,6 @@ class Update extends Base
|
||||
throw new Exception(Exception::BUILD_NOT_READY);
|
||||
}
|
||||
|
||||
$oldDeploymentInternalId = $function->getAttribute('deploymentInternalId', '');
|
||||
|
||||
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
|
||||
'deploymentInternalId' => $deployment->getSequence(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
@@ -106,18 +104,13 @@ class Update extends Base
|
||||
Authorization::skip(fn () => $dbForPlatform->updateDocument('schedules', $schedule->getId(), $schedule));
|
||||
|
||||
$queries = [
|
||||
Query::equal('trigger', 'manual'),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal("type", ["deployment"]),
|
||||
Query::equal("deploymentResourceType", ["function"]),
|
||||
Query::equal("deploymentResourceInternalId", [$function->getSequence()]),
|
||||
Query::equal("deploymentVcsProviderBranch", [""]),
|
||||
];
|
||||
|
||||
if (empty($oldDeploymentInternalId)) {
|
||||
$queries[] = Query::equal("deploymentInternalId", [""]);
|
||||
} else {
|
||||
$queries[] = Query::equal("deploymentInternalId", [$oldDeploymentInternalId]);
|
||||
}
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
|
||||
@@ -57,6 +57,7 @@ class Builds extends Action
|
||||
{
|
||||
$this
|
||||
->desc('Builds worker')
|
||||
->groups(['builds'])
|
||||
->inject('message')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
@@ -1074,8 +1075,6 @@ class Builds extends Action
|
||||
$resource->setAttribute('live', true);
|
||||
switch ($resource->getCollection()) {
|
||||
case 'functions':
|
||||
$oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', '');
|
||||
|
||||
$resource->setAttribute('deploymentId', $deployment->getId());
|
||||
$resource->setAttribute('deploymentInternalId', $deployment->getSequence());
|
||||
$resource->setAttribute('deploymentCreatedAt', $deployment->getCreatedAt());
|
||||
@@ -1087,14 +1086,9 @@ class Builds extends Action
|
||||
Query::equal("deploymentResourceInternalId", [$resource->getSequence()]),
|
||||
Query::equal('deploymentResourceType', ['function']),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal('deploymentVcsProviderBranch', ['']),
|
||||
];
|
||||
|
||||
if (empty($oldDeploymentInternalId)) {
|
||||
$queries[] = Query::equal("deploymentInternalId", [""]);
|
||||
} else {
|
||||
$queries[] = Query::equal("deploymentInternalId", [$oldDeploymentInternalId]);
|
||||
}
|
||||
|
||||
$rulesUpdated = false;
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment, &$rulesUpdated) {
|
||||
$rulesUpdated = true;
|
||||
@@ -1105,8 +1099,6 @@ class Builds extends Action
|
||||
});
|
||||
break;
|
||||
case 'sites':
|
||||
$oldDeploymentInternalId = $resource->getAttribute('deploymentInternalId', '');
|
||||
|
||||
$resource->setAttribute('deploymentId', $deployment->getId());
|
||||
$resource->setAttribute('deploymentInternalId', $deployment->getSequence());
|
||||
$resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', ''));
|
||||
@@ -1119,14 +1111,9 @@ class Builds extends Action
|
||||
Query::equal("deploymentResourceInternalId", [$resource->getSequence()]),
|
||||
Query::equal('deploymentResourceType', ['site']),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal('deploymentVcsProviderBranch', ['']),
|
||||
];
|
||||
|
||||
if (empty($oldDeploymentInternalId)) {
|
||||
$queries[] = Query::equal("deploymentInternalId", [""]);
|
||||
} else {
|
||||
$queries[] = Query::equal("deploymentInternalId", [$oldDeploymentInternalId]);
|
||||
}
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
|
||||
@@ -347,10 +347,16 @@ class Create extends Action
|
||||
'domain' => $domain,
|
||||
'type' => 'deployment',
|
||||
'trigger' => 'deployment',
|
||||
'value' => $deployment->getId(),
|
||||
'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(),
|
||||
'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(),
|
||||
'deploymentResourceType' => 'site',
|
||||
'deploymentResourceId' => $site->getId(),
|
||||
'deploymentResourceInternalId' => $site->getSequence(),
|
||||
'status' => 'verified',
|
||||
'certificateId' => '',
|
||||
'search' => implode(' ', [$ruleId, $domain]),
|
||||
'owner' => 'Appwrite',
|
||||
'region' => $project->getAttribute('region')
|
||||
]))
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -86,8 +86,6 @@ class Update extends Base
|
||||
throw new Exception(Exception::BUILD_NOT_READY);
|
||||
}
|
||||
|
||||
$oldDeploymentInternalId = $site->getAttribute('deploymentInternalId', '');
|
||||
|
||||
$site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [
|
||||
'deploymentInternalId' => $deployment->getSequence(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
@@ -97,18 +95,13 @@ class Update extends Base
|
||||
])));
|
||||
|
||||
$queries = [
|
||||
Query::equal('trigger', 'manual'),
|
||||
Query::equal('trigger', ['manual']),
|
||||
Query::equal("type", ["deployment"]),
|
||||
Query::equal("deploymentResourceType", ["site"]),
|
||||
Query::equal("deploymentResourceInternalId", [$site->getSequence()]),
|
||||
Query::equal("deploymentVcsProviderBranch", [""]),
|
||||
];
|
||||
|
||||
if (empty($oldDeploymentInternalId)) {
|
||||
$queries[] = Query::equal("deploymentInternalId", [""]);
|
||||
} else {
|
||||
$queries[] = Query::equal("deploymentInternalId", [$oldDeploymentInternalId]);
|
||||
}
|
||||
|
||||
$this->listRules($project, $queries, $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
|
||||
$rule = $rule
|
||||
->setAttribute('deploymentId', $deployment->getId())
|
||||
|
||||
@@ -79,16 +79,16 @@ abstract class ScheduleBase extends Action
|
||||
|
||||
// start with "0" to load all active documents.
|
||||
$lastSyncUpdate = "0";
|
||||
$this->collectSchedules($pools, $dbForPlatform, $getProjectDB, $lastSyncUpdate);
|
||||
$this->collectSchedules($dbForPlatform, $getProjectDB, $lastSyncUpdate);
|
||||
|
||||
Console::success("Starting timers at " . DateTime::now());
|
||||
/**
|
||||
* The timer synchronize $schedules copy with database collection.
|
||||
*/
|
||||
Timer::tick(static::UPDATE_TIMER * 1000, function () use ($pools, $dbForPlatform, $getProjectDB, &$lastSyncUpdate) {
|
||||
Timer::tick(static::UPDATE_TIMER * 1000, function () use ($dbForPlatform, $getProjectDB, &$lastSyncUpdate) {
|
||||
$time = DateTime::now();
|
||||
Console::log("Sync tick: Running at $time");
|
||||
$this->collectSchedules($pools, $dbForPlatform, $getProjectDB, $lastSyncUpdate);
|
||||
$this->collectSchedules($dbForPlatform, $getProjectDB, $lastSyncUpdate);
|
||||
});
|
||||
|
||||
while (true) {
|
||||
@@ -103,7 +103,7 @@ abstract class ScheduleBase extends Action
|
||||
}
|
||||
}
|
||||
|
||||
private function collectSchedules(Group $pools, Database $dbForPlatform, callable $getProjectDB, string &$lastSyncUpdate): void
|
||||
private function collectSchedules(Database $dbForPlatform, callable $getProjectDB, string &$lastSyncUpdate): void
|
||||
{
|
||||
// If we haven't synced yet, load all active schedules
|
||||
$initialLoad = $lastSyncUpdate === "0";
|
||||
@@ -115,7 +115,7 @@ abstract class ScheduleBase extends Action
|
||||
* @throws Exception
|
||||
* @var Document $schedule
|
||||
*/
|
||||
$getSchedule = function (Document $schedule) use ($pools, $dbForPlatform, $getProjectDB): array {
|
||||
$getSchedule = function (Document $schedule) use ($dbForPlatform, $getProjectDB): array {
|
||||
$project = $dbForPlatform->getDocument('projects', $schedule->getAttribute('projectId'));
|
||||
|
||||
$resource = $getProjectDB($project)->getDocument(
|
||||
|
||||
@@ -76,7 +76,7 @@ class ScheduleFunctions extends ScheduleBase
|
||||
}
|
||||
|
||||
foreach ($delayedExecutions as $delay => $schedules) {
|
||||
\go(function () use ($delay, $schedules, $pools, $dbForPlatform) {
|
||||
\go(function () use ($delay, $schedules, $dbForPlatform) {
|
||||
\sleep($delay); // in seconds
|
||||
|
||||
foreach ($schedules as $delayConfig) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class ScheduleMessages extends ScheduleBase
|
||||
continue;
|
||||
}
|
||||
|
||||
\go(function () use ($schedule, $scheduledAt, $pools, $dbForPlatform) {
|
||||
\go(function () use ($schedule, $scheduledAt, $dbForPlatform) {
|
||||
$queueForMessaging = new Messaging($this->publisher);
|
||||
|
||||
$this->updateProjectAccess($schedule['project'], $dbForPlatform);
|
||||
|
||||
@@ -36,6 +36,7 @@ class Comment
|
||||
$this->builds[$id] = [
|
||||
'projectName' => $project->getAttribute('name'),
|
||||
'projectId' => $project->getId(),
|
||||
'region' => $project->getAttribute('region', 'default'),
|
||||
'resourceName' => $resource->getAttribute('name'),
|
||||
'resourceId' => $resource->getId(),
|
||||
'resourceType' => $resourceType,
|
||||
@@ -66,6 +67,7 @@ class Comment
|
||||
if ($build['resourceType'] === 'site') {
|
||||
$projects[$build['projectId']]['site'][$build['resourceId']] = [
|
||||
'name' => $build['resourceName'],
|
||||
'region' => $build['region'],
|
||||
'status' => $build['buildStatus'],
|
||||
'deploymentId' => $build['deploymentId'],
|
||||
'action' => $build['action'],
|
||||
@@ -74,6 +76,7 @@ class Comment
|
||||
} elseif ($build['resourceType'] === 'function') {
|
||||
$projects[$build['projectId']]['function'][$build['resourceId']] = [
|
||||
'name' => $build['resourceName'],
|
||||
'region' => $build['region'],
|
||||
'status' => $build['buildStatus'],
|
||||
'deploymentId' => $build['deploymentId'],
|
||||
'action' => $build['action'],
|
||||
@@ -114,7 +117,7 @@ class Comment
|
||||
};
|
||||
|
||||
if ($site['action']['type'] === 'logs') {
|
||||
$action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $projectId . '/sites/site-' . $siteId . '/deployments/deployment-' . $site['deploymentId'] . ')';
|
||||
$action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $site['region'] . '-' . $projectId . '/sites/site-' . $siteId . '/deployments/deployment-' . $site['deploymentId'] . ')';
|
||||
} else {
|
||||
$action = '[Authorize](' . $site['action']['url'] . ')';
|
||||
}
|
||||
@@ -146,12 +149,12 @@ class Comment
|
||||
$text .= "| :- | :- | :- | :- |\n";
|
||||
|
||||
foreach ($project['function'] as $functionId => $function) {
|
||||
$extension = $site['status'] === 'building' ? 'gif' : 'png';
|
||||
$extension = $function['status'] === 'building' ? 'gif' : 'png';
|
||||
|
||||
$pathLight = '/images/vcs/status-' . $site['status'] . '-light.' . $extension;
|
||||
$pathDark = '/images/vcs/status-' . $site['status'] . '-dark.' . $extension;
|
||||
$pathLight = '/images/vcs/status-' . $function['status'] . '-light.' . $extension;
|
||||
$pathDark = '/images/vcs/status-' . $function['status'] . '-dark.' . $extension;
|
||||
|
||||
$status = match ($site['status']) {
|
||||
$status = match ($function['status']) {
|
||||
'waiting' => $this->generatImage($pathLight, $pathDark, 'Queued', 85) . ' _Queued_',
|
||||
'processing' => $this->generatImage($pathLight, $pathDark, 'Processing', 85) . ' _Processing_',
|
||||
'building' => $this->generatImage($pathLight, $pathDark, 'Building', 85) . ' _Building_',
|
||||
@@ -160,7 +163,7 @@ class Comment
|
||||
};
|
||||
|
||||
if ($function['action']['type'] === 'logs') {
|
||||
$action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $projectId . '/functions/function-' . $functionId . '/deployment-' . $function['deploymentId'] . ')';
|
||||
$action = '[View Logs](' . $protocol . '://' . $hostname . '/console/project-' . $function['region'] . '-' . $projectId . '/functions/function-' . $functionId . '/deployment-' . $function['deploymentId'] . ')';
|
||||
} else {
|
||||
$action = '[Authorize](' . $function['action']['url'] . ')';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user