84codes/crystal-container-images

Add `xz-static` to alpine image

Closed this issue · 5 comments

Required e.g. for static builds using libxml2-static.

Added pull request #16

Can you explain how/why xz-static is required?

Okay, https://forum.crystal-lang.org/t/static-linking-with-libxml2/1421 says "Alpine has added xz as a dependency of libxml2"

apk add does not install dependencies?

apk add does not install dependencies?

Not xz-static, but xz-libs

/ # apk add libxml2-static
(1/18) Installing libbz2 (1.0.8-r6)
(2/18) Installing libexpat (2.6.0-r0)
(3/18) Installing libffi (3.4.4-r3)
(4/18) Installing gdbm (1.23-r1)
(5/18) Installing xz-libs (5.4.5-r0)
(6/18) Installing libgcc (13.2.1_git20231014-r0)
(7/18) Installing libstdc++ (13.2.1_git20231014-r0)
(8/18) Installing mpdecimal (2.5.1-r2)
(9/18) Installing ncurses-terminfo-base (6.4_p20231125-r0)
(10/18) Installing libncursesw (6.4_p20231125-r0)
(11/18) Installing libpanelw (6.4_p20231125-r0)
(12/18) Installing readline (8.2.1-r2)
(13/18) Installing sqlite-libs (3.44.2-r0)
(14/18) Installing python3 (3.11.6-r1)
(15/18) Installing python3-pycache-pyc0 (3.11.6-r1)
(16/18) Installing pyc (3.11.6-r1)
(17/18) Installing python3-pyc (3.11.6-r1)
(18/18) Installing libxml2-static (2.11.7-r0)
Executing busybox-1.36.1-r15.trigger
OK: 66 MiB in 34 packages

Feel free to explain more how this works, not sure I fully understand what you mean with a "static build using libxml2-static" and why having xz-static installed makes it work. :)

For an example, see the following Dockerfile:

FROM 84codes/crystal:1.11.2-alpine
ARG xz=0
WORKDIR /test
RUN printf "require \"xml\"\nXML.parse_html(\"<html></html>\")" >test.cr
RUN if [ "${xz}" -eq "1" ]; then apk add xz-static; fi
RUN crystal build --static test.cr

When running docker build --build-arg xz=0 . (=without xz-static), the build fails, when running docker build --build-arg xz=1 . (=with xz-static), the build succeeds.