-
-
Save hasufell/f0893abfbba63ac4ea40feb0520946ee to your computer and use it in GitHub Desktop.
FROM alpine:3.11 as hs | |
# install ghc and stack | |
RUN \ | |
apk add --no-cache git curl gcc g++ gmp-dev ncurses-dev libffi-dev make xz tar perl && \ | |
apk add --no-cache zlib zlib-dev zlib-static ncurses-static && \ | |
curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > /usr/bin/ghcup && \ | |
chmod +x /usr/bin/ghcup && \ | |
ghcup install ghc 8.6.5 && \ | |
ghcup set ghc 8.6.5 && \ | |
ghcup install stack | |
# install haskell-code-explorer | |
RUN \ | |
git clone https://github.com/alexwl/haskell-code-explorer.git ~/haskell-code-explorer && \ | |
cd ~/haskell-code-explorer && \ | |
export PATH="/root/.ghcup/bin:$PATH" && \ | |
stack --system-ghc --stack-yaml=stack-8.6.5.yaml install --ghc-options='-optl-static -split-sections' --copy-bins | |
FROM ubuntu:bionic | |
RUN \ | |
apt-get update && \ | |
apt-get -y upgrade && \ | |
apt-get install -y software-properties-common && \ | |
apt-get install -y curl git wget nano && \ | |
apt-get install -y build-essential pkg-config curl libffi-dev libffi6 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5 && \ | |
apt-get install -y libsodium-dev sqlite zlib1g-dev libssl-dev && \ | |
rm -rf /var/lib/apt/lists/* | |
COPY --from=hs /usr/bin/stack /usr/bin/stack | |
COPY --from=hs /usr/bin/ghcup /usr/bin/ghcup | |
COPY --from=hs /root/.local/bin/haskell-code-server /usr/bin/haskell-code-server | |
COPY --from=hs /root/.local/bin/haskell-code-indexer /usr/bin/haskell-code-indexer | |
Hi, @hasufell!👋 Could you kindly briefly explain me
--ghc-options=
on line 18?I am currently compiling a Haskell project in a container with the command
stack setup && stack install
, with no options. But I get a bunch of problems when I copy the binary to another container, especially if it is based on another OS (RHEL based), similar to your case. How can I copy the binary so that it can be executed on its own? Do I still need to have all the perl, ssl, etc. deps like on line 28?
ghc-options cause the binary to be linked statically. Then you can copy anywhere. For that to work you need to use alpine container though (or some other musl based one).
I see. I ended up doing just stack --system-ghc install --copy-bins
without the --ghc-options
flag. I think it solved the issue I was having with the built binary not working in another container based on another OS. Anyways, this example was helpful, especially the ghcup install part! Thanks.
Hi, @hasufell!:wave: Could you kindly briefly explain me
--ghc-options=
on line 18?I am currently compiling a Haskell project in a container with the command
stack setup && stack install
, with no options. But I get a bunch of problems when I copy the binary to another container, especially if it is based on another OS (RHEL based), similar to your case. How can I copy the binary so that it can be executed on its own? Do I still need to have all the perl, ssl, etc. deps like on line 28?