dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.96k stars 244 forks source link

Static binary : wrong PHP version #761

Open mvuidev opened 6 months ago

mvuidev commented 6 months ago

What happened?

I try to create a custom static binary with PHP 8.2 and imagick extension :

sudo docker buildx bake --load --set "*.platform=linux/amd64" --set static-builder.args.PHP_VERSION=8.2 --set static-builder.args.PHP_EXTENSIONS=imagick --set static-builder.args.PHP_EXTENSIONS_LIBS="" --set static-builder.args.CLEAN=1 static-builder

sudo docker cp $(sudo docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp ; sudo docker rm static-builder

Binary is well created, but it's still in version 8.3 of PHP :

./frankenphp version

FrankenPHP v1.1.4 PHP 8.3.6 Caddy v2.7.6

Also checked with phpinfo() and same result (and imagick is not installed).

What am I doing wrong ?

Build Type

Custom (tell us more in the description)

Worker Mode

No

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration

--

Relevant log output

No response

dunglas commented 6 months ago

Could you try with the Docker cache disabled (add --no-cache)?

mvuidev commented 6 months ago

@dunglas Hi,

Just tried with --no-cache on docker buildx bake :

sudo docker buildx bake --load --set "*.platform=linux/amd64" --set static-builder.args.PHP_VERSION=8.2 --set static-builder.args.PHP_EXTENSIONS=imagick --set static-builder.args.PHP_EXTENSIONS_LIBS="" --set static-builder.args.CLEAN=1 --no-cache static-builder

sudo docker cp $(sudo docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-$(uname -m) frankenphp ; sudo docker rm static-builder

But the problem persists :/

charlienaud commented 4 months ago

Hi,

I'm facing the same issue

It seems to be related to this condition in the build-static.sh script: https://github.com/dunglas/frankenphp/blob/323edefc4b7cb69bcb318745efac4dec9b7ac488/build-static.sh#L76

When the static binary is build through docker, the dunglas/frankenphp:static-builder image comes with an existing dist/static-php-cli/ folder. So all the customization of PHP_VERSION, PHP_EXTENSIONS and PHP_EXTENSION_LIBS are ignored.


Workaround -> Delete the dist/static-php-cli/ folder before running the build script

NOTE: This significantly slows down the build process, as the static-php-cli is recompiled from source every time.

FROM dunglas/frankenphp:static-builder

ARG PHP_VERSION
ARG FRANKENPHP_VERSION

+ RUN rm -rf /go/src/app/dist/static-php-cli

# Prepare the app
WORKDIR /go/src/app/dist/app
COPY . .
RUN composer install --ignore-platform-reqs --no-dev -a

# Build the static binary
WORKDIR /go/src/app/
RUN EMBED=dist/app/ \
    NO_COMPRESS=1 \
    PHP_VERSION=${PHP_VERSION} \
    FRANKENPHP_VERSION=${FRANKENPHP_VERSION} \
    ./build-static.sh