From 6d357d617dd6dd6a93fc22ec55ea240f733c4c46 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Mon, 11 Dec 2023 23:37:32 +0000 Subject: [PATCH 1/6] Add a flag to install and upgrade commands to not start Appwrite This can be useful for cases where the developer only wants the files to be generated and doesn't want to start Appwrite. --- src/Appwrite/Platform/Tasks/Install.php | 14 +++++++++----- src/Appwrite/Platform/Tasks/Upgrade.php | 8 +++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index eb419ade11..8591f4bcc3 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -8,6 +8,7 @@ use Appwrite\Docker\Env; use Appwrite\Utopia\View; use Utopia\CLI\Console; use Utopia\Config\Config; +use Utopia\Validator\Boolean; use Utopia\Validator\Text; use Utopia\Platform\Action; @@ -29,10 +30,11 @@ class Install extends Action ->param('organization', 'appwrite', new Text(0), 'Docker Registry organization', true) ->param('image', 'appwrite', new Text(0), 'Main appwrite docker image', true) ->param('interactive', 'Y', new Text(1), 'Run an interactive session', true) - ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive)); + ->param('noStart', false, new Boolean(true), 'Run an interactive session', true) + ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart)); } - public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive): void + public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart): void { $config = Config::getParam('variables'); $defaultHTTPPort = '80'; @@ -220,9 +222,11 @@ class Install extends Action } } - Console::log("Running \"docker compose up -d --remove-orphans --renew-anon-volumes\""); - - $exit = Console::execute("$env docker compose --project-directory $this->path up -d --remove-orphans --renew-anon-volumes", '', $stdout, $stderr); + $exit = 0; + if (!$noStart) { + Console::log("Running \"docker compose up -d --remove-orphans --renew-anon-volumes\""); + $exit = Console::execute("$env docker compose --project-directory $this->path up -d --remove-orphans --renew-anon-volumes", '', $stdout, $stderr); + } if ($exit !== 0) { $message = 'Failed to install Appwrite dockers'; diff --git a/src/Appwrite/Platform/Tasks/Upgrade.php b/src/Appwrite/Platform/Tasks/Upgrade.php index e3f0458394..1f3e148a82 100644 --- a/src/Appwrite/Platform/Tasks/Upgrade.php +++ b/src/Appwrite/Platform/Tasks/Upgrade.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Tasks; use Utopia\CLI\Console; +use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Upgrade extends Install @@ -21,10 +22,11 @@ class Upgrade extends Install ->param('organization', 'appwrite', new Text(0), 'Docker Registry organization', true) ->param('image', 'appwrite', new Text(0), 'Main appwrite docker image', true) ->param('interactive', 'Y', new Text(1), 'Run an interactive session', true) - ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive)); + ->param('noStart', false, new Boolean(true), 'Run an interactive session', true) + ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart)); } - public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive): void + public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart): void { // Check for previous installation $data = @file_get_contents($this->path . '/docker-compose.yml'); @@ -37,6 +39,6 @@ class Upgrade extends Install Console::log(' └── docker-compose.yml'); Console::exit(1); } - parent::action($httpPort, $httpsPort, $organization, $image, $interactive); + parent::action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart); } } From f1ba7b08ab40718aa08f0eb0b682676ca0a74ec7 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 27 Dec 2023 23:35:32 +0000 Subject: [PATCH 2/6] Update the delete identity endpoints to set the params and payload Because no payload was set, the event params (userId and identityId) wasn't picked up automatically. This updates the endpoints so that the payload is set, but also makes sure to set the userId and identityId params since the identityId param's key doesn't match the key in the payload. --- app/controllers/api/account.php | 10 ++++++++-- app/controllers/api/users.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c210b19f4f..9cbe6ce7ef 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -842,7 +842,7 @@ App::get('/v1/account/identities') }); App::delete('/v1/account/identities/:identityId') - ->desc('Delete Identity') + ->desc('Delete identity') ->groups(['api', 'account']) ->label('scope', 'account') ->label('event', 'users.[userId].identities.[identityId].delete') @@ -859,7 +859,8 @@ App::delete('/v1/account/identities/:identityId') ->param('identityId', '', new UID(), 'Identity ID.') ->inject('response') ->inject('dbForProject') - ->action(function (string $identityId, Response $response, Database $dbForProject) { + ->inject('queueForEvents') + ->action(function (string $identityId, Response $response, Database $dbForProject, Event $queueForEvents) { $identity = $dbForProject->getDocument('identities', $identityId); @@ -869,6 +870,11 @@ App::delete('/v1/account/identities/:identityId') $dbForProject->deleteDocument('identities', $identityId); + $queueForEvents + ->setParam('userId', $identity->getAttribute('userId')) + ->setParam('identityId', $identity->getId()) + ->setPayload($response->output($identity, Response::MODEL_IDENTITY)); + return $response->noContent(); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 0869453cc9..30f52c614e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1211,7 +1211,7 @@ App::delete('/v1/users/:userId') }); App::delete('/v1/users/identities/:identityId') - ->desc('Delete Identity') + ->desc('Delete identity') ->groups(['api', 'users']) ->label('event', 'users.[userId].identities.[identityId].delete') ->label('scope', 'users.write') @@ -1227,7 +1227,8 @@ App::delete('/v1/users/identities/:identityId') ->param('identityId', '', new UID(), 'Identity ID.') ->inject('response') ->inject('dbForProject') - ->action(function (string $identityId, Response $response, Database $dbForProject) { + ->inject('queueForEvents') + ->action(function (string $identityId, Response $response, Database $dbForProject, Event $queueForEvents) { $identity = $dbForProject->getDocument('identities', $identityId); @@ -1237,6 +1238,11 @@ App::delete('/v1/users/identities/:identityId') $dbForProject->deleteDocument('identities', $identityId); + $queueForEvents + ->setParam('userId', $identity->getAttribute('userId')) + ->setParam('identityId', $identity->getId()) + ->setPayload($response->output($identity, Response::MODEL_IDENTITY)); + return $response->noContent(); }); From b6b5570b0b75f7e3c8a1fb6307bbadc589f1cc08 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 3 Jan 2024 19:48:31 +0000 Subject: [PATCH 3/6] Add General E2E tests to CI pipeline --- .github/workflows/tests.yml | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 842d61ff1c..2fb6840f6e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -75,8 +75,32 @@ jobs: - name: Run Unit Tests run: docker compose exec appwrite test /usr/src/code/tests/unit - e2e_test: - name: E2E Test + e2e_general_test: + name: E2E General Test + runs-on: ubuntu-latest + needs: setup + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Load Cache + uses: actions/cache@v3 + with: + key: ${{ env.CACHE_KEY }} + path: /tmp/${{ env.IMAGE }}.tar + fail-on-cache-miss: true + + - name: Load and Start Appwrite + run: | + docker load --input /tmp/${{ env.IMAGE }}.tar + docker compose up -d + sleep 10 + + - name: Run General Tests + run: docker compose exec -T appwrite test /usr/src/code/tests/e2e/General --debug + + e2e_service_test: + name: E2E Service Test runs-on: ubuntu-latest needs: setup strategy: @@ -119,4 +143,4 @@ jobs: sleep 10 - name: Run ${{matrix.service}} Tests - run: docker compose exec -T appwrite test /usr/src/code/tests/e2e/Services/${{matrix.service}} --debug \ No newline at end of file + run: docker compose exec -T appwrite test /usr/src/code/tests/e2e/Services/${{matrix.service}} --debug From fbd277f6aa0ff161838a60e79b950e5a3f58e3f6 Mon Sep 17 00:00:00 2001 From: Ben Humphries Date: Thu, 4 Jan 2024 05:46:08 -0500 Subject: [PATCH 4/6] executor: pass build timeout to runtimes (#7350) open-runtimes executor (v1/runtimes) supports passing a timeout parameter that defaults to 600 seconds. ->param('timeout', 600, new Integer(), 'Commands execution time in seconds.', true) https://github.com/open-runtimes/executor/blob/main/app/http.php#L383 This change passes the _APP_FUNCTIONS_BUILD_TIMEOUT env var. --- src/Executor/Executor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index c7388069a1..8e73747047 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -72,6 +72,7 @@ class Executor ) { $runtimeId = "$projectId-$deploymentId-build"; $route = "/runtimes"; + $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); $params = [ 'runtimeId' => $runtimeId, 'source' => $source, @@ -84,10 +85,9 @@ class Executor 'cpus' => $this->cpus, 'memory' => $this->memory, 'version' => $version, + 'timeout' => $timeout, ]; - $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); - $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout); $status = $response['headers']['status-code']; @@ -111,7 +111,7 @@ class Executor string $projectId, callable $callback ) { - $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); + $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); $runtimeId = "$projectId-$deploymentId-build"; $route = "/runtimes/{$runtimeId}/logs"; From 864703fb4ee5711af4a05d6927111a9a70b38210 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Mon, 8 Jan 2024 20:56:51 +0000 Subject: [PATCH 5/6] Update the install/upgrade arguments to be kebab instead of camel case Kebab case like --http-port is much more common in CLIs than --httpPort. --- src/Appwrite/Platform/Tasks/Install.php | 6 +++--- src/Appwrite/Platform/Tasks/Upgrade.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 8591f4bcc3..c6107c6ba8 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -25,12 +25,12 @@ class Install extends Action { $this ->desc('Install Appwrite') - ->param('httpPort', '', new Text(4), 'Server HTTP port', true) - ->param('httpsPort', '', new Text(4), 'Server HTTPS port', true) + ->param('http-port', '', new Text(4), 'Server HTTP port', true) + ->param('https-port', '', new Text(4), 'Server HTTPS port', true) ->param('organization', 'appwrite', new Text(0), 'Docker Registry organization', true) ->param('image', 'appwrite', new Text(0), 'Main appwrite docker image', true) ->param('interactive', 'Y', new Text(1), 'Run an interactive session', true) - ->param('noStart', false, new Boolean(true), 'Run an interactive session', true) + ->param('no-start', false, new Boolean(true), 'Run an interactive session', true) ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart)); } diff --git a/src/Appwrite/Platform/Tasks/Upgrade.php b/src/Appwrite/Platform/Tasks/Upgrade.php index 1f3e148a82..341ce42fc4 100644 --- a/src/Appwrite/Platform/Tasks/Upgrade.php +++ b/src/Appwrite/Platform/Tasks/Upgrade.php @@ -17,12 +17,12 @@ class Upgrade extends Install { $this ->desc('Upgrade Appwrite') - ->param('httpPort', '', new Text(4), 'Server HTTP port', true) - ->param('httpsPort', '', new Text(4), 'Server HTTPS port', true) + ->param('http-port', '', new Text(4), 'Server HTTP port', true) + ->param('https-port', '', new Text(4), 'Server HTTPS port', true) ->param('organization', 'appwrite', new Text(0), 'Docker Registry organization', true) ->param('image', 'appwrite', new Text(0), 'Main appwrite docker image', true) ->param('interactive', 'Y', new Text(1), 'Run an interactive session', true) - ->param('noStart', false, new Boolean(true), 'Run an interactive session', true) + ->param('no-start', false, new Boolean(true), 'Run an interactive session', true) ->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart)); } From 310d75b6be6e072d3bd63d62b2b3f6f671196232 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:17:52 +0000 Subject: [PATCH 6/6] feat: update assistant --- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 898b46b3a5..9146d0cca4 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -652,7 +652,7 @@ services: - _APP_DB_PASS appwrite-assistant: - image: appwrite/assistant:0.2.2 + image: appwrite/assistant:0.3.0 container_name: appwrite-assistant <<: *x-logging restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index 97cf7e5136..7fe63473d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -711,7 +711,7 @@ services: appwrite-assistant: container_name: appwrite-assistant - image: appwrite/assistant:0.2.2 + image: appwrite/assistant:0.3.0 networks: - appwrite environment: