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: Allow local images #134

Merged
merged 4 commits into from
Dec 2, 2024
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
OPR_EXECUTOR_ENV=development
OPR_EXECUTOR_IMAGE_PULL=enabled
OPR_EXECUTOR_RUNTIMES=php-8.1,dart-2.18,deno-1.24,node-18.0,python-3.10,ruby-3.1,cpp-17,dotnet-6.0
OPR_EXECUTOR_CONNECTION_STORAGE=
OPR_EXECUTOR_INACTIVE_TRESHOLD=60
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
docker run --rm -v $PWD:/app composer:2.6 sh -c \
"composer install --profile --ignore-platform-reqs && composer check"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ services:
- OPR_EXECUTOR_RUNTIME_VERSIONS
- OPR_EXECUTOR_RETRY_ATTEMPTS
- OPR_EXECUTOR_RETRY_DELAY_MS
- OPR_EXECUTOR_IMAGE_PULL

networks:
openruntimes-runtimes:
Expand All @@ -80,6 +81,7 @@ volumes:
OPR_EXECUTOR_ENV=development
OPR_EXECUTOR_RUNTIMES=php-8.0
OPR_EXECUTOR_CONNECTION_STORAGE=file://localhost
OPR_EXECUTOR_IMAGE_PULL=enabled
OPR_EXECUTOR_INACTIVE_TRESHOLD=60
OPR_EXECUTOR_MAINTENANCE_INTERVAL=60
OPR_EXECUTOR_NETWORK=openruntimes-runtimes
Expand Down Expand Up @@ -202,6 +204,7 @@ docker compose down
| OPR_EXECUTOR_RUNTIME_VERSIONS | Version tag for runtime environments, ex: `v4` |
| OPR_EXECUTOR_RETRY_ATTEMPTS | Number of retry attempts for failed executions, ex: `5` |
| OPR_EXECUTOR_RETRY_DELAY_MS | Delay (in milliseconds) between retry attempts, ex: `500` |
| OPR_EXECUTOR_IMAGE_PULL | Pull open runtimes images before executor starts. Takes `disabled` and `enabled` |

## Contributing

Expand Down
41 changes: 23 additions & 18 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -1491,25 +1491,30 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix
*/
$allowList = empty(Http::getEnv('OPR_EXECUTOR_RUNTIMES')) ? [] : \explode(',', Http::getEnv('OPR_EXECUTOR_RUNTIMES'));

$runtimeVersions = \explode(',', Http::getEnv('OPR_EXECUTOR_RUNTIME_VERSIONS', 'v4') ?? 'v4');
foreach ($runtimeVersions as $runtimeVersion) {
Console::success("Pulling $runtimeVersion images...");
$runtimes = new Runtimes($runtimeVersion); // TODO: @Meldiron Make part of open runtimes
$runtimes = $runtimes->getAll(true, $allowList);
$callables = [];
foreach ($runtimes as $runtime) {
$callables[] = function () use ($runtime, $orchestration) {
Console::log('Warming up ' . $runtime['name'] . ' ' . $runtime['version'] . ' environment...');
$response = $orchestration->pull($runtime['image']);
if ($response) {
Console::info("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
} else {
Console::warning("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
}
};
}
if (Http::getEnv('OPR_EXECUTOR_IMAGE_PULL', 'enabled') === 'disabled') {
// Useful to prevent auto-pulling from remote when testing local images
Console::info("Skipping image pulling");
} else {
Comment on lines +1494 to +1497

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Http::getEnv('OPR_EXECUTOR_IMAGE_PULL', 'enabled') === 'disabled') {
// Useful to prevent auto-pulling from remote when testing local images
Console::info("Skipping image pulling");
} else {
if (Http::getEnv('OPR_EXECUTOR_IMAGE_PULL', 'enabled') === 'disabled') {
// Useful to prevent auto-pulling from remote when testing local images
Console::info("Skipping image pulling");
return;
}

Can we do something like this to remove the else block and make a bit less indentation to make it readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly not in this scenario, code continues to start http server.

I like the idea, and it is possible to allow this, but that would make PR diff even bigger and more complex. I would like to avoid that as I want this PR merged quickly.

$runtimeVersions = \explode(',', Http::getEnv('OPR_EXECUTOR_RUNTIME_VERSIONS', 'v4') ?? 'v4');
foreach ($runtimeVersions as $runtimeVersion) {
Console::success("Pulling $runtimeVersion images...");
$runtimes = new Runtimes($runtimeVersion); // TODO: @Meldiron Make part of open runtimes
$runtimes = $runtimes->getAll(true, $allowList);
$callables = [];
foreach ($runtimes as $runtime) {
$callables[] = function () use ($runtime, $orchestration) {
Console::log('Warming up ' . $runtime['name'] . ' ' . $runtime['version'] . ' environment...');
$response = $orchestration->pull($runtime['image']);
if ($response) {
Console::info("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
} else {
Console::warning("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
}
};
}

batch($callables);
batch($callables);
}
}

Console::success("Image pulling finished.");
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
- OPR_EXECUTOR_RUNTIME_VERSIONS
- OPR_EXECUTOR_RETRY_ATTEMPTS
- OPR_EXECUTOR_RETRY_DELAY_MS
- OPR_EXECUTOR_IMAGE_PULL

volumes:
openruntimes-builds:
Expand Down