diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f6346e6..ab7933b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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" diff --git a/.gitignore b/.gitignore index 65a19cc..7ae71de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor/ /.idea/ .phpunit.result.cache -/tests/resources/functions/**/code.tar.gz \ No newline at end of file +/tests/resources/functions/**/code.tar.gz +/tests/resources/functions/**/code.zip \ No newline at end of file diff --git a/tests/ExecutorTest.php b/tests/ExecutorTest.php index 72aa0c0..5c26c53 100644 --- a/tests/ExecutorTest.php +++ b/tests/ExecutorTest.php @@ -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']); + } }