Skip to content

Distroless builds: Lua, Perl and Php Distroless Builds - #460

Open
cosmintanasa47 wants to merge 13 commits into
unikraft-cloud:mainfrom
cosmintanasa47:lua-perl-php-distroless
Open

Distroless builds: Lua, Perl and Php Distroless Builds#460
cosmintanasa47 wants to merge 13 commits into
unikraft-cloud:mainfrom
cosmintanasa47:lua-perl-php-distroless

Conversation

@cosmintanasa47

Copy link
Copy Markdown

Those are the 3 distroless versions for the 3 examples present in the title. Details on each file's content in the commit messages.

First stage resolves dependencies, the second stage runs the server.

Didn't find a lua specific distroless image so I started to
build from the cc-debian distroless image, adding necessary
libraries. The image already contains some useful libraries.
Slightly modify to fit the new distroless version.
Slightly modify to fit new distroless version.
Unmodified files from non-distroless original version.
First stage resolves dependencies, the second stage runs the server.

Didn't find a perl distroless image and used cc-debian12 as
distroless image to have maximum compatibility with the build stage
image. Didn't add duplicate libraries.
Slightly modified to fit new distroless version.
Slightly modify to fit new distroless version.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The PHP distroless image wiring has correctness issues (extension placement/config duplication and interpreter path consistency) and the PHP server should fail fast on socket setup failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds three new “distroless” variants of existing HTTP server examples (Lua 5.1, Perl 5.42, PHP 8.2), including container rootfs definitions, Kraft specs, README deployment guides, and end-to-end tests to validate “Hello, World!” responses on Unikraft Cloud.

Changes:

  • Introduce new distroless example directories for Lua, Perl, and PHP with Dockerfile+Kraftfile-based root filesystems.
  • Add language-specific “Hello, World!” server implementations and supporting runtime config (e.g., PHP sockets).
  • Add E2E pytest coverage for each new distroless example.
File summaries
File Description
httpserver-php8.2-distroless/test_httpserver-php8.2-distroless.py New E2E test that builds, runs, and validates the PHP distroless example.
httpserver-php8.2-distroless/server.php PHP socket-based HTTP server implementation returning “Hello, World!”.
httpserver-php8.2-distroless/rootfs/usr/local/etc/php/php.ini PHP config enabling sockets extension for the distroless image.
httpserver-php8.2-distroless/README.md New deployment and usage guide for the PHP distroless example.
httpserver-php8.2-distroless/Kraftfile Unikraft Cloud specification for running the PHP distroless rootfs.
httpserver-php8.2-distroless/Dockerfile Distroless-rootfs build for PHP, including sockets extension provisioning.
httpserver-perl5.42-distroless/test_httpserver-perl5.42-distroless.py New E2E test that builds, runs, and validates the Perl distroless example.
httpserver-perl5.42-distroless/server.pl Perl HTTP::Daemon-based server returning “Hello, World!”.
httpserver-perl5.42-distroless/README.md New deployment and usage guide for the Perl distroless example.
httpserver-perl5.42-distroless/Kraftfile Unikraft Cloud specification for running the Perl distroless rootfs.
httpserver-perl5.42-distroless/Dockerfile Distroless-rootfs build for Perl runtime + modules.
httpserver-lua5.1-distroless/test_httpserver-lua5.1-distroless.py New E2E test that builds, runs, and validates the Lua distroless example.
httpserver-lua5.1-distroless/README.md New deployment and usage guide for the Lua distroless example.
httpserver-lua5.1-distroless/Kraftfile Unikraft Cloud specification for running the Lua distroless rootfs.
httpserver-lua5.1-distroless/http_server.lua Lua HTTP server implementation (lua-http) returning “Hello, World!”.
httpserver-lua5.1-distroless/Dockerfile Distroless-rootfs build for Lua + LuaRocks dependencies.
Review details

Suppressed comments (2)

httpserver-php8.2-distroless/server.php:26

  • If socket_listen() fails, the script prints an error but then enters the accept loop anyway. Exiting on failure avoids a broken instance that appears deployed but cannot accept connections.
if (socket_listen($sock, 5) === false) {
    echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}

httpserver-php8.2-distroless/server.php:22

  • If socket_bind() fails, the script currently continues and will attempt to listen()/accept() anyway. Exit early on failure so the instance fails fast instead of hanging or looping with errors.
if (socket_bind($sock, $address, $port) === false) {
    echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}

  • Files reviewed: 16/16 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread httpserver-php8.2-distroless/Dockerfile Outdated
Comment on lines +15 to +18
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}

Comment on lines +5 to +7
If a request is not a HEAD method, then reply with "Hello world!"

Usage: lua examples/server_hello.lua [<port>]
Comment thread httpserver-php8.2-distroless/Kraftfile Outdated
First stage installs dependencies, second one runs the server.

ghcr.io/opencodeco/distroless-php:8.2 image is the best suited
distroless image for this php8.2 http server. It contains all
necesary system libraries. Only useful files are copied,
no duplicate.

Copying the whole extensions folder preserves that versioned
subfolder, so PHP finds the .so where it expects it.
Took old Kraftfile and modified the php path to fit
the distroless php image ghcr.io/opencodeco/distroless-php:8.2.

Previos: /usr/local/bin/php
Current: /bin/php
Slightly modified to fit new distroless version.
Slightly modified to fit new distroless version.
Unmodified files from non-distroless version.
@cosmintanasa47

Copy link
Copy Markdown
Author

Modified so that the extensions problem and the php executable problem are resolved. Considering that I have to add distroless examples starting from the original non-distroless examples, I have to modify dockerfiles and kraftfiles, not source code. The examples added are tested and they work the same as the "original" ones.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical Perl and PHP runtime issues block approval; the Perl README command also needs correction.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

httpserver-php8.2-distroless/rootfs/usr/local/etc/php/php.ini:3

  • The selected ghcr.io/opencodeco/distroless-php:8.2 image ships a static PHP binary with sockets already compiled in, so this setting attempts to load a second copy of the same module from the separately built .so copied by the Dockerfile. That produces a startup warning and can fail if the module ABI differs; remove the dynamic extension copy/configuration or use a base image intended for shared extensions.
extension=sockets
  • Files reviewed: 16/16 changed files
  • Comments generated: 3
  • Review effort level: Lite

COPY --from=build /usr/local/lib/perl5 /usr/local/lib/perl5

# System libraries
COPY --from=build /usr/local/lib/perl5/5.42.0/x86_64-linux-gnu/CORE/libperl.so /usr/local/lib/perl5/5.42.0/x86_64-linux-gnu/CORE/libperl.so
FROM ghcr.io/opencodeco/distroless-php:8.2

# Copy sockets extension and enable it via php.ini.
COPY --from=build /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/

**Using the unikraft CLI (Recommended)**
```bash title="unikraft"
unikraft instance list --watch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants