diff --git a/.env b/.env index 92b13e20ce..dac72357ba 100644 --- a/.env +++ b/.env @@ -56,6 +56,7 @@ _APP_FUNCTIONS_MEMORY_SWAP=0 _APP_FUNCTIONS_INACTIVE_THRESHOLD=60 OPEN_RUNTIMES_NETWORK=appwrite_runtimes _APP_EXECUTOR_SECRET=your-secret-key +_APP_EXECUTOR_HOST= _APP_MAINTENANCE_INTERVAL=86400 _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 diff --git a/Dockerfile b/Dockerfile index 023e88a205..cb9f4e0c14 100755 --- a/Dockerfile +++ b/Dockerfile @@ -185,6 +185,7 @@ ENV _APP_SERVER=swoole \ _APP_FUNCTIONS_MEMORY=128 \ _APP_FUNCTIONS_MEMORY_SWAP=128 \ _APP_EXECUTOR_SECRET=a-random-secret \ + _APP_EXECUTOR_HOST= \ _APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes \ _APP_SETUP=self-hosted \ _APP_VERSION=$VERSION \ diff --git a/app/config/variables.php b/app/config/variables.php index 6067622454..2bed472758 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -597,6 +597,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_EXECUTOR_HOST', + 'description' => 'The host used by Appwrite to communicate with the function executor!', + 'introduction' => '0.13.0', + 'default' => 'http://appwrite-executor/v1', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_EXECUTOR_RUNTIME_NETWORK', 'description' => 'Deprecated with 0.14.0, use \'OPEN_RUNTIMES_NETWORK\' instead!', diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d491b7d75b..6c2cf53290 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -938,7 +938,7 @@ App::post('/v1/functions/:functionId/executions') ]); /** Execute function */ - $executor = new Executor(); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); $executionResponse = []; try { $executionResponse = $executor->createExecution( diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 3ae1c2654f..4c3406ffed 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -128,6 +128,7 @@ services: - _APP_FUNCTIONS_MEMORY_SWAP - _APP_FUNCTIONS_RUNTIMES - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_STATSD_HOST @@ -268,6 +269,7 @@ services: - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST appwrite-worker-database: image: /: @@ -310,6 +312,7 @@ services: - _APP_ENV - _APP_OPENSSL_KEY_V1 - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_REDIS_USER @@ -379,6 +382,7 @@ services: - _APP_DB_PASS - _APP_FUNCTIONS_TIMEOUT - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_USAGE_STATS - DOCKERHUB_PULL_USERNAME - DOCKERHUB_PULL_PASSWORD diff --git a/app/workers/builds.php b/app/workers/builds.php index a81ccd9112..a2665d0683 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -33,7 +33,7 @@ class BuildsV1 extends Worker } public function init(): void { - $this->executor = new Executor(); + $this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); } public function run(): void diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 963488a00a..d8aaf26e5a 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -368,7 +368,7 @@ class DeletesV1 extends Worker * Request executor to delete all deployment containers */ Console::info("Requesting executor to delete all deployment containers for function " . $functionId); - $executor = new Executor(); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); foreach ($deploymentIds as $deploymentId) { try { $executor->deleteRuntime($projectId, $deploymentId); @@ -420,7 +420,7 @@ class DeletesV1 extends Worker */ Console::info("Requesting executor to delete deployment container for deployment " . $deploymentId); try { - $executor = new Executor(); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); $executor->deleteRuntime($projectId, $deploymentId); } catch (Throwable $th) { Console::error($th->getMessage()); diff --git a/app/workers/functions.php b/app/workers/functions.php index 2d4cdb2e54..9bccc43a66 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -37,7 +37,7 @@ class FunctionsV1 extends Worker public function init(): void { - $this->executor = new Executor(); + $this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); } public function run(): void diff --git a/docker-compose.yml b/docker-compose.yml index 1ed63bd6f3..9d3a28aeb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -150,6 +150,7 @@ services: - _APP_FUNCTIONS_MEMORY_SWAP - _APP_FUNCTIONS_RUNTIMES - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_STATSD_HOST @@ -306,6 +307,7 @@ services: - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST appwrite-worker-database: entrypoint: worker-database @@ -355,6 +357,7 @@ services: - _APP_ENV - _APP_OPENSSL_KEY_V1 - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_REDIS_USER @@ -429,6 +432,7 @@ services: - _APP_DB_PASS - _APP_FUNCTIONS_TIMEOUT - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST - _APP_USAGE_STATS - DOCKERHUB_PULL_USERNAME - DOCKERHUB_PULL_PASSWORD diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index fff322161f..bebba919c4 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -6,7 +6,7 @@ use Exception; use Utopia\App; use Utopia\CLI\Console; -class Executor +class Executor { const METHOD_GET = 'GET'; const METHOD_POST = 'POST'; @@ -18,6 +18,8 @@ class Executor const METHOD_CONNECT = 'CONNECT'; const METHOD_TRACE = 'TRACE'; + const DEFAULT_HOST = 'http://appwrite-executor/v1'; + private $endpoint; private $selfSigned = false; @@ -26,9 +28,14 @@ class Executor 'content-type' => '', ]; - public function __construct(string $endpoint = 'http://appwrite-executor/v1') - { - $this->endpoint = $endpoint; + public function __construct(string $endpoint = self::DEFAULT_HOST) + { + if (empty($endpoint)) { + Console::warning('Undefined Executor host (fallback to ' . self::DEFAULT_HOST . ')'); + $this->endpoint = self::DEFAULT_HOST; + } else { + $this->endpoint = $endpoint; + } } /** diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index 3955573723..e7bbaf2705 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -88,6 +88,7 @@ services: - _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_MEMORY - _APP_FUNCTIONS_MEMORY_SWAP + - _APP_EXECUTOR_HOST appwrite-worker-usage: entrypoint: worker-usage @@ -193,6 +194,7 @@ services: - _APP_DB_SCHEMA - _APP_DB_USER - _APP_DB_PASS + - _APP_EXECUTOR_HOST appwrite-worker-certificates: entrypoint: worker-certificates @@ -247,6 +249,7 @@ services: - _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_MEMORY - _APP_FUNCTIONS_MEMORY_SWAP + - _APP_EXECUTOR_HOST appwrite-worker-mails: entrypoint: worker-mails @@ -294,6 +297,7 @@ services: - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - _APP_EXECUTOR_SECRET + - _APP_EXECUTOR_HOST appwrite-schedule: entrypoint: schedule