frankenphp-demo icon indicating copy to clipboard operation
frankenphp-demo copied to clipboard

Unable to run static build

Open Skaronator opened this issue 4 months ago • 2 comments

I want to try out static build but quickly noticed that they are not working in this repository.

$ git clone [email protected]:dunglas/frankenphp-demo.git
$ cd frankenphp-demo
$ docker build -t static-app -f static-build.Dockerfile .

------

 1 warning found (use docker --debug to expand):
 - FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" (line 1)
static-build.Dockerfile:13
--------------------
  12 |     WORKDIR /go/src/app/
  13 | >>> RUN EMBED=dist/app/ \
  14 | >>>     ./build-static.sh
  15 |
--------------------
ERROR: failed to build: failed to solve: process "/bin/ash -eo pipefail -c EMBED=dist/app/     ./build-static.sh" did not complete successfully: exit code: 2

Skaronator avatar Sep 04 '25 09:09 Skaronator

I try

FROM --platform=linux/amd64 dunglas/frankenphp:static-builder

# Prepare the app
WORKDIR /go/src/app/dist/app
COPY . .

# +++++++++++++++++++++++++++++++++
RUN apk update \
    && apk add php84-ctype \
    php84-iconv \
    php84-openssl \
    php84-session
# +++++++++++++++++++++++++++++++++

RUN echo APP_ENV=prod > .env.local ; \
    echo APP_DEBUG=0 >> .env.local ; \
    composer install --ignore-platform-reqs --no-dev -a ; \
    composer dump-env prod

# Build the static binary
WORKDIR /go/src/app/
RUN EMBED=dist/app/ \
    ./build-static.sh \

output

