tomnomnom / gron

Make JSON greppable!
MIT License
13.87k stars 328 forks source link

Binary builds broken?? #94

Open bradwood opened 2 years ago

bradwood commented 2 years ago

I think the binaries for Linux x86 are broken:

bash-5.0# curl -LO https://github.com/tomnomnom/gron/releases/download/v0.6.0/gron-linux-amd64-0.6.0.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   661  100   661    0     0   3998      0 --:--:-- --:--:-- --:--:--  4006
100 2438k  100 2438k    0     0  4853k      0 --:--:-- --:--:-- --:--:-- 18.4M
bash-5.0# tar zxvf gron-linux-amd64-0.6.0.tgz
gron
bash-5.0# ./gron
bash: ./gron: No such file or directory
bash-5.0#
bash-5.0#
bash-5.0#
bash-5.0# uname -a
Linux a6b910ef5e59 5.11.0-1028-aws #31~20.04.1-Ubuntu SMP Fri Jan 14 14:37:50 UTC 2022 x86_64 Linux
bash-5.0#

Or am I doing something stupid?

bradwood commented 2 years ago

i386 build works fine, btw.

jfrancin commented 2 years ago

works for me:

ryzen1> curl -LO https://github.com/tomnomnom/gron/releases/download/v0.6.0/gron-linux-amd64-0.6.0.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   661  100   661    0     0    126      0  0:00:05  0:00:05 --:--:--   151
100 2438k  100 2438k    0     0   231k      0  0:00:10  0:00:10 --:--:--  524k
ryzen1> ls
gron-linux-amd64-0.6.0.tgz
ryzen1> tar -xzf gron-linux-amd64-0.6.0.tgz 
ryzen1> ls -lsa
total 9240
   0 drwxrwxr-x.  2 jfrancin jfrancin      52 Feb 21 12:27 .
   4 drwx-----x. 39 jfrancin jfrancin    4096 Feb 21 12:27 ..
6796 -rwxrwxr-x.  1 jfrancin jfrancin 6957332 Jul  5  2018 gron
2440 -rw-rw-r--.  1 jfrancin jfrancin 2496601 Feb 21 12:27 gron-linux-amd64-0.6.0.tgz
ryzen1> file gron
gron: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, with debug_info, not stripped
ryzen1> ./gron --help
Transform JSON (from a file, URL, or stdin) into discrete assignments to make it greppable

Usage:
  gron [OPTIONS] [FILE|URL|-]

Options:
  -u, --ungron     Reverse the operation (turn assignments back into JSON)
  -c, --colorize   Colorize output (default on tty)
  -m, --monochrome Monochrome (don't colorize output)
  -s, --stream     Treat each line of input as a separate JSON object
  -k, --insecure   Disable certificate validation
  -j, --json       Represent gron data as JSON stream
      --no-sort    Don't sort output (faster)
      --version    Print version information

Exit Codes:
  0 OK
  1 Failed to open file
  2 Failed to read input
  3 Failed to form statements
  4 Failed to fetch URL
  5 Failed to parse statements
  6 Failed to encode JSON

Examples:
  gron /tmp/apiresponse.json
  gron http://jsonplaceholder.typicode.com/users/1 
  curl -s http://jsonplaceholder.typicode.com/users/1 | gron
  gron http://jsonplaceholder.typicode.com/users/1 | grep company | gron --ungron
ryzen1> uname -a
Linux ryzen1.narfnet.com 4.18.0-348.12.2.el8_5.x86_64 #1 SMP Mon Jan 17 07:06:06 EST 2022 x86_64 x86_64 x86_64 GNU/Linux
ryzen1> cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.5 (Ootpa)
bradwood commented 2 years ago

weird. this is in an alpine container, maybe it's that, but golang is zero deps, so will have to look a bit more... cheers...

dotcs commented 2 years ago

Indeed this seems to be the case. This line reproduces the error:

$ docker run --rm -it alpine sh -c "apk add curl; curl -LO https://github.com/tomnomnom/gron/releases/download/v0.6.0/gron-linux-amd64-0.6.0.tgz; tar zxvf gron-linux-amd64-0.6.0.tgz; ./gron --help"
sh: ./gron: not found

I'm not a golang pro but it might be the case that the net package is responsible for this as mentioned in this stackoverflow answer. The net package is imported here, so gron might be affected by this.

A possible fix is to install the libc6-compat package and start gron with the env variables CGO_ENABLED=1 GOOS=linux:

$ docker run --rm -it alpine sh -c "apk add curl libc6-compat; curl -LO https://github.com/tomnomnom/gron/releases/download/v0.6.0/gron-linux-amd64-0.6.0.tgz; tar zxvf gron-linux-amd64-0.6.0.tgz; CGO_ENABLED=1 GOOS=linux ./gron --help"
Transform JSON (from a file, URL, or stdin) into discrete assignments to make it greppable
...

With this trick even the network I/O works without problems in my case:

$ docker run --rm -it alpine sh -c "apk add curl libc6-compat; curl -LO https://github.com/tomnomnom/gron/releases/download/v0.6.0/gron-linux-amd64-0.6.0.tgz; tar zxvf gron-linux-amd64-0.6.0.tgz; CGO_ENABLED=1 GOOS=linux ./gron https://api.github.com/users"
json = [];
json[0] = {};
json[0].avatar_url = "https://avatars.githubusercontent.com/u/1?v=4";
...

Hope this helps.