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

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 thread httpserver-php8.2-distroless/server.php
Comment thread httpserver-lua5.1-distroless/http_server.lua
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

Comment thread httpserver-perl5.42-distroless/Dockerfile
Comment thread httpserver-php8.2-distroless/Dockerfile
Comment thread httpserver-perl5.42-distroless/README.md
@cosmintanasa47

Copy link
Copy Markdown
Author

About Copilot's observations:

First one - the perl distroless example works just fine so it doesn't fail to start as Copilot assumes.

Second one - Copilot's claim doesn't hold up against the actual runtime behavior observed: when the sockets.so was copied to the wrong path, PHP failed with "cannot open shared object file: No such file or directory" — the specific error for a missing file it's actively searching for. If sockets were already statically compiled into the /bin/php binary as Copilot claims, PHP would never attempt to dlopen a file for it at all, and the error would instead be something like "already loaded" or a symbol conflict, not a file-not-found. The observed error directly indicates the module is not built in, contradicting Copilot's assumption.

Third one - the two commands do the exact same thing - tested it.

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