1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Get Rust Execution working

This commit is contained in:
Bradley Schofield 2021-09-20 16:52:12 +01:00
parent 3c533f1932
commit fc17e12547
3 changed files with 202 additions and 86 deletions

View file

@ -340,6 +340,7 @@ function runBuildStage(string $tagID, Document $function, string $projectID, Dat
'APPWRITE_FUNCTION_RUNTIME_NAME' => $runtime['name'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'],
'APPWRITE_FUNCTION_PROJECT_ID' => $projectID,
'APPWRITE_ENTRYPOINT_NAME' => $tag->getAttribute('entrypoint')
]);
$buildStart = \microtime(true);
@ -383,7 +384,7 @@ function runBuildStage(string $tagID, Document $function, string $projectID, Dat
command: [
'sh',
'-c',
'mkdir /usr/code -p && cp /tmp/code.tar.gz /usr/code.tar.gz && cd /usr && tar -zxf /usr/code.tar.gz -C /usr/code && rm /usr/code.tar.gz'
'mkdir -p /usr/code && cp /tmp/code.tar.gz /usr/code.tar.gz && cd /usr && tar -zxf /usr/code.tar.gz -C /usr/code && rm /usr/code.tar.gz'
],
stdout: $untarStdout,
stderr: $untarStderr,
@ -403,7 +404,7 @@ function runBuildStage(string $tagID, Document $function, string $projectID, Dat
command: $runtime['buildCommand'],
stdout: $buildStdout,
stderr: $buildStderr,
timeout: 60
timeout: 600 //TODO: Make this configurable
);
if (!$buildSuccess) {
@ -419,9 +420,7 @@ function runBuildStage(string $tagID, Document $function, string $projectID, Dat
$compressSuccess = $orchestration->execute(
name: $container,
command: [
'sh',
'-c',
'tar -czvf /usr/builtCode/code.tar.gz /usr/code'
'tar', '-C', '/usr/code', '-czvf', '/usr/builtCode/code.tar.gz', './'
],
stdout: $compressStdout,
stderr: $compressStderr,
@ -533,12 +532,12 @@ function createRuntimeServer(string $functionId, string $projectId, Document $ta
// Grab Tag Files
$tagPath = $tag->getAttribute('builtPath', '');
$tagPathTarget = '/tmp/project-' . $projectId . '/' . $tag->getId() . '/code.tar.gz';
$tagPathTarget = '/tmp/project-' . $projectId . '/' . $tag->getId() . '/builtCode/code.tar.gz';
$tagPathTargetDir = \pathinfo($tagPathTarget, PATHINFO_DIRNAME);
$container = 'appwrite-function-' . $tag->getId();
if (!\is_readable($tagPath)) {
throw new Exception('Code is not readable: ' . $tag->getAttribute('path', ''));
throw new Exception('Code is not readable: ' . $tagPath);
}
if (!\file_exists($tagPathTargetDir)) {
@ -589,24 +588,25 @@ function createRuntimeServer(string $functionId, string $projectId, Document $ta
// Add to network
$orchestration->networkConnect($container, 'appwrite_runtimes');
$untarStdout = '';
$untarStderr = '';
// Handled by Dockerfiles
// $untarStdout = '';
// $untarStderr = '';
$untarSuccess = $orchestration->execute(
name: $container,
command: [
'sh',
'-c',
'mkdir /usr/code -p && cp /tmp/code.tar.gz /usr/code/code.tar.gz && cd /usr/code && tar -zxf /usr/code/code.tar.gz --strip 1 && rm /usr/code/code.tar.gz'
],
stdout: $untarStdout,
stderr: $untarStderr,
timeout: 60
);
// $untarSuccess = $orchestration->execute(
// name: $container,
// command: [
// 'sh',
// '-c',
// 'mkdir /usr/code -p && cp /tmp/code.tar.gz /usr/code/code.tar.gz && cd /usr/code && tar -zxf /usr/code/code.tar.gz --strip 1 && rm /usr/code/code.tar.gz'
// ],
// stdout: $untarStdout,
// stderr: $untarStderr,
// timeout: 60
// );
if (!$untarSuccess) {
throw new Exception('Failed to extract tar: ' . $untarStderr);
}
// if (!$untarSuccess) {
// throw new Exception('Failed to extract tar: ' . $untarStderr);
// }
$executionEnd = \microtime(true);
@ -750,20 +750,28 @@ function execute(string $trigger, string $projectId, string $executionId, string
do {
$attempts++;
$ch = \curl_init();
\curl_setopt($ch, CURLOPT_URL, "http://" . $container . ":3000/");
\curl_setopt($ch, CURLOPT_POST, true);
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
$body = \json_encode([
'path' => '/usr/code',
'file' => $tag->getAttribute('entrypoint', ''),
'env' => $vars,
'payload' => $data,
'timeout' => $function->getAttribute('timeout', (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900))
]));
]);
\curl_setopt($ch, CURLOPT_URL, "http://" . $container . ":3000/");
\curl_setopt($ch, CURLOPT_POST, true);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\curl_setopt($ch, CURLOPT_TIMEOUT, $function->getAttribute('timeout', (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)));
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
\curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . \strlen($body)
]);
$executorResponse = \curl_exec($ch);
$error = \curl_error($ch);

226
composer.lock generated
View file

@ -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": "67e012ba43c42585ebaaf21f3e2ab840",
"content-hash": "5a286ad3333879ad6087d3ff97f2858b",
"packages": [
{
"name": "adhocore/jwt",
@ -119,10 +119,11 @@
"source": {
"type": "git",
"url": "https://github.com/PineappleIOnic/php-runtimes.git",
"reference": "147e76f4a72bc925d9d1613494417d583bd5de34"
"reference": "315b451ca1b5604c7d199628155703d908d832b5"
},
"require": {
"php": ">=8.0",
"utopia-php/orchestration": "dev-exp1",
"utopia-php/system": "0.4.*"
},
"require-dev": {
@ -155,7 +156,7 @@
"php",
"runtimes"
],
"time": "2021-09-06T14:46:02+00:00"
"time": "2021-09-20T12:17:32+00:00"
},
{
"name": "chillerlan/php-qrcode",
@ -237,16 +238,16 @@
},
{
"name": "chillerlan/php-settings-container",
"version": "2.1.1",
"version": "2.1.2",
"source": {
"type": "git",
"url": "https://github.com/chillerlan/php-settings-container.git",
"reference": "98ccc1b31b31a53bcb563465c4961879b2b93096"
"reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/98ccc1b31b31a53bcb563465c4961879b2b93096",
"reference": "98ccc1b31b31a53bcb563465c4961879b2b93096",
"url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/ec834493a88682dd69652a1eeaf462789ed0c5f5",
"reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5",
"shasum": ""
},
"require": {
@ -296,7 +297,7 @@
"type": "ko_fi"
}
],
"time": "2021-01-06T15:57:03+00:00"
"time": "2021-09-06T15:17:01+00:00"
},
{
"name": "colinmollenhour/credis",
@ -1902,7 +1903,7 @@
"source": {
"type": "git",
"url": "https://github.com/PineappleIOnic/orchestration.git",
"reference": "26b4d08fd72a00a1e2b41e11876e97566036db48"
"reference": "31ad19f3421b94b5050c06c0fe124b9aee09f1e3"
},
"require": {
"php": ">=8.0",
@ -1943,7 +1944,7 @@
"upf",
"utopia"
],
"time": "2021-08-27T09:04:09+00:00"
"time": "2021-09-17T15:25:20+00:00"
},
{
"name": "utopia-php/preloader",
@ -2213,6 +2214,64 @@
},
"time": "2021-02-04T14:14:49+00:00"
},
{
"name": "utopia-php/websocket",
"version": "0.0.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/websocket.git",
"reference": "808317ef4ea0683c2c82dee5d543b1c8378e2e1b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/websocket/zipball/808317ef4ea0683c2c82dee5d543b1c8378e2e1b",
"reference": "808317ef4ea0683c2c82dee5d543b1c8378e2e1b",
"shasum": ""
},
"require": {
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.5",
"swoole/ide-helper": "4.6.6",
"textalk/websocket": "1.5.2",
"vimeo/psalm": "^4.8.1",
"workerman/workerman": "^4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Utopia\\WebSocket\\": "src/WebSocket"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Eldad Fux",
"email": "eldad@appwrite.io"
},
{
"name": "Torsten Dittmann",
"email": "torsten@appwrite.io"
}
],
"description": "A simple abstraction for WebSocket servers.",
"keywords": [
"framework",
"php",
"upf",
"utopia",
"websocket"
],
"support": {
"issues": "https://github.com/utopia-php/websocket/issues",
"source": "https://github.com/utopia-php/websocket/tree/0.0.1"
},
"time": "2021-07-11T13:09:44+00:00"
},
{
"name": "webmozart/assert",
"version": "1.10.0",
@ -2441,16 +2500,16 @@
},
{
"name": "appwrite/sdk-generator",
"version": "0.12.1",
"version": "0.14.3",
"source": {
"type": "git",
"url": "https://github.com/appwrite/sdk-generator.git",
"reference": "8e3c4a0a4159152d428602ffc3a2a4947e72c609"
"reference": "a1075a59db33fe2bba9e648bf67b3ece1debcfa4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/8e3c4a0a4159152d428602ffc3a2a4947e72c609",
"reference": "8e3c4a0a4159152d428602ffc3a2a4947e72c609",
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/a1075a59db33fe2bba9e648bf67b3ece1debcfa4",
"reference": "a1075a59db33fe2bba9e648bf67b3ece1debcfa4",
"shasum": ""
},
"require": {
@ -2484,22 +2543,22 @@
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
"support": {
"issues": "https://github.com/appwrite/sdk-generator/issues",
"source": "https://github.com/appwrite/sdk-generator/tree/0.12.1"
"source": "https://github.com/appwrite/sdk-generator/tree/0.14.3"
},
"time": "2021-07-29T07:50:02+00:00"
"time": "2021-09-06T09:32:51+00:00"
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.3",
"version": "1.11.99.4",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
"reference": "fff576ac850c045158a250e7e27666e146e78d18"
"reference": "b174585d1fe49ceed21928a945138948cb394600"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/fff576ac850c045158a250e7e27666e146e78d18",
"reference": "fff576ac850c045158a250e7e27666e146e78d18",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b174585d1fe49ceed21928a945138948cb394600",
"reference": "b174585d1fe49ceed21928a945138948cb394600",
"shasum": ""
},
"require": {
@ -2543,7 +2602,7 @@
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.3"
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.4"
},
"funding": [
{
@ -2559,7 +2618,7 @@
"type": "tidelift"
}
],
"time": "2021-08-17T13:49:14+00:00"
"time": "2021-09-13T08:41:34+00:00"
},
{
"name": "composer/semver",
@ -3155,16 +3214,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.12.0",
"version": "v4.13.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "6608f01670c3cc5079e18c1dab1104e002579143"
"reference": "50953a2691a922aa1769461637869a0a2faa3f53"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143",
"reference": "6608f01670c3cc5079e18c1dab1104e002579143",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53",
"shasum": ""
},
"require": {
@ -3205,9 +3264,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0"
},
"time": "2021-07-21T10:44:31+00:00"
"time": "2021-09-20T12:20:58+00:00"
},
{
"name": "openlss/lib-array2xml",
@ -3484,16 +3543,16 @@
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.4.0",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0"
"reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0",
"reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30f38bffc6f24293dadd1823936372dfa9e86e2f",
"reference": "30f38bffc6f24293dadd1823936372dfa9e86e2f",
"shasum": ""
},
"require": {
@ -3501,7 +3560,8 @@
"phpdocumentor/reflection-common": "^2.0"
},
"require-dev": {
"ext-tokenizer": "*"
"ext-tokenizer": "*",
"psalm/phar": "^4.8"
},
"type": "library",
"extra": {
@ -3527,39 +3587,39 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0"
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.0"
},
"time": "2020-09-17T18:55:26+00:00"
"time": "2021-09-17T15:28:14+00:00"
},
{
"name": "phpspec/prophecy",
"version": "1.13.0",
"version": "1.14.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "be1996ed8adc35c3fd795488a653f4b518be70ea"
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea",
"reference": "be1996ed8adc35c3fd795488a653f4b518be70ea",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"reference": "d86dfc2e2a3cd366cee475e52c6bb3bbc371aa0e",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.2",
"php": "^7.2 || ~8.0, <8.1",
"php": "^7.2 || ~8.0, <8.2",
"phpdocumentor/reflection-docblock": "^5.2",
"sebastian/comparator": "^3.0 || ^4.0",
"sebastian/recursion-context": "^3.0 || ^4.0"
},
"require-dev": {
"phpspec/phpspec": "^6.0",
"phpspec/phpspec": "^6.0 || ^7.0",
"phpunit/phpunit": "^8.0 || ^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.11.x-dev"
"dev-master": "1.x-dev"
}
},
"autoload": {
@ -3594,29 +3654,29 @@
],
"support": {
"issues": "https://github.com/phpspec/prophecy/issues",
"source": "https://github.com/phpspec/prophecy/tree/1.13.0"
"source": "https://github.com/phpspec/prophecy/tree/1.14.0"
},
"time": "2021-03-17T13:42:18+00:00"
"time": "2021-09-10T09:02:12+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.6",
"version": "9.2.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "f6293e1b30a2354e8428e004689671b83871edde"
"reference": "d4c798ed8d51506800b441f7a13ecb0f76f12218"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde",
"reference": "f6293e1b30a2354e8428e004689671b83871edde",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d4c798ed8d51506800b441f7a13ecb0f76f12218",
"reference": "d4c798ed8d51506800b441f7a13ecb0f76f12218",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
"nikic/php-parser": "^4.10.2",
"nikic/php-parser": "^4.12.0",
"php": ">=7.3",
"phpunit/php-file-iterator": "^3.0.3",
"phpunit/php-text-template": "^2.0.2",
@ -3665,7 +3725,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.7"
},
"funding": [
{
@ -3673,7 +3733,7 @@
"type": "github"
}
],
"time": "2021-03-28T07:26:59+00:00"
"time": "2021-09-17T05:39:03+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -4920,7 +4980,6 @@
"type": "github"
}
],
"abandoned": true,
"time": "2020-09-28T06:45:17+00:00"
},
{
@ -5819,6 +5878,55 @@
],
"time": "2021-08-26T08:00:08+00:00"
},
{
"name": "textalk/websocket",
"version": "1.5.2",
"source": {
"type": "git",
"url": "https://github.com/Textalk/websocket-php.git",
"reference": "b93249453806a2dd46495de46d76fcbcb0d8dee8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Textalk/websocket-php/zipball/b93249453806a2dd46495de46d76fcbcb0d8dee8",
"reference": "b93249453806a2dd46495de46d76fcbcb0d8dee8",
"shasum": ""
},
"require": {
"php": "^7.2 | ^8.0",
"psr/log": "^1.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.0",
"phpunit/phpunit": "^8.0|^9.0",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"autoload": {
"psr-4": {
"WebSocket\\": "lib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"ISC"
],
"authors": [
{
"name": "Fredrik Liljegren"
},
{
"name": "Sören Jensen",
"email": "soren@abicart.se"
}
],
"description": "WebSocket client and server",
"support": {
"issues": "https://github.com/Textalk/websocket-php/issues",
"source": "https://github.com/Textalk/websocket-php/tree/1.5.2"
},
"time": "2021-02-12T15:39:23+00:00"
},
{
"name": "theseer/tokenizer",
"version": "1.2.1",
@ -5871,16 +5979,16 @@
},
{
"name": "twig/twig",
"version": "v2.14.6",
"version": "v2.14.7",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "27e5cf2b05e3744accf39d4c68a3235d9966d260"
"reference": "8e202327ee1ed863629de9b18a5ec70ac614d88f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/27e5cf2b05e3744accf39d4c68a3235d9966d260",
"reference": "27e5cf2b05e3744accf39d4c68a3235d9966d260",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/8e202327ee1ed863629de9b18a5ec70ac614d88f",
"reference": "8e202327ee1ed863629de9b18a5ec70ac614d88f",
"shasum": ""
},
"require": {
@ -5890,7 +5998,7 @@
},
"require-dev": {
"psr/container": "^1.0",
"symfony/phpunit-bridge": "^4.4.9|^5.0.9"
"symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0"
},
"type": "library",
"extra": {
@ -5934,7 +6042,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v2.14.6"
"source": "https://github.com/twigphp/Twig/tree/v2.14.7"
},
"funding": [
{
@ -5946,7 +6054,7 @@
"type": "tidelift"
}
],
"time": "2021-05-16T12:12:47+00:00"
"time": "2021-09-17T08:39:54+00:00"
},
{
"name": "vimeo/psalm",

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB