haskell/docker-haskell

docker-haskell micro?

PiotrJustyna opened this issue Β· 3 comments

Hello and first of all great work on the project πŸ‘ πŸ‘ πŸ‘

I've been using something like this, just very slimmed down and without stack myself for a while and thought I would leave it here in case people are interested. Works great for my purposes and could be a great starting place for Haskell/GHC/Cabal newbies.

FROM alpine:3.20.2

WORKDIR "/root/code/drakon-renderer"

RUN \
  apk update \
  && \
  apk add \
    zsh \
    git \
    openssh \
    curl \
    zlib-dev \
    g++ \
    ghc \
    cabal \
    ncurses-dev \
  && \
  git config --global --add safe.directory "/root/code/drakon-renderer" \
  && \
  cabal update \
  && \
  cabal install hlint hindent \
  && \
  echo "PROMPT='%F{cyan}%n%f %F{magenta}%~%f $ '" >> ~/.zshrc

# 2024-12-02 PJ:
# --------------
# this is where executables
# installed with cabal install are located
ENV PATH="${PATH}:/root/.local/bin"

CMD [ "/bin/zsh" ]
#!/bin/sh

# 2024-12-04 PJ:
# --------------
# At the time of writing this, these directories are covered here:
# https://cabal.readthedocs.io/en/latest/config.html#directories
# Mounting them as volumes allows us to reuse cabal files
# between containers saving a significant amount of build time.
docker volume create cabal-config
docker volume create cabal-cache
docker volume create cabal-state

docker buildx build \
  -t "drakon-renderer:latest" \
  -f "dockerfile" \
  . \
&& \
docker run \
  -it \
  -v "$HOME/.ssh/:/root/.ssh:ro" \
  -v "$(pwd):/root/code/drakon-renderer" \
  -v cabal-config:/root/.config/cabal \
  -v cabal-cache:/root/.cache/cabal \
  -v cabal-state:/root/.local/state/cabal \
  --rm "drakon-renderer:latest"

My local development setup is pretty simple:

  • vs code
  • shell

Here is a sample project I use it with: https://github.com/PiotrJustyna/drakon-renderer

There is also GHC musl – Unofficial binary distributions of GHC on Alpine Linux:

  1. Multi‑arch: linux/amd64, linux/arm64/v8
  2. Built using Hadrian1, from source, without docs
  3. Built using the LLVM backend
    • flavour: perf+llvm+split_sections

Including Dev Containers providing the following tools:

Footnotes

  1. GHC versions β‰₯ 9.2.8. ↩

That is very cool, thanks for sharing @benz0li. I wouldn't want the issue to brew for too long and to elevate the current issue number, but hoping somebody finds it useful!

I don't mind the issue laying around open BTW