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

Spectral cli doesn't work in alpine docker image #1374

Closed
slamdev opened this issue Oct 4, 2020 · 3 comments
Closed

Spectral cli doesn't work in alpine docker image #1374

slamdev opened this issue Oct 4, 2020 · 3 comments
Labels
help wanted Extra attention is needed t/bug Something isn't working

Comments

@slamdev
Copy link

slamdev commented Oct 4, 2020

Describe the bug
spectral binary doesn't work in alpine docker image

To Reproduce

  1. Install spectral via install.sh script
  2. Run spectral --help
  3. See error

Expected behavior
Help info is displayed.

Additional context

$ docker run -ti alpine
$ apk add curl
$ curl -L https://raw.githack.com/stoplightio/spectral/master/scripts/install.sh | sh
Spectral was installed to: /usr/local/bin/spectral
$ spectral --help
/bin/sh: spectral: not found
$ ls -la /usr/local/bin/spectral
-rwxr-xr-x    1 root     root      57092527 Oct  4 22:12 /usr/local/bin/spectral
@slamdev slamdev added the t/bug Something isn't working label Oct 4, 2020
@drmmr763
Copy link

I'm also having this issue

@philsturgeon philsturgeon added the help wanted Extra attention is needed label Dec 31, 2020
@DenialAdams
Copy link

DenialAdams commented Feb 19, 2021

Hi, I ran into this issue this afternoon and investigated it a bit.

Alpine is a very lightweight linux distribution (as it's intended for use in Docker), and one of the ways that they achieve their lightweight status is by shipping with musl libc instead of the more ubiquitous glibc. However, the spectral-cli binary depends on glibc in order to run. You can see this by looking at the dynamic dependencies:

/usr/local/bin # ldd ./spectral
        /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
        libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
        librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fe49b907000)
        libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fe49b8ed000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fe49baa9000)
Error relocating ./spectral: gnu_get_libc_version: symbol not found
Error relocating ./spectral: __register_atfork: symbol not found
Error relocating ./spectral: __strdup: symbol not found
Error relocating ./spectral: setcontext: symbol not found
Error relocating ./spectral: makecontext: symbol not found
Error relocating ./spectral: backtrace: symbol not found
Error relocating ./spectral: getcontext: symbol not found

NOTE - I had to install "libgcc" and "libstdc++" by running:

apk add libstdc++
apk add libgcc

I believe that all of the remaining relocation errors are due to the missing glibc.

So, ideally we'd be able to build the spectral-cli without this dependency on glibc --- the good news is that I took a look at pkg (which is used to build the spectral-cli binary) and it seems like they have an alpine linux target! (which I believe would compile with musl and not require glibc)

https://www.npmjs.com/package/pkg

I'm thinking that we could update the CI configuration to also build the alpine linux binaries (leveraging the --targets flag of pkg), and then include those binaries when cutting a release. I'm not sure exactly what the next steps for that are, but I would love to see that happen so that embedding spectral in docker containers becomes easier!

Also want to note that even after this I think that installing libstdc++ and libgcc to your container will be necessary (see vercel/pkg#726), but that's at least very easy to do with the commands listed above.

@P0lip
Copy link
Contributor

P0lip commented May 11, 2021

We adjusted the process to include the alpine builds and they're attached to each new release now.

@P0lip P0lip closed this as completed May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants