#!/bin/sh # Usage: ./docker.sh # # Example: ./docker.sh #< build all images namespace="registry.gitlab.com/dxld/cabal-helper/ci" tmpdir=$(mktemp -p "${TMPDIR:-/tmp/}" -d cabal-helper-docker-XXXX) || exit 1 dldir="/tmp/cabal-helper-docker-dl" GHC_BASE=https://downloads.haskell.org/~ghc HACKAGE_BASE=https://hackage.haskell.org/package STACK_BASE=https://github.com/commercialhaskell/stack/releases/download image=debian:buster cabal=3.0.0.0 stack=2.1.3 stack_url="${STACK_BASE}/v${stack}/stack-${stack}-linux-x86_64-static.tar.gz" stack_file="$(basename "$stack_url")" mkdir -p "$dldir" cat >"$tmpdir"/ghc_table <> "$tmpdir"/ghcs } | tee "$tmpdir"/ghc-urls | xargs -n1 -P$(nproc) sh -ue -c ' cd "$1" wget -nv -nc -c "$3" cp "$(basename "$3")" "$2" ' urldl "$dldir" "$tmpdir" ghc_files="" for url in $(cat "$tmpdir"/ghc-urls); do ghc_files=""$(basename "$url")" $ghc_files" done cat > "$tmpdir"/install-ghc.sh <<"EOF" $!/bin/sh set -eux ghc=$1; shift tar -xf ghc-${ghc}-*.tar.xz cd ghc-${ghc} ./configure --prefix=/usr/local/ghc-${ghc} make install ln -s /usr/local/ghc-${ghc}/bin/*-${ghc} /usr/local/bin for f in /usr/local/ghc-${ghc}/bin/*-${ghc}; do ln -s "$f" /usr/local/bin/"$(basename "${f%.*}")" done cd .. EOF cat > "$tmpdir"/Dockerfile </dev/null RUN cat ghcs | xargs -P$(nproc) -n1 sh install-ghc.sh RUN cabal update && \ cabal install cabal-install-${cabal} --ghc-option=-j && \ cp -L ~/.cabal/bin/cabal /usr/local/bin FROM base COPY --from=build /usr/local/ /usr/local/ EOF tag="${namespace}:ghc-$(printf '%s' "$(cat "$tmpdir"/ghcs)" | tr ' ' '-')--cabal-install-${cabal}--stack-${stack}" docker build -t "$tag" "$tmpdir" for ghc in $(cat "$tmpdir"/ghcs); do stag="${namespace}:ghc-${ghc}--cabal-install-${cabal}--stack-${stack}" printf '%s\n' \ "FROM $tag" \ 'ENV PATH="/usr/local/ghc-'"${ghc}"'/bin:${PATH}"' \ | docker build -t "$stag" - done