Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ZIP support #136

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}
Loading