Skip to content

Commit

Permalink
Merge pull request #136 from open-runtimes/feat-zip-support
Browse files Browse the repository at this point in the history
Feat: ZIP support
  • Loading branch information
Meldiron authored Jan 8, 2025
2 parents d5890b7 + ab078cd commit bdfaad2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: Run Tests
run: |
docker run --rm -v $PWD:/app -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c "apk update && apk add docker-cli && composer install --profile --ignore-platform-reqs && composer test"
docker run --rm -v $PWD:/app -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock --network executor_runtimes -w /app phpswoole/swoole:5.1.2-php8.3-alpine sh -c "apk update && apk add docker-cli zip unzip && composer install --profile --ignore-platform-reqs && composer test"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/.idea/
.phpunit.result.cache
/tests/resources/functions/**/code.tar.gz
/tests/resources/functions/**/code.tar.gz
/tests/resources/functions/**/code.zip
42 changes: 42 additions & 0 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,4 +1005,46 @@ public function testCustomRuntimes(string $folder, string $image, string $entryp
$response = $this->client->call(Client::METHOD_DELETE, "/runtimes/custom-execute-{$folder}", [], []);
$this->assertEquals(200, $response['headers']['status-code']);
}

public function testZipBuild(): void
{
/** Prepare function */
$output = '';
Console::execute('cd /app/tests/resources/functions/php && zip -x code.zip -r code.zip .', '', $output);

$params = [
'remove' => true,
'runtimeId' => 'test-build-zip',
'source' => '/storage/functions/php/code.zip',
'destination' => '/storage/builds/test-zip',
'entrypoint' => 'index.php',
'image' => 'openruntimes/php:v4-8.1',
'command' => 'unzip /tmp/code.tar.gz -d /mnt/code && helpers/build.sh "composer install"',
];

$response = $this->client->call(Client::METHOD_POST, '/runtimes', [], $params);

$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty(201, $response['body']['path']);

$buildPath = $response['body']['path'];

/** Test executions */
$command = 'php src/server.php';
$params = [
'runtimeId' => 'test-exec-zip',
'source' => $buildPath,
'entrypoint' => 'index.php',
'image' => 'openruntimes/php:v4-8.1',
'runtimeEntrypoint' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "' . $command . '"'
];

$response = $this->client->call(Client::METHOD_POST, '/runtimes', [], $params);
$this->assertEquals(201, $response['headers']['status-code']);

$response = $this->client->call(Client::METHOD_POST, '/runtimes/test-exec-zip/executions');

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(200, $response['body']['statusCode']);
}
}

0 comments on commit bdfaad2

Please sign in to comment.