node-oom-heapdump icon indicating copy to clipboard operation
node-oom-heapdump copied to clipboard

Build binaries for Alpine

Open orgads opened this issue 4 years ago • 5 comments

orgads avatar Jan 28 '21 15:01 orgads

Thanks for the pr, will check next week!

paulrutter avatar Feb 06 '21 08:02 paulrutter

Thank you. This is incomplete, because there are no alpine binaries for gcstats. I'm looking into that too, but it might take some time. And the original gcstats is not maintained, so we'll need to use an alternative fork, as proposed by @adnanraic. Will you consider that?

orgads avatar Feb 07 '21 08:02 orgads

I'll think about that. Another way to go is to drop the need for gc-stats altogether, as it's only needed for OOMImplementation: GC_MONITORING. We could release a new major version that only supports NATIVE_HOOK, making gc-stats no longer relevant.

paulrutter avatar Feb 08 '21 07:02 paulrutter

Or you can change it to an optionalDependency (with proper protection on require), then I'll be able to install oom-heapdump without build tools, as long as I don't need gc monitoring.

orgads avatar Feb 08 '21 07:02 orgads

Yes, that's possible as well. But it might be unexpected that GC_MONITORING won't work then, but that can be "solved" by logging a warning.

paulrutter avatar Feb 08 '21 08:02 paulrutter

Did you run this on your repo? I see no github actions there.

paulrutter avatar Jun 09 '24 19:06 paulrutter

I did this 3 years ago, I no longer remember. :)

Just stumbled upon the repo on my disk and remembered.

orgads avatar Jun 09 '24 19:06 orgads

Is this pr still relevant? E.g. Are prebuilt binaries still requested for alpine?

paulrutter avatar Jun 09 '24 19:06 paulrutter

Looks like the existing binaries are linked with glibc, so it should be needed, yes.

orgads avatar Jun 09 '24 19:06 orgads

I will take a look, thanks

paulrutter avatar Jun 09 '24 20:06 paulrutter

@orgads it has been released to npm, can you check if this works for you?

paulrutter avatar Jun 10 '24 06:06 paulrutter

hmm... Actually it looks like the original build works on alpine as well. I wonder how it works... 🤔

I guess you can revert the alpine parts of this change then. Sorry for the noise.

orgads avatar Jun 10 '24 16:06 orgads

As long as you have the build tools in place, it will compile it from source indeed. Still, having the prebuilt binaries is still good to have, i'll leave it in for now.

paulrutter avatar Jun 10 '24 16:06 paulrutter

I tested with 3.2.3 without installed build tools. I verified that the binary was not linked with musl, and that it was not built locally (the modification timestamp of the file was from a month ago).

It doesn't harm though, so it's your choice :)

orgads avatar Jun 10 '24 16:06 orgads

Strange, how is it able to call into native code then? Or do you have oom monitoring disabled? Then it would indeed work without compilation.

paulrutter avatar Jun 10 '24 16:06 paulrutter

No, it does use the native bindings.

Here:

docker run -w /app --rm -it node:18.19.0-alpine3.19 ash                                                                                              ✔  1h 8m 53s  orgads@siplenovo  20:27:58
/app # npm init -y
Wrote to /app/package.json:
[...]
/app # npm i [email protected]
[...]
/app # ls -l node_modules/node-oom-heapdump/build/Release/
total 28
-rwxr-xr-x    2 1001     127          23608 May 16 07:42 node_oom_heapdump_native.node
drwxr-xr-x    3 root     root          4096 Jun 10 17:28 obj.target
/app # strings node_modules/node-oom-heapdump/build/Release/node_oom_heapdump_native.node | grep musl
/app # strings node_modules/node-oom-heapdump/build/Release/node_oom_heapdump_native.node | grep libc
libc.so.6
/app # cd node_modules/node-oom-heapdump/
/app/node_modules/node-oom-heapdump # ldd build/Release/node_oom_heapdump_native.node
        /lib/ld-musl-x86_64.so.1 (0x7d307af48000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7d307aca9000)
        libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7d307af48000) <--- This line is interesting :)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7d307ac85000)
Error relocating build/Release/node_oom_heapdump_native.node: _ZN2v86String11NewFromUtf8EPNS_7IsolateEPKcNS_13NewStringTypeEi: symbol not found
Error relocating build/Release/node_oom_heapdump_native.node: _ZN2v812api_internal12ToLocalEmptyEv: symbol not found
[...]
/app/node_modules/node-oom-heapdump # node
Welcome to Node.js v18.19.0.
Type ".help" for more information.
> require('bindings')('node_oom_heapdump_native.node')
{
  call: [Function: call],
  path: '/app/node_modules/node-oom-heapdump/build/Release/node_oom_heapdump_native.node'
}

This is what ChatGPT had to say about it: https://chatgpt.com/share/40b7f4f3-7bbf-406d-aef6-7375063f7107 :)

The bottom line is that it might be ok for simple API calls, but it is recommended to build separately for musl.

orgads avatar Jun 10 '24 17:06 orgads

Thanks for the details, didn’t know how that worked n alpine. Let's keep it in for now :)

paulrutter avatar Jun 10 '24 18:06 paulrutter