diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index a10d7a007f..17b082fe32 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1079,7 +1079,7 @@ App::post('/v1/functions/:functionId/deployments') } $fileExt = new FileExt([FileExt::TYPE_GZIP]); - $fileSizeValidator = new FileSize(App::getEnv('_APP_FUNCTIONS_SIZE_LIMIT', 0)); + $fileSizeValidator = new FileSize(App::getEnv('_APP_FUNCTIONS_SIZE_LIMIT', '30000000')); $upload = new Upload(); // Make sure we handle a single file and multiple files the same way diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index d59f97b9da..f8ea37067c 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -381,6 +381,7 @@ services: - _APP_FUNCTIONS_BUILD_TIMEOUT - _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_MEMORY + - _APP_FUNCTIONS_SIZE_LIMIT - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN - _APP_STORAGE_DEVICE @@ -662,7 +663,7 @@ services: hostname: appwrite-executor <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.4.1 + image: openruntimes/executor:0.4.2 networks: - appwrite - runtimes diff --git a/app/workers/builds.php b/app/workers/builds.php index fb71dadcf5..f3eb1fb972 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -253,15 +253,24 @@ class BuildsV1 extends Worker $tmpPath = '/tmp/builds/' . \escapeshellcmd($buildId); $tmpPathFile = $tmpPath . '/code.tar.gz'; + $localDevice = new Local(); + + if (substr($tmpDirectory, -1) !== '/') { + $tmpDirectory .= '/'; + } + + $directorySize = $localDevice->getDirectorySize($tmpDirectory); + $functionsSizeLimit = (int) App::getEnv('_APP_FUNCTIONS_SIZE_LIMIT', '30000000'); + if ($directorySize > $functionsSizeLimit) { + throw new Exception('Repository directory size should be less than ' . number_format($functionsSizeLimit / 1048576, 2) . ' MBs.'); + } Console::execute('tar --exclude code.tar.gz -czf ' . $tmpPathFile . ' -C /tmp/builds/' . \escapeshellcmd($buildId) . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); - $localDevice = new Local(); - $buffer = $localDevice->read($tmpPathFile); - $mimeType = $localDevice->getFileMimeType($tmpPathFile); + $deviceFunctions = $this->getFunctionsDevice($project->getId()); $path = $deviceFunctions->getPath($deployment->getId() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); - $result = $deviceFunctions->write($path, $buffer, $mimeType); + $result = $localDevice->transfer($tmpPathFile, $path, $deviceFunctions); if (!$result) { throw new \Exception("Unable to move file"); @@ -480,7 +489,7 @@ class BuildsV1 extends Worker * Send realtime Event */ $target = Realtime::fromPayload( - // Pass first, most verbose event pattern + // Pass first, most verbose event pattern event: $allEvents[0], payload: $build, project: $project diff --git a/composer.json b/composer.json index 7775b990df..0d415677ce 100644 --- a/composer.json +++ b/composer.json @@ -64,7 +64,7 @@ "utopia-php/preloader": "0.2.*", "utopia-php/queue": "0.5.*", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "0.14.*", + "utopia-php/storage": "0.17.*", "utopia-php/swoole": "0.5.*", "utopia-php/vcs": "0.5.*", "utopia-php/websocket": "0.1.*", diff --git a/composer.lock b/composer.lock index 2580f92b3a..a345b65c45 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "54d54b76790d03a0bcfb9bbd23ed1009", + "content-hash": "13a3bdc7c1dec5756bf58ec73a49753d", "packages": [ { "name": "adhocore/jwt", @@ -2998,16 +2998,16 @@ }, { "name": "utopia-php/storage", - "version": "0.14.0", + "version": "0.17.0", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "eda6651ac16884dc2a79ecb984ea591ba1ed498c" + "reference": "efec5376c02d3d8330f1beb1469e6d6e313e21ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/eda6651ac16884dc2a79ecb984ea591ba1ed498c", - "reference": "eda6651ac16884dc2a79ecb984ea591ba1ed498c", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/efec5376c02d3d8330f1beb1469e6d6e313e21ee", + "reference": "efec5376c02d3d8330f1beb1469e6d6e313e21ee", "shasum": "" }, "require": { @@ -3015,10 +3015,12 @@ "ext-fileinfo": "*", "ext-lz4": "*", "ext-snappy": "*", + "ext-xz": "*", "ext-zlib": "*", "ext-zstd": "*", "php": ">=8.0", - "utopia-php/framework": "0.*.*" + "utopia-php/framework": "0.*.*", + "utopia-php/system": "0.*.*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -3045,9 +3047,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.14.0" + "source": "https://github.com/utopia-php/storage/tree/0.17.0" }, - "time": "2023-03-15T00:16:34+00:00" + "time": "2023-08-21T11:28:36+00:00" }, { "name": "utopia-php/swoole", @@ -4145,16 +4147,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.0", + "version": "1.24.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6" + "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", + "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", "shasum": "" }, "require": { @@ -4186,22 +4188,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1" }, - "time": "2023-09-07T20:46:32+00:00" + "time": "2023-09-18T12:18:02+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.28", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", - "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { @@ -4258,7 +4260,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.28" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -4266,7 +4268,7 @@ "type": "github" } ], - "time": "2023-09-12T14:36:20+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -6027,5 +6029,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/docker-compose.yml b/docker-compose.yml index a6c1018d3c..25c3973080 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -416,6 +416,7 @@ services: - _APP_FUNCTIONS_BUILD_TIMEOUT - _APP_FUNCTIONS_CPUS - _APP_FUNCTIONS_MEMORY + - _APP_FUNCTIONS_SIZE_LIMIT - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN - _APP_STORAGE_DEVICE @@ -716,7 +717,7 @@ services: hostname: appwrite-executor <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.4.1 + image: openruntimes/executor:0.4.2 networks: - appwrite - runtimes