274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libbz2.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libxml2.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libicui18n.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libicudata.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libz.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libiconv.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libcharset.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libbrotlidec.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libbrotlienc.a is not portable!
274.3 
274.3 *** Warning: Linking the shared library libphp.la against the
274.3 *** static library /go/src/app/dist/static-php-cli/buildroot/lib/libbrotlicommon.a is not portable!
275.7 Installing PHP SAPI module:       embed
275.9 [09:46:38] [D] [PASSTHRU] ar -t /go/src/app/dist/static-php-cli/buildroot/lib/libphp.a | grep '\.a$' | xargs -n1 ar d /go/src/app/dist/static-php-cli/buildroot/lib/libphp.a
281.8 [09:46:44] [I] [EXEC] nm -g --defined-only -P '/go/src/app/dist/static-php-cli/buildroot/lib/libphp.a'
281.9 [09:46:44] [D] Patching phpize prefix
281.9 [09:46:44] [D] Replacing file with type[1]: /go/src/app/dist/static-php-cli/buildroot/bin/phpize
281.9 [09:46:44] [D] Replacing file with type[1]: /go/src/app/dist/static-php-cli/buildroot/bin/phpize
281.9 [09:46:44] [D] Patching php-config prefix and libs order
281.9 [09:46:44] [I] running embed sanity check
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --cflags-only-other libbrotlicommon libbrotlidec libbrotlienc
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --cflags-only-other libxml-2.0
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --cflags-only-other libwebp libwebpdecoder libwebpdemux libwebpmux libsharpyuv
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-l libbrotlicommon libbrotlidec libbrotlienc
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-other libbrotlicommon libbrotlidec libbrotlienc
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-l libxml-2.0
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-other libxml-2.0
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-l libwebp libwebpdecoder libwebpdemux libwebpmux libsharpyuv
281.9 [09:46:44] [D] Running command (no output) : pkg-config --static --libs-only-other libwebp libwebpdecoder libwebpdemux libwebpmux libsharpyuv
281.9 [09:46:44] [D] Entering dir: /go/src/app/dist/static-php-cli/source/embed-test
281.9 [09:46:44] [I] [EXEC] gcc -o embed embed.c -fPIC -Os -I/go/src/app/dist/static-php-cli/buildroot/include -I/go/src/app/dist/static-php-cli/buildroot/include/php -I/go/src/app/dist/static-php-cli/buildroot/include/php/main -I/go/src/app/dist/static-php-cli/buildroot/include/php/TSRM -I/go/src/app/dist/static-php-cli/buildroot/include/php/Zend -I/go/src/app/dist/static-php-cli/buildroot/include/php/ext -DLIBXML_STATIC -L/go/src/app/dist/static-php-cli/buildroot/lib -lphp -lnghttp2 -lzip -lssl -lcrypto -lwebpdecoder -lwebpdemux -lwebpmux -lwebp -lsharpyuv -llz4 -ljpeg -lturbojpeg -lavif -lfreetype -lbz2 -lxml2 -licui18n -licuuc -licudata -lpthread -lm -lz -liconv -lcharset -lbrotlidec -lbrotlienc -lbrotlicommon -ldl -lpthread -lm -lc -static  -Wl,--dynamic-list=/go/src/app/dist/static-php-cli/buildroot/lib/libphp.a.dynsym
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(udata.ao):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `std::once_flag::_Prepare_execution::_Prepare_execution<std::call_once<void (&)()>(std::once_flag&, void (&)())::{lambda()#1}>(void (&)())::{lambda()#1}::_FUN()':
282.3 umutex.cpp:(.text._ZZNSt9once_flag18_Prepare_executionC4IZSt9call_onceIRFvvEJEEvRS_OT_DpOT0_EUlvE_EERS6_ENUlvE_4_FUNEv[_ZZNSt9once_flag18_Prepare_executionC4IZSt9call_onceIRFvvEJEEvRS_OT_DpOT0_EUlvE_EERS6_ENUlvE_4_FUNEv]+0x3): undefined reference to `std::__once_callable'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_init':
282.3 umutex.cpp:(.text.umtx_init+0x37): undefined reference to `std::condition_variable::condition_variable()'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_cleanup':
282.3 umutex.cpp:(.text.umtx_cleanup+0xc): undefined reference to `std::condition_variable::~condition_variable()'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::UMutex::getMutex() [clone .cold]':
282.3 umutex.cpp:(.text.unlikely._ZN6icu_776UMutex8getMutexEv+0x13): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text.unlikely._ZN6icu_776UMutex8getMutexEv+0x2a): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::UMutex::getMutex()':
282.3 umutex.cpp:(.text._ZN6icu_776UMutex8getMutexEv+0x5a): undefined reference to `std::__once_callable'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_776UMutex8getMutexEv+0x68): undefined reference to `std::__once_call'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_776UMutex8getMutexEv+0x8b): undefined reference to `__once_proxy'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `umtx_lock_77.cold':
282.3 umutex.cpp:(.text.unlikely.umtx_lock_77+0x3): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::umtx_initImplPreInit(icu_77::UInitOnce&) [clone .cold]':
282.3 umutex.cpp:(.text.unlikely._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0x17): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text.unlikely._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0x2e): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text.unlikely._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0xa3): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::umtx_initImplPreInit(icu_77::UInitOnce&)':
282.3 umutex.cpp:(.text._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0x14): undefined reference to `std::__once_callable'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0x1b): undefined reference to `std::__once_call'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0x52): undefined reference to `__once_proxy'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text._ZN6icu_7720umtx_initImplPreInitERNS_9UInitOnceE+0xbb): undefined reference to `std::condition_variable::wait(std::unique_lock<std::mutex>&)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::umtx_initImplPostInit(icu_77::UInitOnce&) [clone .cold]':
282.3 umutex.cpp:(.text.unlikely._ZN6icu_7721umtx_initImplPostInitERNS_9UInitOnceE+0x6): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: umutex.cpp:(.text.unlikely._ZN6icu_7721umtx_initImplPostInitERNS_9UInitOnceE+0xd): undefined reference to `std::__throw_system_error(int)'
282.3 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(umutex.ao): in function `icu_77::umtx_initImplPostInit(icu_77::UInitOnce&)':
282.3 umutex.cpp:(.text._ZN6icu_7721umtx_initImplPostInitERNS_9UInitOnceE+0x46): undefined reference to `std::condition_variable::notify_all()'
282.4 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(uobject.ao):(.data.rel.ro._ZTIN6icu_777UMemoryE[_ZTIN6icu_777UMemoryE]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
282.4 /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/src/app/dist/static-php-cli/buildroot/lib/libicuuc.a(uobject.ao):(.data.rel.ro._ZTIN6icu_777UObjectE[_ZTIN6icu_777UObjectE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
282.5 collect2: error: ld returned 1 exit status
282.5 ⚠ Validation failed: embed failed sanity check: build failed. Error message: 
282.5 ----------------------------------------
282.5 
282.5 Failed module: Builder for Linux
282.5 Failed validation module: static libphp.a sanity check
282.5 
282.5 Build PHP extra info:
282.5     Build OS:              Linux (x86_64)
282.5     Build Target:          false
282.5     Build Toolchain:       SPC\toolchain\GccNativeToolchain
282.5     Build SAPI:            embed
282.5     Static Extensions (3): ctype,iconv,xml
282.5     Shared Extensions (0): ""
282.5     Libraries (16):        brotli,libiconv,zlib,libxml2,bzip2,freetype,libavif,libjpeg,liblz4,libwebp,openssl,libzip,nghttp2
282.5     Strip Binaries:        yes
282.5     Enable ZTS:            yes
282.5     Build Dev:             yes
282.5     Config File Path:      /usr/local/etc/php
282.5     Opcache JIT:           disabled
282.5     PHP Version:           8.4.14
282.5 
282.5 Builder function: sanityCheck
282.5 
282.5 ----------------------------------------
282.5 
282.5 ⚠ The console output log is saved in /go/src/app/dist/static-php-cli/log/spc.output.log
282.5 ⚠ The shell output log is saved in /go/src/app/dist/static-php-cli/log/spc.shell.log
------

 1 warning found (use docker --debug to expand):
 - FromPlatformFlagConstDisallowed: FROM --platform flag should not use constant value "linux/amd64" (line 1)
static-build.Dockerfile:22
--------------------
  21 |     WORKDIR /go/src/app/
  22 | >>> RUN EMBED=dist/app/ \
  23 | >>>     ./build-static.sh \
  24 |     
--------------------
ERROR: failed to solve: process "/bin/ash -eo pipefail -c EMBED=dist/app/     ./build-static.sh" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/default/default/ov6l96vw5rzbehhap5ruzzavg
make: *** [Makefile:27: app] Ошибка 1

des1roer avatar Nov 03 '25 09:11 des1roer

Use in Dockerfile

FROM --platform=linux/amd64 dunglas/frankenphp:static-builder

# Update Go to 1.25 (required by Caddy v2.10.2)
RUN apk add --no-cache wget && \
    wget -O go.tar.gz https://go.dev/dl/go1.25.0.linux-amd64.tar.gz && \
    rm -rf /usr/local/go && \
    tar -C /usr/local -xzf go.tar.gz && \
    rm go.tar.gz

# Prepare the app
WORKDIR /go/src/app/dist/app
COPY . .

# Wrap composer to always add --ignore-platform-reqs
# The build-static.sh script runs composer, so we need this wrapper
RUN mv /usr/bin/composer /usr/bin/composer.real && \
    echo '#!/bin/sh' > /usr/bin/composer && \
    echo 'exec /usr/bin/composer.real "$@" --ignore-platform-reqs' >> /usr/bin/composer && \
    chmod +x /usr/bin/composer

# Build the static binary
WORKDIR /go/src/app/
RUN EMBED=dist/app/ \
    ./build-static.sh

Even so .. large codebases can't be embed currently, probably a Go limitation!?

519.5 /go/src/app/embed.go:24:5: embed app.tar: file too large (7255889920 bytes > 2000000000 bytes)

radutopala avatar Nov 07 '25 14:11 radutopala