diff --git a/.env b/.env index dac72357ba..1b35cca898 100644 --- a/.env +++ b/.env @@ -56,7 +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_EXECUTOR_HOST=http://appwrite-executor/v1 _APP_MAINTENANCE_INTERVAL=86400 _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 diff --git a/Dockerfile b/Dockerfile index cb9f4e0c14..ba4c72ac40 100755 --- a/Dockerfile +++ b/Dockerfile @@ -185,7 +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_HOST=http://appwrite-executor/v1 \ _APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes \ _APP_SETUP=self-hosted \ _APP_VERSION=$VERSION \ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 6c2cf53290..da65d4deb4 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(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); $executionResponse = []; try { $executionResponse = $executor->createExecution( diff --git a/app/workers/builds.php b/app/workers/builds.php index a2665d0683..031ffd84c3 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(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); + $this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); } public function run(): void diff --git a/app/workers/deletes.php b/app/workers/deletes.php index d8aaf26e5a..b8a44ebb82 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(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); 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(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); + $executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); $executor->deleteRuntime($projectId, $deploymentId); } catch (Throwable $th) { Console::error($th->getMessage()); diff --git a/app/workers/functions.php b/app/workers/functions.php index 9bccc43a66..66464a9d23 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(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1')); + $this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST')); } public function run(): void diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index bebba919c4..300e1a7a9b 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -18,8 +18,6 @@ class Executor const METHOD_CONNECT = 'CONNECT'; const METHOD_TRACE = 'TRACE'; - const DEFAULT_HOST = 'http://appwrite-executor/v1'; - private $endpoint; private $selfSigned = false; @@ -28,14 +26,12 @@ class Executor 'content-type' => '', ]; - public function __construct(string $endpoint = self::DEFAULT_HOST) + public function __construct(string $endpoint) { - if (empty($endpoint)) { - Console::warning('Undefined Executor host (fallback to ' . self::DEFAULT_HOST . ')'); - $this->endpoint = self::DEFAULT_HOST; - } else { - $this->endpoint = $endpoint; + if (!filter_var($endpoint, FILTER_VALIDATE_URL)) { + throw new Exception('Unsupported endpoint'); } + $this->endpoint = $endpoint; } /**