volta
volta copied to clipboard
Support Alpine Linux
Hello 👋
I'm looking to contribute support for Alpine Linux to Volta. I've cloned the repository into a Docker container running Alpine, and I installed Rust onto that container. I then ran cargo build --release, but this fails with the following error:
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: could not compile `libc` due to previous error
I would like to ask for some expertise on what would be a good approach to building Volta for MUSL-based systems, when Volta depends on libc?
Volta only depends on libc transitively through the Rust compiler. I haven't tried it myself, but I suspect the first step would be to use one of the -musl build targets for Rust: https://doc.rust-lang.org/rustc/platform-support.html
I anticipate that won't be it, however. Alpine is very stripped down, so for instance OpenSSL may not be available either.
This is actually pretty easy. See https://github.com/ellie/atuin/pull/404#issuecomment-1125941524 for a better explanation.
In short, you need to tell cargo to use OpenSSL from Alpine, so set OPENSSL_NO_VENDOR=1 and have gcc and openssl-dev installed. Then run cargo install ... like usual.
I was able to get volta to compile in an alpine linux container. Using the instructions above
To see this work run:
docker run --rm -it frolvlad/alpine-glibc:latest bash -c 'apk update && apk add git rust cargo openssl-dev bash ca-certificates && git clone https://github.com/volta-cli/volta.git --depth=1 && cd volta && OPENSSL_NO_VENDOR=1 cargo build --release && /volta/target/release/volta install node@latest'
What is not working though is actually running node on alpine. After looking into how the docker node alpine image is built I found https://github.com/nodejs/docker-node/blob/c87ff785fe4be8271b95d03e6c226d07d79df003/16/alpine3.16/Dockerfile#L21 docker-node is pulling in a node version that is built against musl which can then run on alpine.
So ideally to get this working all that we should need is a new alpine build target for volta and a way to have volta be aware of where it is running and choose to pull in that alpine compatible version of node!