Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary not working in Linux Alpine after upgrading from 5.12.1 to 5.13.0 #88

Closed
pabloFuente opened this issue Sep 11, 2024 · 6 comments
Closed

Comments

@pabloFuente
Copy link

What version of pkg are you using?

5.13.0

What version of Node.js are you using?

22.8.0

What operating system are you using?

Ubuntu 22.04

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

Node 22.8.0 for Alpine Linux 3.20.0

Describe the Bug

I have a Dockerfile using FROM alpine:3.20.3 where I run the Node binary (built with Node 22.8.0) generated with @yao-pkg/pkg. The binary is built with this command:

pkg server.cjs -t latest-linux

The resulting binary server works fine inside my Docker container based on alpine:3.20.3 if I build it with @yao-pkg/pkg:5.12.1, but it doesn't work if I build it with @yao-pkg/pkg:5.13.0. The error logged by the container in the latter case is this one:

Error relocating /bin/server: fcntl64: symbol not found
Error relocating /bin/server: fcntl64: symbol not found
Error relocating /bin/server: fcntl64: symbol not found
Error relocating /bin/server: fcntl64: symbol not found
...

My only guess based on the commit history of the repository is this dependency update between versions 5.12.1 and 5.13.0: dda9032#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L28

Expected Behavior

A Node binary built with @yao-pkg/pkg:5.13.0 should work fine inside a Linux Alpine 3.20.3 container, as it did with @yao-pkg/pkg:5.12.1.

To Reproduce

Pack a Node binary using @yao-pkg/pkg:5.13.0 and build a Docker container using the Dockerfile below. Any simple Node application should work. The resulting binary is referred as server in the Dockerfile:

FROM alpine:3.20.3
# Alpine needs these libraries to run the binary file
RUN apk add --no-cache gcompat libstdc++
COPY server /bin
CMD ["/bin/server"]

Running the container will output the following error:

Error relocating /bin/server: fcntl64: symbol not found

Doing the same using @yao-pkg/pkg:5.12.1 will NOT trigger this error.

@robertsLando
Copy link
Member

Hi @pabloFuente thanks for your issue, I think you are using pkg 5.14.0 and not 5.13.0 as 5.13 doens't have support for nodejs 22. Anyway does using nodejs 20 works?

Ref #87

@robertsLando
Copy link
Member

cc @faulpeltz

@faulpeltz
Copy link

Both binaries for node 20 and node 22 work with your Dockerfile example on my machine @pabloFuente - what is the exact target your building?

Things you can try:

  1. xxd -l 1024 -c 32 ./server dump the first 1K of your binary that could help
  2. try running the correct binary directly from "https://github.com/yao-pkg/pkg-fetch/releases" -> it should give a node error with a javascript stack

@faulpeltz
Copy link

Also you should build against latest-alpine not latest-linux, this should not need gcompat anyway

@robertsLando
Copy link
Member

Also you should build against latest-alpine not latest-linux, this should not need gcompat anyway

I think the problem is exactly this, I didn't noticed the command at start...

@pabloFuente
Copy link
Author

You were absolutetly correct. The proper target when packaging the binary should be latest-alpine instead of latest-linux. It is not related with the Node version (I had the same problem using Node 20 and 22 with pkg 5.14.0).

Using latest-alpine as target, the Dockerfile can be as simple as this:

FROM alpine:3.20.3
COPY server /bin
CMD ["/bin/server"]

The reason why the target latest-linux worked fine in a Linux Alpine container for pkg versions <5.13.0, I don't know. Something must have changed between 5.12.1 and 5.13.0.

Thank you for the quick support!

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

No branches or pull requests

3 participants