From 192cf2e20d2f5cf0f24e4778e8adedbf9287aa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 10 Nov 2022 12:04:49 +0000 Subject: [PATCH] PR review changes + fix test --- .env | 10 +++---- Dockerfile | 6 +--- app/config/variables.php | 29 +++++++------------ app/views/install/compose.phtml | 14 ++++----- composer.lock | 28 +++++++++--------- docker-compose.yml | 12 ++++---- src/Executor/Executor.php | 24 ++++++--------- .../Functions/FunctionsCustomServerTest.php | 4 +-- 8 files changed, 53 insertions(+), 74 deletions(-) diff --git a/.env b/.env index 0f85260154..74315daa87 100644 --- a/.env +++ b/.env @@ -70,8 +70,9 @@ _APP_FUNCTIONS_TIMEOUT=900 _APP_FUNCTIONS_BUILD_TIMEOUT=900 _APP_FUNCTIONS_CPUS=1 _APP_FUNCTIONS_MEMORY=512 -OPR_EXECUTOR_INACTIVE_TRESHOLD=600 -OPR_EXECUTOR_NETWORK=openruntimes-runtimes +_APP_FUNCTIONS_INACTIVE_THRESHOLD=600 +_APP_FUNCTIONS_RUNTIMES_NETWORK=openruntimes-runtimes +_APP_FUNCTIONS_CONNECTION_STORAGE=file://localhost _APP_EXECUTOR_SECRET=your-secret-key _APP_EXECUTOR_HOST=http://exc1/v1 _APP_FUNCTIONS_RUNTIMES= @@ -85,6 +86,5 @@ _APP_USAGE_DATABASE_INTERVAL=15 _APP_USAGE_STATS=enabled _APP_LOGGING_PROVIDER= _APP_LOGGING_CONFIG= -OPR_EXECUTOR_CONNECTION_STORAGE=file://localhost -OPR_EXECUTOR_DOCKER_HUB_USERNAME= -OPR_EXECUTOR_DOCKER_HUB_PASSWORD= \ No newline at end of file +_APP_DOCKER_HUB_USERNAME= +_APP_DOCKER_HUB_PASSWORD= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 594cd69cb2..543f39cd62 100755 --- a/Dockerfile +++ b/Dockerfile @@ -262,11 +262,7 @@ ENV _APP_SERVER=swoole \ _APP_MAINTENANCE_RETENTION_ABUSE=86400 \ _APP_MAINTENANCE_INTERVAL=86400 \ _APP_LOGGING_PROVIDER= \ - OPR_EXECUTOR_CONNECTION_STORAGE=file://localhost \ - OPR_EXECUTOR_INACTIVE_TRESHOLD=600 \ - OPR_EXECUTOR_NETWORK=openruntimes-runtimes \ - OPR_EXECUTOR_DOCKER_HUB_USERNAME= \ - OPR_EXECUTOR_DOCKER_HUB_PASSWORD= + _APP_LOGGING_CONFIG= RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/app/config/variables.php b/app/config/variables.php index 7e02656620..7434f09b81 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -701,7 +701,7 @@ return [ ], [ 'name' => '_APP_FUNCTIONS_CONTAINERS', - 'description' => 'Deprecated since 1.2.0. Runtimes now timeout by inactivity using \'OPR_EXECUTOR_INACTIVE_TRESHOLD\'.', + 'description' => 'Deprecated since 1.2.0. Runtimes now timeout by inactivity using \'_APP_FUNCTIONS_INACTIVE_THRESHOLD\'.', 'introduction' => '0.7.0', 'default' => '10', 'required' => false, @@ -782,7 +782,7 @@ return [ ], [ 'name' => '_APP_FUNCTIONS_INACTIVE_THRESHOLD', - 'description' => 'Deprecated with 1.2.0, use \'OPR_EXECUTOR_INACTIVE_TRESHOLD\' instead!', + 'description' => 'The minimum time a function can be inactive before it\'s container is shutdown and put to sleep. The default value is 60 seconds.', 'introduction' => '0.13.0', 'default' => '60', 'required' => false, @@ -791,7 +791,7 @@ return [ ], [ 'name' => 'DOCKERHUB_PULL_USERNAME', - 'description' => 'Deprecated with 1.2.0, use \'OPR_EXECUTOR_DOCKER_HUB_USERNAME\' instead!', + 'description' => 'Deprecated with 1.2.0, use \'_APP_DOCKER_HUB_USERNAME\' instead!', 'introduction' => '0.10.0', 'default' => '', 'required' => false, @@ -800,7 +800,7 @@ return [ ], [ 'name' => 'DOCKERHUB_PULL_PASSWORD', - 'description' => 'Deprecated with 1.2.0, use \'OPR_EXECUTOR_DOCKER_HUB_PASSWORD\' instead!', + 'description' => 'Deprecated with 1.2.0, use \'_APP_DOCKER_HUB_PASSWORD\' instead!', 'introduction' => '0.10.0', 'default' => '', 'required' => false, @@ -818,7 +818,7 @@ return [ ], [ 'name' => 'OPEN_RUNTIMES_NETWORK', - 'description' => 'Deprecated with 1.2.0, use \'OPR_EXECUTOR_NETWORK\' instead!', + 'description' => 'Deprecated with 1.2.0, use \'_APP_FUNCTIONS_RUNTIMES_NETWORK\' instead!', 'introduction' => '0.13.0', 'default' => 'appwrite_runtimes', 'required' => false, @@ -826,25 +826,16 @@ return [ 'filter' => '' ], [ - 'name' => 'OPR_EXECUTOR_INACTIVE_TRESHOLD', - 'description' => 'The minimum time a function can be inactive before it\'s container is shutdown and put to sleep. The default value is 60 seconds', - 'introduction' => '1.2.0', - 'default' => '60', - 'required' => false, - 'question' => '', - 'filter' => '' - ], - [ - 'name' => 'OPR_EXECUTOR_NETWORK', + 'name' => '_APP_FUNCTIONS_RUNTIMES_NETWORK', 'description' => 'The docker network used for communication between the executor and runtimes. Change this if you have altered the default network names.', 'introduction' => '1.2.0', - 'default' => 'appwrite_runtimes', + 'default' => 'openruntimes-runtimes', 'required' => false, 'question' => '', 'filter' => '' ], [ - 'name' => 'OPR_EXECUTOR_DOCKER_HUB_USERNAME', + 'name' => '_APP_DOCKER_HUB_USERNAME', 'description' => 'The username for hub.docker.com. This variable is used to pull images from hub.docker.com.', 'introduction' => '1.2.0', 'default' => '', @@ -853,7 +844,7 @@ return [ 'filter' => '' ], [ - 'name' => 'OPR_EXECUTOR_DOCKER_HUB_PASSWORD', + 'name' => '_APP_DOCKER_HUB_PASSWORD', 'description' => 'The password for hub.docker.com. This variable is used to pull images from hub.docker.com.', 'introduction' => '1.2.0', 'default' => '', @@ -862,7 +853,7 @@ return [ 'filter' => '' ], [ - 'name' => 'OPR_EXECUTOR_CONNECTION_STORAGE', + 'name' => '_APP_FUNCTIONS_CONNECTION_STORAGE', 'description' => 'DSN record of storage driver where Open Runtimes Executor stores output of Appwrite Function Deployment builds.', 'introduction' => '1.2.0', 'default' => '', diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index e163ecac8e..915a09158a 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -134,10 +134,8 @@ services: - _APP_FUNCTIONS_SIZE_LIMIT - _APP_FUNCTIONS_TIMEOUT - _APP_FUNCTIONS_BUILD_TIMEOUT - - _APP_FUNCTIONS_CONTAINERS - _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_MEMORY - - _APP_FUNCTIONS_MEMORY_SWAP - _APP_FUNCTIONS_RUNTIMES - _APP_EXECUTOR_SECRET - _APP_EXECUTOR_HOST @@ -413,8 +411,6 @@ services: - _APP_EXECUTOR_SECRET - _APP_EXECUTOR_HOST - _APP_USAGE_STATS - - DOCKERHUB_PULL_USERNAME - - DOCKERHUB_PULL_PASSWORD appwrite-worker-mails: image: /: @@ -589,11 +585,11 @@ services: - openruntimes-functions:/storage/functions:rw - /tmp:/tmp:rw environment: - - OPR_EXECUTOR_CONNECTION_STORAGE - - OPR_EXECUTOR_INACTIVE_TRESHOLD - - OPR_EXECUTOR_NETWORK - - OPR_EXECUTOR_DOCKER_HUB_USERNAME - - OPR_EXECUTOR_DOCKER_HUB_PASSWORD + - OPR_EXECUTOR_CONNECTION_STORAGE=$_APP_FUNCTIONS_CONNECTION_STORAGE + - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_FUNCTIONS_INACTIVE_THRESHOLD + - OPR_EXECUTOR_NETWORK=$_APP_FUNCTIONS_RUNTIMES_NETWORK + - 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_SECRET=$_APP_EXECUTOR_SECRET diff --git a/composer.lock b/composer.lock index af264e7b30..d0ecd343a2 100644 --- a/composer.lock +++ b/composer.lock @@ -4836,16 +4836,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", "shasum": "" }, "require": { @@ -4860,7 +4860,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -4898,7 +4898,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" }, "funding": [ { @@ -4914,20 +4914,20 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.26.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e" + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", "shasum": "" }, "require": { @@ -4942,7 +4942,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -4981,7 +4981,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" }, "funding": [ { @@ -4997,7 +4997,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "textalk/websocket", diff --git a/docker-compose.yml b/docker-compose.yml index d1a011ad7f..2ab76ef805 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -160,6 +160,8 @@ services: - _APP_FUNCTIONS_SIZE_LIMIT - _APP_FUNCTIONS_TIMEOUT - _APP_FUNCTIONS_BUILD_TIMEOUT + - _APP_FUNCTIONS_CPUS + - _APP_FUNCTIONS_MEMORY - _APP_FUNCTIONS_RUNTIMES - _APP_EXECUTOR_SECRET - _APP_EXECUTOR_HOST @@ -700,11 +702,11 @@ services: - openruntimes-functions:/storage/functions:rw - /tmp:/tmp:rw environment: - - OPR_EXECUTOR_CONNECTION_STORAGE - - OPR_EXECUTOR_INACTIVE_TRESHOLD - - OPR_EXECUTOR_NETWORK - - OPR_EXECUTOR_DOCKER_HUB_USERNAME - - OPR_EXECUTOR_DOCKER_HUB_PASSWORD + - OPR_EXECUTOR_CONNECTION_STORAGE=$_APP_FUNCTIONS_CONNECTION_STORAGE + - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_FUNCTIONS_INACTIVE_THRESHOLD + - OPR_EXECUTOR_NETWORK=$_APP_FUNCTIONS_RUNTIMES_NETWORK + - 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_SECRET=$_APP_EXECUTOR_SECRET diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index b87b208e0a..ca0d3b5208 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -18,13 +18,11 @@ class Executor public const METHOD_CONNECT = 'CONNECT'; public const METHOD_TRACE = 'TRACE'; - private $endpoint; + private bool $selfSigned = false; - private $selfSigned = false; + private string $endpoint; - protected $headers = [ - 'content-type' => '', - ]; + protected array $headers; protected int $cpus; @@ -39,6 +37,10 @@ class Executor $this->endpoint = $endpoint; $this->cpus = \intval(App::getEnv('_APP_FUNCTIONS_CPUS', '1')); $this->memory = intval(App::getEnv('_APP_FUNCTIONS_MEMORY', '512')); + $this->headers = [ + 'content-type' => 'application/json', + 'authorization' => 'Bearer ' . App::getEnv('_APP_EXECUTOR_SECRET', ''), + ]; } /** @@ -71,11 +73,7 @@ class Executor ) { $runtimeId = "$projectId-$deploymentId"; $route = "/runtimes"; - $headers = [ - 'content-type' => 'application/json', - 'authorization' => 'Bearer ' . App::getEnv('_APP_EXECUTOR_SECRET', ''), - 'x-opr-runtime-id' => $runtimeId - ]; + $headers = array_merge($this->headers, [ 'x-opr-runtime-id' => $runtimeId ]); $params = [ 'runtimeId' => $runtimeId, 'source' => $source, @@ -128,11 +126,7 @@ class Executor ) { $runtimeId = "$projectId-$deploymentId"; $route = '/runtimes/' . $runtimeId . '/execution'; - $headers = [ - 'content-type' => 'application/json', - 'authorization' => 'Bearer ' . App::getEnv('_APP_EXECUTOR_SECRET', ''), - 'x-opr-runtime-id' => $runtimeId - ]; + $headers = array_merge($this->headers, [ 'x-opr-runtime-id' => $runtimeId ]); $params = [ 'runtimeId' => $runtimeId, 'variables' => $variables, diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 5e498368ea..6c047a4f09 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -631,7 +631,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('8.0', $execution['body']['response']); $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars $this->assertEquals('', $execution['body']['stderr']); - $this->assertLessThan(0.500, $execution['body']['duration']); + $this->assertLessThan(1.500, $execution['body']['duration']); /** * Test for FAILURE @@ -750,7 +750,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('PHP', $execution['body']['response']); $this->assertStringContainsString('8.0', $execution['body']['response']); $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars - $this->assertLessThan(0.500, $execution['body']['duration']); + $this->assertLessThan(1.500, $execution['body']['duration']); return $data; }