Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
scripts: docker: Include stack binary in image
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielG committed Jun 17, 2019
1 parent c1a5e67 commit 391e187
Showing 1 changed file with 81 additions and 21 deletions.
102 changes: 81 additions & 21 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,86 @@
#!/bin/sh

# Usage: ./docker.sh [GHC_VER]
# Example: ./docker.sh 8.2.2
# Usage: ./docker.sh [GHC_VER...]
#
# Example: ./docker.sh #< build all images
#
# Example: ./docker.sh 8.2.2 #< build just 8.2.2 image
#
# Faster Example:
# $ echo 8.6.3 8.4.4 8.2.2 8.0.2 7.10.3 | xargs -P4 -n1 -- ./docker.sh

# $ SWAP=1 ./docker.sh tmux 8.6.5 8.4.4 8.2.2 8.0.2 7.10.3
#
# tmux cheatsheet:
# quit: Ctrl-b & y
# other-window: Ctrl-b o
# scroll: Ctrl-b [

if [ -n "$SWAP" ] && ! [ -e /tmp/swap ]; then
# We run out of memory with 5 concurrent builds on the Vultr 4 core
# instance.
swapoff /tmp/swap || true
dd if=/dev/zero of=/tmp/swap bs=4k count=4M # 16GiB
chmod 0600 /tmp/swap
mkswap /tmp/swap
swapon /tmp/swap
fi

if [ "$1" = tmux ]; then
shift
tmux kill-session -t docker || true
exec tmux new -s docker sh -x "$0" do-tmux "$@"
elif [ "$1" = do-tmux ]; then
shift
myghc=$1; shift

tmux set-option remain-on-exit on

for ghc in "$@"; do
tmux split-window sh -c "$0 $ghc 2>&1 | tee $ghc.log"
done

tmux select-layout even-vertical

set -- $myghc
fi

namespace="registry.gitlab.com/dxld/ghc-mod"
target="$1"

tmpdir=$(mktemp -p "${TMPDIR:-/tmp/}" -d ghc-mod-docker-XXXX) || exit 1
[ -z "$DEBUG" ] && trap 'rm -r '"$tmpdir" 0 2 15
if [ -z "$DEBUG" ]; then
trap 'echo This is $ghc signing off>&2; rm -r '"$tmpdir" 0 2 15
fi

dldir="/tmp/ghc-mod-docker-dl"

while read -r ghc_rel ghc ghc_arch ghc_ext cabal cabal_rev image; do
[ -n "$target" ] && [ x"$ghc_rel" != x"$target" ] && continue
GHC_BASE=https://downloads.haskell.org/~ghc
HACKAGE_BASE=https://hackage.haskell.org/package
STACK_BASE=https://github.com/commercialhaskell/stack/releases/download

