crystal-lang / distribution-scripts

40 stars 24 forks source link

crystal:0.36.1-alpine missing yaml-static #84

Closed kimburgess closed 2 years ago

kimburgess commented 3 years ago

A new Alpine image for 0.36.1 made it's way to docker hub last night. This is unable to statically compile crystal programs that use YAML.

Reduced example: https://gist.github.com/kimburgess/2a740af0f2c8bc5b217a9fa47638df0e.

~Cause appears to be https://github.com/crystal-lang/distribution-scripts/commit/bdff883a42e007acac17549b4d44ba8a3dc83264~

Build output:

Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM crystallang/crystal@sha256:ee97e1ef8b609cd80a8d504fdf8c5c09f7ac2fc520d360a7b10c8d50aa21f4b2
 ---> 32474966bd9f
Step 2/3 : COPY . .
 ---> 7e65d2efd8e7
Step 3/3 : RUN crystal build --static --error-trace yaml.cr
 ---> Running in cffb373d5aed
/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lyaml (this usually means you need to install the development package for libyaml)
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /yaml  -rdynamic -static -L/usr/bin/../lib/crystal/lib -lyaml  -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt`
The command '/bin/sh -c crystal build --static --error-trace yaml.cr' returned a non-zero code: 1
straight-shoota commented 3 years ago

Hm, the new images should be based on alpine 3.12 and not include that commit.

ref https://github.com/crystal-lang/crystal/issues/10366#issuecomment-799472500

Blacksmoke16 commented 3 years ago

Related?: https://github.com/crystal-lang/distribution-scripts/pull/63#issuecomment-718353007.

bcardiff commented 3 years ago

libyaml it's not missing. In that docker image you can see that

# pkg-config yaml-0.1 --libs
-lyaml 

But the static libyaml is not there which seems to be what you want.

# apk add --update yaml-static

After that your program will link with --static.

The 3.13 image does have yaml-static, but that was a new addition.

maiha commented 3 years ago

In the current image, it seems the repository is still 3.12. Is this the cause?

$ docker run --rm -it crystallang/crystal:0.36.1-alpine cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/v3.12/main
http://dl-cdn.alpinelinux.org/alpine/v3.12/community

$ docker images | grep 0.36.1-alpine
crystallang/crystal            0.36.1-alpine         32474966bd9f   3 days ago      314MB
bcardiff commented 3 years ago

@maiha the images were reverted to 3.12 for the CI as explained in https://github.com/crystal-lang/crystal/issues/10366#issuecomment-799472500 . The issue on that image the lack of yaml-static which I think is optional and as any library can be tweaked by the user.

kimburgess commented 3 years ago

Easy enough to workaround downstream for now. Given it was available previously and is needed running a static build using only std lib components, is it worth reintroducing it to the 3.12 based image?

straight-shoota commented 2 years ago

Closing. The latest docker images all contain yaml-static.