Bug 279519

Summary: [NEW PORT] databases/mongosh: mongodb official Shell CLI
Product: Ports & Packages Reporter: Fabien Amelinck <fabienamelinck>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed FIXED    
Severity: Affects Many People CC: a.shikov, beppo, diizzy, einar, fabienamelinck, ronald, samm
Priority: ---    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
New port patch
none
Updated patch
none
patch for 2.2.5 none

Description Fabien Amelinck 2024-06-04 14:31:54 UTC
Created attachment 251215 [details]
New port patch

As mentionned on the forum : https://forums.freebsd.org/threads/mongodb-7-0-mongo-shell-mongosh-is-missing.90658/

Mongo shell has been deprecated and isn't packaged anymore.
I have created a new port to build the actually supported mongosh based on NodeJS.

It builds a standalone version of mongosh and provide only the binary file without the need of NodeJS after installation.

ETB is approximatly 25 minutes with 10 cpus and 128 GB of ram.
Comment 1 Ronald Klop freebsd_committer freebsd_triage 2024-06-25 09:52:08 UTC
Doing a test build on FreeBSD 14/aarch64.
Comment 2 Ronald Klop freebsd_committer freebsd_triage 2024-06-25 10:04:03 UTC
(In reply to Ronald Klop from comment #1)
Got an error.

post-patch is trying to access the network
"
[00:00:50] ===>  Applying FreeBSD patches for mongosh-2.2.5 from /usr/ports/databases/mongosh/files
[00:00:51] cd /wrkdirs/usr/ports/databases/mongosh/work/mongosh-2.2.5 && npx cross-env PUPPETEER_SKIP_DOWNLOAD=1 npm install
[00:02:03] npm error code EAI_FAIL
[00:02:03] npm error syscall getaddrinfo
"

After the fetch phase you cannot access network on the package building cluster. Use poudriere you can test this scenario yourself.
Some info about poudriere is for example: https://wiki.freebsd.org/VladimirKrstulja/Guides/Poudriere

Full build log:
https://june24:T0nB$jEKu@jail14.thuis.klop.ws/data/freebsd14-custom/2024-06-25_09h52m00s/logs/mongosh-2.2.5.log
Comment 3 Fabien Amelinck 2024-06-27 11:41:19 UTC
(In reply to Ronald Klop from comment #2)

Thank you for taking the time to review my port submission.

I actually know, that's why I have ALLOW_NETWORKING_PACKAGES="mongosh" in poudriere.conf.

What do you suggest ?
A repo with the node_modules populated or an ugly "npm install" at fetch step ?

I didn't find how electron and vscode are managing this constraint.
Comment 4 Ronald Klop freebsd_committer freebsd_triage 2024-06-29 05:07:50 UTC
(In reply to Fabien Amelinck from comment #3)
I don’t have experience building a npm based port. So asked your question at ports@freebsd.org. This was an answer on the list by Hiroo Ono. Maybe it helps.

Hi,

Not a committed port, so I do not know if it is the right solution.
I managed to limit the networking in fetch phase in the port below:

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272180

in short, I took the following steps

in fetch phase,
1. HOME=${WRKDIR} npm install --ignore-scripts
2. backup ${WRKDIR}/.npm under ${DISTDIR}

in extract phase
3. extract backup .npm under ${WRKDIR}

in build phase
4. HOME=${WRKDIR} npm install --offline

Another solution is electron port.
When I looked into in (around version 22), it archived yarn cache
somewhere and fetched it.
Comment 5 Ronald Klop freebsd_committer freebsd_triage 2024-11-02 11:03:05 UTC
Hi,

Is this port issue still being worked on?
AFAIS the only problem was downloading files after the fetch phase. So the official package builders will not be able to build a pkg for it.

I don't know if it is "allowed"/preferred to add a port with an IGNORE="needs download after fetch phase" to get the port into the tree without generating pkgs.
Comment 6 Daniel Engberg freebsd_committer freebsd_triage 2024-11-03 09:26:06 UTC
(In reply to Ronald Klop from comment #5)
No, that would be an invalid/broken port and not to be committed.
Comment 7 Ronald Klop freebsd_committer freebsd_triage 2024-11-04 15:54:11 UTC
(In reply to Daniel Engberg from comment #6)
Thank for the feedback Daniel.
I'll wait another week for feedback of the reporter and than close the issue as "Not Accepted" with a small description to it. We can always re-open it if new development occurs in the future.
Comment 8 Fabien Amelinck 2024-11-05 15:45:02 UTC
(In reply to Ronald Klop from comment #7)

It's a bit tricky to handle node's packages (~1600) because some are downloaded during the build phase.
I tried to add it one by one in the package.json but it's a mess.
The best solution is to make an archive host on my github as "vscode" port do but it's also very ugly.

Still in WIP.
Comment 9 Fabien Amelinck 2024-11-15 16:55:49 UTC
(In reply to Fabien Amelinck from comment #8)

I finally got it working with a cache tarball hosted on github.
I haven't tried on an aarch64, feel free to try and get back to me if you need any details or changes.
Comment 10 Fabien Amelinck 2024-11-15 18:30:12 UTC
Created attachment 255203 [details]
Updated patch
Comment 11 Ronald Klop freebsd_committer freebsd_triage 2024-11-16 06:49:40 UTC
(In reply to Fabien Amelinck from comment #10)
Nice work!
I tested it and got a fetch error. Does this ring a bell?

https://nov24:lgxSrhwY1iGLnZUc0Vls5@pkg.thuis.klop.ws/build.html?mastername=freebsd141-custom&build=2024-11-15_20h22m08s
Comment 12 Fabien Amelinck 2024-11-16 16:34:39 UTC
(In reply to Ronald Klop from comment #11)
My bad, I changed the node_modules tarball's name to include mongosh version.
I'm working on the 2.3.3 now but I want the 2.2.5 to come out first to be sure because we already use it now in production.
Comment 13 Fabien Amelinck 2024-11-16 16:36:10 UTC
Created attachment 255218 [details]
patch for 2.2.5
Comment 14 commit-hook freebsd_committer freebsd_triage 2024-11-21 08:53:45 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=31d8a7eb3429202e96349c29c0bb240395989ec8

commit 31d8a7eb3429202e96349c29c0bb240395989ec8
Author:     Fabien Amelinck <fabien.amelinck@advens.fr>
AuthorDate: 2024-11-21 07:52:25 +0000
Commit:     Ronald Klop <ronald@FreeBSD.org>
CommitDate: 2024-11-21 08:52:59 +0000

    databases/mongosh: new port

    Standalone MongoDB Shell replacing deprecated Mongo CLI.
    NodeJS doesn't need to be installed.

    PR:     279519

 databases/Makefile                                 |   1 +
 databases/mongosh/Makefile (new)                   | 146 +++++++++++++++++++++
 databases/mongosh/distinfo (new)                   |  11 ++
 .../patch-node__modules_kerberos_binding.gyp (new) |  32 +++++
 ...__modules_kerberos_src_kerberos__common.h (new) |  11 ++
 ...les_mongodb-client-encryption_binding.gyp (new) |  35 +++++
 ...es_mongodb-client-encryption_package.json (new) |  11 ++
 ...h-node__modules_os-dns-native_binding.gyp (new) |  13 ++
 .../mongosh/files/node-patches/004-openssl3 (new)  |  15 +++
 .../files/node-patches/005-src_cares__wrap.h (new) |  11 ++
 databases/mongosh/files/patch-package.json (new)   |  36 +++++
 ...ejs-patches_002-workaround-node-bug-52229 (new) |  17 +++
 .../files/patch-scripts_prep-fle-addon.sh (new)    |  20 +++
 .../files/patch-scripts_sort-workspaces.js (new)   |  11 ++
 databases/mongosh/pkg-descr (new)                  |   5 +
 databases/mongosh/pkg-plist (new)                  |   1 +
 16 files changed, 376 insertions(+)
Comment 15 Ronald Klop freebsd_committer freebsd_triage 2024-11-21 10:58:30 UTC
Thanks for all the effort in making this a proper port.

I noticed some small cleanup things for the port but will make follow-up issues for that.
Comment 16 Oleksii Samorukov freebsd_committer freebsd_triage 2024-11-21 11:44:51 UTC
seems to be broken on aarch64 at least

> compile-cli
> lerna run compile --scope @mongosh/cli-repl --include-dependencies

/wrkdirs/usr/ports/databases/mongosh/work/mongosh-2.2.5/node_modules/lerna/node_modules/nx/src/native/index.js:147
      throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
      ^

Error: Unsupported architecture on FreeBSD: arm64
    at Object.<anonymous> (/wrkdirs/usr/ports/databases/mongosh/work/mongosh-2.2.5/node_modules/lerna/node_modules/nx/src/native/index.js:147:13)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/wrkdirs/usr/ports/databases/mongosh/work/mongosh-2.2.5/node_modules/lerna/node_modules/nx/src/project-graph/utils/retrieve-workspace-files.js:9:18)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)

Node.js v20.18.0
*** Error code 1