brefphp / extra-php-extensions

Community-maintained extra PHP extensions usable in AWS Lambda with the Bref PHP runtimes.
https://bref.sh/docs/environment/php.html#extra-extensions
213 stars 110 forks source link

LibSQL extension layer #564

Open speniti opened 4 weeks ago

speniti commented 4 weeks ago

Hello! I recently came across Turso, that seems a great fit for serverless applications and, since it requires an additional extension, I am trying to add a new layer to install it.

So, following the steps provided in the documentation, I built this Dockerfile:

ARG PHP_VERSION
ARG BREF_VERSION

FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext

COPY --from=composer /usr/bin/composer /usr/bin/composer

RUN composer global require darkterminal/turso-php-installer \
  && /root/.config/composer/vendor/bin/turso-php-installer install --yes
RUN echo 'extension=liblibsql_php.so' > /tmp/ext.ini

# Build the final image with just the files we need
FROM scratch

# Copy things we installed to the final image
COPY --from=ext /root/.turso-client-php/liblibsql_php.so /opt/bref/extensions/liblibsql_php.so
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-liblibsql.ini

The Docker build runs smoothly, but when I try to run the test with the command make test it fails with the following error:

Warning: PHP Startup: Unable to load dynamic library 'liblibsql_php.so' (tried: /opt/bref/extensions/liblibsql_php.so (/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /opt/bref/extensions/liblibsql_php.so)), /opt/bref/extensions/liblibsql_php.so.so (/opt/bref/extensions/liblibsql_php.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
FAIL: Class "LibSQL" does not exist.
make: *** [test] Error 1

The problem seems related to GLIBC_2.29 that is missing but, unfortunately, it is not clear to me where/how to install it properly. Can anyone help me to solve this issue, please?

Thanks! 🙏

speniti commented 3 weeks ago

Searching on the web, the issue seems related to the Bref's Docker image that, at the moment, is based upon Amazon Linux 2 and it contains GLIB.2.26. So this open PR should fix it.

notrab commented 2 weeks ago

Turso released a new LibSQL composer package which depends on ffi.enable. Is it possible to allow that configuration with fpm?