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 mirroring not working since node-pre-gyp to prebuild-install migration #4667

Closed
Fiouz opened this issue Jun 21, 2022 · 8 comments
Closed

Comments

@Fiouz
Copy link

Fiouz commented Jun 21, 2022

How frequently does the bug occur?

All the time

Description

Context

Command

npm --loglevel=verbose install [email protected]

Expected behavior

npm install should success, and since our build machines are not able to compile native components, success would imply that the binary was successfully downloaded from the configured HTTP mirror.

Since the mirror setting between node-pre-gyp and prebuild-install has the same spelling, we expect a working mirroring for older versions to also work for newer versions of realm.

See also: #2501

Actual behavior

When prebuild-install constructs the mirror URL, the URL has a different shape compared to the "original" URL, making it unable to download anything from the mirror.

Generated URL for mirroring:

<mirror_prefix>/v10.20.0-beta.5/realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz

Original URL (without mirroring):

<original_prefix>/realm-js-prebuilds/10.20.0-beta.5/realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz

(URL obtained by manually executing the prebuild-install --verbose command from the node_modules/realm directory)

This only affects latest versions, previous versions that relied on node-pre-gyp (e.g. 6.1.8) are properly mirrored, i.e. the following works fine with binary mirroring enabled:

npm --loglevel=verbose install [email protected]

Stacktrace & log output

npm verb stack Error: command failed
npm verb stack     at ChildProcess.<anonymous> (C:\Users\Fiouz\AppData\Local\Temp\realm\prefix\node_modules\npm\node_modules\@npmcli\promise-spawn\lib\index.js:63:27)
npm verb stack     at ChildProcess.emit (node:events:527:28)
npm verb stack     at maybeClose (node:internal/child_process:1092:16)
npm verb stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm verb pkgid [email protected]
npm verb cwd C:\Users\Fiouz\AppData\Local\Temp\realm\project
npm verb Windows_NT 10.0.19043
npm verb node v16.15.1
npm verb npm  v8.12.2
npm ERR! code 1
npm ERR! path C:\Users\Fiouz\AppData\Local\Temp\realm\project\node_modules\realm
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install -r napi || cmake-js build
npm ERR! prebuild-install info begin Prebuild-install version 7.1.1
npm ERR! prebuild-install info looking for local prebuild @ prebuilds\realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz
npm ERR! prebuild-install info looking for cached prebuild @ C:\Users\Fiouz\AppData\Local\Temp\realm\cache\_prebuilds\0b863b-realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz
npm ERR! prebuild-install http request GET https://static.realm.io/v10.20.0-beta.5/realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz
npm ERR! prebuild-install http 404 https://static.realm.io/v10.20.0-beta.5/realm-v10.20.0-beta.5-napi-v4-win32-x64.tar.gz
npm ERR! prebuild-install warn install No prebuilt binaries found (target=4 runtime=napi arch=x64 libc= platform=win32)
npm ERR! 'cmake-js' is not recognized as an internal or external command,
npm ERR! operable program or batch file.

Can you reproduce the bug?

Yes, always

Reproduction Steps

  1. Make sure local machine does not have native compilation capability
  2. Setup an HTTP mirror for https://static.realm.io
  3. Configure the realm_binary_host_mirror npm variable with the relevant mirror URL (npm config set realm_binary_host_mirror https://mirror.host/static.realm.io)
    Since it may be impractical to setup an HTTP mirror just for the sake of reproducing the issue, you can just use the official URL as a mirror URL, and see that this results in a broken URL, as shown in the above reported failure log:
npm config set realm_binary_host_mirror https://static.realm.io
  1. Clean <npm_config_cache>/_prebuilds
  2. npm --loglevel=verbose install [email protected], and see that it fails
  3. Try an older version that still uses node-pre-gyp npm --loglevel=verbose install [email protected], and see that it succeeds

Note: details about mirroring the npm registry, and making it work with custom X.509 certificates are omitted from the reproduction steps for brevity

Version

10.20.0-beta.5

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Windows / Linux

Build environment

[email protected]
[email protected]

Cocoapods version

No response

@tomduncalf
Copy link
Contributor

Thanks for the report @Fiouz. This isn't something I'm familiar with but it sounds like you probably have some in depth knowledge of working with this setup – do you have any idea of what we might need to change to make this work, or an example of another npm module which uses prebuild-install and can successfully be installed in this environment?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Jun 22, 2022
@Fiouz
Copy link
Author

Fiouz commented Jun 22, 2022

From what I can gather, we need the following branches to behave the same:

After some quick testing, it seems possible by combining a change on the project, and a change on the build machine:

  • We need to discard the {tag_prefix} (it is forcefully added when mirroring, but omitted with custom host), by changing
    "install": "prebuild-install -r napi || cmake-js build",
    into
    "install": "prebuild-install --tag-prefix= -r napi || cmake-js build",

If you previously used the npm config set realm_binary_host_mirror https://mirror.lan/realm, you now need to configure npm config set realm_binary_host https://mirror.lan/realm/realm-js-prebuilds (same mirror, additional suffix)

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jun 22, 2022
@tomduncalf
Copy link
Contributor

Thanks for the research @Fiouz! I've created a branch of Realm JS with the change you suggested, named td/binary-mirroring-test. Are you able to try this out to see if it works for you?

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Jun 23, 2022
@Fiouz
Copy link
Author

Fiouz commented Jun 23, 2022

Yes, it works thank you. As you may already feel, such setup looks janky, so I raised prebuild/prebuild-install#183 to have the point of view of prebuild-install maintainers.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Jun 23, 2022
@tomduncalf
Copy link
Contributor

OK great, I'll run this past the team to check they are happy with this change as I don't have much experience with this part of the build. If they are then we can merge it in

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label Jun 24, 2022
@tomduncalf
Copy link
Contributor

@Fiouz We have just released Realm JS 10.9.3 which should fix this issue, please let us know if you are still having problems.

@Fiouz
Copy link
Author

Fiouz commented Jun 29, 2022

Thank you @tomduncalf, it is indeed working with 10.19.3. Would you have a timeline for a > 10.20.0-beta.5 version?

@tomduncalf
Copy link
Contributor

We are actively working on getting a new beta release out now. We have some test failures we are investigating but hopefully we can resolve these soon. I can't commit to a timeline but we will get it out as soon as possible!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants