diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 38439d5126..9547cfda00 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -11,9 +11,7 @@ $httpsPort = $this->getParam('httpsPort', ''); $version = $this->getParam('version', ''); $organization = $this->getParam('organization', ''); $image = $this->getParam('image', ''); -?>version: '3' - -services: +?>services: traefik: image: traefik:2.11 container_name: appwrite-traefik @@ -523,6 +521,8 @@ services: restart: unless-stopped networks: - appwrite + volumes: + - appwrite-uploads:/storage/uploads:rw depends_on: - redis environment: @@ -542,6 +542,27 @@ services: - _APP_LOGGING_CONFIG - _APP_SMS_FROM - _APP_SMS_PROVIDER + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-migrations: image: /: diff --git a/app/worker.php b/app/worker.php index 763ab1d914..60358ad6b2 100644 --- a/app/worker.php +++ b/app/worker.php @@ -34,7 +34,6 @@ use Utopia\Queue\Connection; use Utopia\Queue\Message; use Utopia\Queue\Server; use Utopia\Registry\Registry; -use Utopia\Storage\Device\Local; use Utopia\System\System; Authorization::disable(); @@ -273,9 +272,6 @@ Server::setResource('deviceForCache', function (Document $project) { return getDevice(APP_STORAGE_CACHE . '/app-' . $project->getId()); }, ['project']); -Server::setResource('deviceForLocalFiles', function (Document $project) { - return new Local(APP_STORAGE_UPLOADS . '/app-' . $project->getId()); -}, ['project']); $pools = $register->get('pools'); $platform = new Appwrite(); diff --git a/composer.lock b/composer.lock index bfe8fc0730..8acbbed541 100644 --- a/composer.lock +++ b/composer.lock @@ -5613,5 +5613,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.2.0" } diff --git a/docker-compose.yml b/docker-compose.yml index c104102a76..b1e30a1e07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -570,6 +570,7 @@ services: networks: - appwrite volumes: + - appwrite-uploads:/storage/uploads:rw - ./app:/usr/src/code/app - ./src:/usr/src/code/src depends_on: @@ -592,6 +593,27 @@ services: - _APP_SMS_FROM - _APP_SMS_PROVIDER - _APP_SMS_PROJECTS_DENY_LIST + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-migrations: entrypoint: worker-migrations diff --git a/src/Appwrite/Docker/Compose.php b/src/Appwrite/Docker/Compose.php index 64441805de..241e281ed8 100644 --- a/src/Appwrite/Docker/Compose.php +++ b/src/Appwrite/Docker/Compose.php @@ -27,14 +27,6 @@ class Compose } } - /** - * @return string - */ - public function getVersion(): string - { - return (isset($this->compose['version'])) ? $this->compose['version'] : ''; - } - /** * @return Service[] */ diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index c8df169e28..19d2c5a0fe 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -35,6 +35,7 @@ use Utopia\Messaging\Messages\SMS; use Utopia\Platform\Action; use Utopia\Queue\Message; use Utopia\Storage\Device; +use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Utopia\System\System; @@ -42,6 +43,8 @@ use function Swoole\Coroutine\batch; class Messaging extends Action { + private ?Local $localDevice = null; + public static function getName(): string { return 'messaging'; @@ -58,9 +61,8 @@ class Messaging extends Action ->inject('log') ->inject('dbForProject') ->inject('deviceForFiles') - ->inject('deviceForLocalFiles') ->inject('queueForUsage') - ->callback(fn (Message $message, Log $log, Database $dbForProject, Device $deviceForFiles, Device $deviceForLocalFiles, Usage $queueForUsage) => $this->action($message, $log, $dbForProject, $deviceForFiles, $deviceForLocalFiles, $queueForUsage)); + ->callback(fn (Message $message, Log $log, Database $dbForProject, Device $deviceForFiles, Usage $queueForUsage) => $this->action($message, $log, $dbForProject, $deviceForFiles, $queueForUsage)); } /** @@ -68,7 +70,6 @@ class Messaging extends Action * @param Log $log * @param Database $dbForProject * @param Device $deviceForFiles - * @param Device $deviceForLocalFiles * @param Usage $queueForUsage * @return void * @throws \Exception @@ -78,7 +79,6 @@ class Messaging extends Action Log $log, Database $dbForProject, Device $deviceForFiles, - Device $deviceForLocalFiles, Usage $queueForUsage ): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); @@ -101,7 +101,7 @@ class Messaging extends Action case MESSAGE_SEND_TYPE_EXTERNAL: $message = $dbForProject->getDocument('messages', $payload['messageId']); - $this->sendExternalMessage($dbForProject, $message, $deviceForFiles, $deviceForLocalFiles, ); + $this->sendExternalMessage($dbForProject, $message, $deviceForFiles, $project); break; default: throw new \Exception('Unknown message type: ' . $type); @@ -112,7 +112,7 @@ class Messaging extends Action Database $dbForProject, Document $message, Device $deviceForFiles, - Device $deviceForLocalFiles, + Document $project, ): void { $topicIds = $message->getAttribute('topics', []); $targetIds = $message->getAttribute('targets', []); @@ -218,8 +218,8 @@ class Messaging extends Action /** * @var array $results */ - $results = batch(\array_map(function ($providerId) use ($identifiers, &$providers, $default, $message, $dbForProject, $deviceForFiles, $deviceForLocalFiles) { - return function () use ($providerId, $identifiers, &$providers, $default, $message, $dbForProject, $deviceForFiles, $deviceForLocalFiles) { + $results = batch(\array_map(function ($providerId) use ($identifiers, &$providers, $default, $message, $dbForProject, $deviceForFiles, $project) { + return function () use ($providerId, $identifiers, &$providers, $default, $message, $dbForProject, $deviceForFiles, $project) { if (\array_key_exists($providerId, $providers)) { $provider = $providers[$providerId]; } else { @@ -246,8 +246,8 @@ class Messaging extends Action $adapter->getMaxMessagesPerRequest() ); - return batch(\array_map(function ($batch) use ($message, $provider, $adapter, $dbForProject, $deviceForFiles, $deviceForLocalFiles) { - return function () use ($batch, $message, $provider, $adapter, $dbForProject, $deviceForFiles, $deviceForLocalFiles) { + return batch(\array_map(function ($batch) use ($message, $provider, $adapter, $dbForProject, $deviceForFiles, $project) { + return function () use ($batch, $message, $provider, $adapter, $dbForProject, $deviceForFiles, $project) { $deliveredTotal = 0; $deliveryErrors = []; $messageData = clone $message; @@ -256,7 +256,7 @@ class Messaging extends Action $data = match ($provider->getAttribute('type')) { MESSAGE_TYPE_SMS => $this->buildSmsMessage($messageData, $provider), MESSAGE_TYPE_PUSH => $this->buildPushMessage($messageData), - MESSAGE_TYPE_EMAIL => $this->buildEmailMessage($dbForProject, $messageData, $provider, $deviceForFiles, $deviceForLocalFiles), + MESSAGE_TYPE_EMAIL => $this->buildEmailMessage($dbForProject, $messageData, $provider, $deviceForFiles, $project), default => throw new \Exception('Provider with the requested ID is of the incorrect type') }; @@ -354,8 +354,8 @@ class Messaging extends Action $path = $file->getAttribute('path', ''); - if ($deviceForLocalFiles->exists($path)) { - $deviceForLocalFiles->delete($path); + if ($this->getLocalDevice($project)->exists($path)) { + $this->getLocalDevice($project)->delete($path); } } } @@ -524,7 +524,7 @@ class Messaging extends Action Document $message, Document $provider, Device $deviceForFiles, - Device $deviceForLocalFiles, + Document $project, ): Email { $fromName = $provider['options']['fromName'] ?? null; $fromEmail = $provider['options']['fromEmail'] ?? null; @@ -586,7 +586,7 @@ class Messaging extends Action } if ($deviceForFiles->getType() !== Storage::DEVICE_LOCAL) { - $deviceForFiles->transfer($path, $path, $deviceForLocalFiles); + $deviceForFiles->transfer($path, $path, $this->getLocalDevice($project)); } $attachment = new Attachment( @@ -658,4 +658,13 @@ class Messaging extends Action $badge ); } + + private function getLocalDevice($project): Local + { + if($this->localDevice === null) { + $this->localDevice = new Local(APP_STORAGE_UPLOADS . '/app-' . $project->getId()); + } + + return $this->localDevice; + } } diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index cd3c3b64ba..acb31d9fbe 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: traefik: image: traefik:2.2 diff --git a/tests/unit/Docker/ComposeTest.php b/tests/unit/Docker/ComposeTest.php index 56448ffd01..93e0204264 100644 --- a/tests/unit/Docker/ComposeTest.php +++ b/tests/unit/Docker/ComposeTest.php @@ -21,11 +21,6 @@ class ComposeTest extends TestCase $this->object = new Compose($data); } - public function testVersion(): void - { - $this->assertEquals('3', $this->object->getVersion()); - } - public function testServices(): void { $this->assertCount(15, $this->object->getServices());