Skip to content

Commit 69a159b

Browse files
authored
Merge pull request #168 from open-runtimes/feat-uncompressed-builds
Feat: Uncompressed builds
2 parents 5fb29dd + 9dea285 commit 69a159b

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/Executor/Runner/Docker.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,19 @@ public function createRuntime(
442442
/**
443443
* Temporary file paths in the executor
444444
*/
445+
$buildFile = "code.tar.gz";
446+
if (($variables['OPEN_RUNTIMES_BUILD_COMPRESSION'] ?? '') === 'none') {
447+
$buildFile = "code.tar";
448+
}
449+
450+
$sourceFile = "code.tar.gz";
451+
if (\pathinfo($source, PATHINFO_EXTENSION) === 'tar') {
452+
$sourceFile = "code.tar";
453+
}
454+
445455
$tmpFolder = "tmp/$runtimeName/";
446-
$tmpSource = "/{$tmpFolder}src/code.tar.gz";
447-
$tmpBuild = "/{$tmpFolder}builds/code.tar.gz";
456+
$tmpSource = "/{$tmpFolder}src/$sourceFile";
457+
$tmpBuild = "/{$tmpFolder}builds/$buildFile";
448458
$tmpLogging = "/{$tmpFolder}logging"; // Build logs
449459
$tmpLogs = "/{$tmpFolder}logs"; // Runtime logs
450460

@@ -576,8 +586,7 @@ public function createRuntime(
576586
$container['size'] = $size;
577587

578588
$destinationDevice = $this->getStorageDevice($destination);
579-
$path = $destinationDevice->getPath(\uniqid() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION));
580-
589+
$path = $destinationDevice->getPath(\uniqid() . '.' . \pathinfo($tmpBuild, PATHINFO_EXTENSION));
581590

582591
if (!$localDevice->transfer($tmpBuild, $path, $destinationDevice)) {
583592
throw new Exception('Failed to move built code to storage', 500);

tests/ExecutorTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,53 @@ public function testBuildOutputDirectory(): void
325325
$this->assertEquals(200, $response['headers']['status-code']);
326326
}
327327

328+
public function testBuildUncompressed(): void
329+
{
330+
$output = '';
331+
Console::execute('cd /app/tests/resources/functions/node && tar --exclude code.tar.gz -czf code.tar.gz .', '', $output);
332+
333+
$runtimeId = \bin2hex(\random_bytes(4));
334+
335+
/** Build runtime */
336+
$params = [
337+
'runtimeId' => 'test-build-' . $runtimeId,
338+
'source' => '/storage/functions/node/code.tar.gz',
339+
'destination' => '/storage/builds/test',
340+
'entrypoint' => 'index.js',
341+
'image' => 'openruntimes/node:v5-22',
342+
'command' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && bash helpers/build.sh "npm install"',
343+
'variables' => [
344+
'OPEN_RUNTIMES_BUILD_COMPRESSION' => 'none'
345+
]
346+
];
347+
348+
$response = $this->client->call(Client::METHOD_POST, '/runtimes', [], $params);
349+
$this->assertEquals(201, $response['headers']['status-code']);
350+
$this->assertNotEmpty($response['body']['path']);
351+
352+
$buildPath = $response['body']['path'];
353+
354+
/** Ensure build folder exists (container still running) */
355+
$tmpFolderPath = '/tmp/executor-test-build-' . $runtimeId;
356+
$this->assertTrue(\is_dir($tmpFolderPath));
357+
$this->assertTrue(\file_exists($tmpFolderPath));
358+
359+
$response = $this->client->call(Client::METHOD_POST, '/runtimes/test-exec-' . $runtimeId . '/executions', [], [
360+
'source' => $buildPath,
361+
'entrypoint' => 'index.js',
362+
'image' => 'openruntimes/node:v5-22',
363+
'runtimeEntrypoint' => 'cp /tmp/code.tar /mnt/code/code.tar && nohup helpers/start.sh "bash helpers/server.sh"',
364+
]);
365+
366+
$this->assertEquals(200, $response['headers']['status-code']);
367+
$this->assertEquals(200, $response['body']['statusCode']);
368+
$json = json_decode($response['body']['body'], true);
369+
$this->assertEquals("Hello Open Runtimes 👋", $json['message']);
370+
371+
$response = $this->client->call(Client::METHOD_DELETE, '/runtimes/test-exec-' . $runtimeId, [], []);
372+
$this->assertEquals(200, $response['headers']['status-code']);
373+
}
374+
328375
public function testExecute(): void
329376
{
330377
/** Prepare function */

0 commit comments

Comments
 (0)