while read -r ghc ghc_arch ghc_ext cabal cabal_rev stack image; do
if [ $# -eq 0 ]; then cont=false; else cont=true; fi
for target in "$@"; do
if [ x"$ghc" = x"$target" ]; then cont=false; fi
done
if $cont; then continue; fi

ghc_url="https://downloads.haskell.org/~ghc/${ghc_rel}/ghc-${ghc}-${ghc_arch}.tar.${ghc_ext}"
cabal_url="https://hackage.haskell.org/package/cabal-install-${cabal}/cabal-install-${cabal}.tar.gz"
cabal_meta_url="https://hackage.haskell.org/package/cabal-install-${cabal}/revision/${cabal_rev}.cabal"
ghc_url="${GHC_BASE}/${ghc}/ghc-${ghc}-${ghc_arch}.tar.${ghc_ext}"

cabal_base="${HACKAGE_BASE}/cabal-install-${cabal}"
cabal_url="${cabal_base}/cabal-install-${cabal}.tar.gz"
cabal_meta_url="${cabal_base}/revision/${cabal_rev}.cabal"

stack_url="${STACK_BASE}/v${stack}/stack-${stack}-linux-x86_64-static.tar.gz"
ghc_file="$(basename "$ghc_url")"
cabal_file="$(basename "$cabal_url")"
cabal_meta_file=cabal-install-"${cabal}"-"${cabal_rev}".cabal
stack_file="$(basename "$stack_url")"

ADDITIONAL_PACKAGES=""
ADDITIONAL_PURGE_PACKAGES=""
ADDITIONAL_COMMANDS=""
ADDITIONAL_BOOTSTRAP_SETUP="true"
ADDITIONAL_BOOTSTRAP_TEARDOWN="true"

if [ $ghc_rel = "7.10.3" ]; then
if [ $ghc = "7.10.3" ]; then
cabal_boot=2.2.0.0
cabal_bin_url="https://www.haskell.org/cabal/release/cabal-install-${cabal_boot}/cabal-install-${cabal_boot}-x86_64-unknown-linux.tar.gz"
cabal_bin_file="$(basename "$cabal_bin_url")"
Expand All @@ -49,11 +98,12 @@ while read -r ghc_rel ghc ghc_arch ghc_ext cabal cabal_rev image; do
if [ ! -e "$dldir"/"${cabal_meta_file}" ]; then
wget -nv "$cabal_meta_url" -O "$dldir"/"${cabal_meta_file}"
fi && cp -l "$dldir"/"${cabal_meta_file}" "$tmpdir"
wget -nv -nc -c "$stack_url" && cp -l "$stack_file" "$tmpdir"

ls -l "$tmpdir"
cd "$d" || exit 1

ADDITIONAL_COMMANDS="${ADDITIONAL_COMMANDS}COPY $ghc_file $cabal_file $cabal_bin_file $cabal_meta_file /root/
ADDITIONAL_COMMANDS="${ADDITIONAL_COMMANDS}COPY $ghc_file $cabal_file $cabal_bin_file $cabal_meta_file $stack_file /root/
"

cat > "$tmpdir"/Dockerfile <<EOF
Expand All @@ -66,6 +116,11 @@ WORKDIR /root
$ADDITIONAL_COMMANDS
RUN ( cd /usr/local/bin && \
tar -xvf /root/${stack_file} \
--strip-components 1 --wildcards '*/stack' && \
cd && stack --help >/dev/null \
)
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
alex happy wget git xz-utils gpgv ca-certificates build-essential libgmp3-dev libtinfo-dev zlib1g-dev netbase pkg-config $ADDITIONAL_PACKAGES && \
Expand All @@ -86,15 +141,20 @@ RUN tar -xf cabal-install-${cabal}.tar.* && \
rm -r cabal-*
EOF

docker build -t "${namespace}:ghc${ghc}-cabal-install${cabal}" "$tmpdir"
docker build -t "${namespace}:ghc${ghc}-cabal-install${cabal}-stack${stack}" "$tmpdir"
done <<EOF
8.6.5 8.6.5 x86_64-deb8-linux xz 2.4.1.0 3 debian:jessie
8.6.3 8.6.3 x86_64-deb8-linux xz 2.4.1.0 0 debian:jessie
8.4.4 8.4.4 x86_64-deb8-linux xz 2.4.1.0 0 debian:jessie
8.2.2 8.2.2 x86_64-deb8-linux xz 2.4.1.0 0 debian:jessie
8.0.2 8.0.2 x86_64-deb8-linux xz 2.4.1.0 0 debian:jessie
7.10.3 7.10.3 x86_64-deb8-linux xz 2.4.1.0 0 debian:jessie
8.6.5 x86_64-deb8-linux xz 2.4.1.0 3 2.1.1 debian:jessie
8.6.3 x86_64-deb8-linux xz 2.4.1.0 0 2.1.1 debian:jessie
8.4.4 x86_64-deb8-linux xz 2.4.1.0 0 2.1.1 debian:jessie
8.2.2 x86_64-deb8-linux xz 2.4.1.0 0 2.1.1 debian:jessie
8.0.2 x86_64-deb8-linux xz 2.4.1.0 0 2.1.1 debian:jessie
7.10.3 x86_64-deb8-linux xz 2.4.1.0 0 2.1.1 debian:jessie
EOF
# ^-ver ^-arch ^-ver rev^ ^-ver ^-base img
# |--------------------------| |-------| |-----| |-----------|
# GHC caba-inst Stack Docker

## Old versions:

# 7.8.4 7.8.4 x86_64-unknown-linux-deb7 xz 2.2.0.0 0 debian:jessie

Expand Down

0 comments on commit 391e187

Please sign in to comment.