Closed ouven closed 2 years ago
Unfortunately dart-sass will not run on Alpine Linux because it requires glibc.
You may be able to install a sass binary via apk and copy/symlink it to _build/sass, but there isn't anything more we can do on this end. Thanks!
I had the same problem and after some research I could get it working by adding this alpine package: https://github.com/sgerrand/alpine-pkg-glibc#installing
...
# add glibc in order to use dart-sass
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk
RUN apk add glibc-2.34-r0.apk
# build assets
COPY assets assets
COPY config config
RUN mix assets.deploy
...
And... It works 🥳
@philipgiuliani Awesome, thanks for the report! Given the popularity around Alpine for CI, I think it would be great to call this out in the README. Would you like to send a PR? :)
@philipgiuliani -> Hero
I still had some issues with the linker, which I had to solve by calling ldconfig. See the contents (the start) of my Dockerfile, that make it work:
FROM hexpm/elixir:1.12.3-erlang-24.1.1-alpine-3.14.0 as build
# add glibc in order to use dart-sass
ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.34-r0
RUN apk add --update --no-cache npm make g++ git ca-certificates
RUN update-ca-certificates --fresh
RUN apk --update add libstdc++ curl ca-certificates && \
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk
RUN mix local.hex --force
RUN mix local.rebar --force
# ...
Interesting, which error did you get? So we can document this in #14 . I only had the error ../../runtime/bin/eventhandler_linux.cc: 412: error: Failed to start event handler thread 1
when building on my CI (not on my Mac) which could be resolved by downgrading glibc to 2.33 (see details in #14)
Ran into this as well, and unfortunately didn't find this discussion, because the ticket is closed. I should have looked better!
Since my Docker build is multi stage, I decided to just install npm and use the Javascript version of DartSass instead:
- RUN apk add --no-cache build-base
+ RUN apk add --no-cache build-base npm
+ # Install Dart Sass
+ RUN npm install -g sass
[...]
+ # build Sass -> CSS
+ RUN cd assets && \
+ sass --no-source-map --style=compressed css/app.scss ../priv/static/assets/app.css
# build assets
RUN mix assets.deploy
[...]
where mix.exs assets.deploy is:
defp aliases do
[...]
"assets.deploy": [
"esbuild default --minify",
"phx.digest"
]
end
Pros:
I think this is good enough for me.
Interesting, which error did you get? So we can document this in #14 . I only had the error
../../runtime/bin/eventhandler_linux.cc: 412: error: Failed to start event handler thread 1
when building on my CI (not on my Mac) which could be resolved by downgrading glibc to 2.33 (see details in #14)
Sorry, I was not able to reproduce 🤔
Hi, thank you for this piece of work!
I tried to use the mix task in my build pipeline (upon
hexpm/elixir:1.12.3-erlang-24.1.1-alpine-3.14.0
). Unfortunatly it fails because of some lib bindings.