forked from jkachmar/alpine-haskell-stack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
124 lines (104 loc) · 4.17 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
################################################################################
# Set up environment variables, OS packages, and scripts that are common to the
# build and distribution layers in this Dockerfile
FROM alpine:3.9 AS base
# Must be one of 'gmp' or 'simple'; used to build GHC with support for either
# 'integer-gmp' (with 'libgmp') or 'integer-simple'
#
# Default to building with 'integer-gmp' and 'libgmp' support
ARG GHC_BUILD_TYPE=gmp
# Must be a valid GHC version number, only tested with 8.4.4 and 8.6.4
#
# Default to GHC version 8.6.4 (latest at the time of writing)
ARG GHC_VERSION=8.6.4
# Add ghcup's bin directory to the PATH so that the versions of GHC it builds
# are available in the build layers
ENV GHCUP_INSTALL_BASE_PREFIX=/
ENV PATH=/.ghcup/bin:$PATH
# Install the basic required dependencies to run 'ghcup' and 'stack'
RUN apk upgrade --no-cache &&\
apk add --no-cache \
curl \
gcc \
git \
xz &&\
if [ "${GHC_BUILD_TYPE}" = "gmp" ]; then \
echo "Installing 'libgmp'" &&\
apk add --no-cache gmp-dev; \
fi
COPY docker/ghcup /usr/bin/ghcup
# Workaround hardcoded linker settings in GHC's build by patching 'ghcup'
COPY docker/ghcup.diff /tmp/ghcup.diff
RUN patch /usr/bin/ghcup < /tmp/ghcup.diff &&\
rm /tmp/ghcup.diff
################################################################################
# Intermediate layer that builds GHC
FROM base AS build-ghc
# Carry build args through to this stage
ARG GHC_BUILD_TYPE=gmp
ARG GHC_VERSION=8.6.4
RUN echo "Install OS packages necessary to build GHC" &&\
apk add --no-cache \
autoconf \
automake \
binutils-gold \
build-base \
coreutils \
cpio \
ghc \
linux-headers \
libffi-dev \
llvm5 \
musl-dev \
ncurses-dev \
perl \
python3 \
zlib-dev
COPY docker/build-gmp.mk /tmp/build-gmp.mk
COPY docker/build-simple.mk /tmp/build-simple.mk
RUN if [ "${GHC_BUILD_TYPE}" = "gmp" ]; then \
echo "Using 'integer-gmp' build config" &&\
apk add --no-cache gmp-dev &&\
mv /tmp/build-gmp.mk /tmp/build.mk && rm /tmp/build-simple.mk; \
elif [ "${GHC_BUILD_TYPE}" = "simple" ]; then \
echo "Using 'integer-simple' build config" &&\
mv /tmp/build-simple.mk /tmp/build.mk && rm tmp/build-gmp.mk; \
else \
echo "Invalid argument \[ GHC_BUILD_TYPE=${GHC_BUILD_TYPE} \]" && exit 1; \
fi
RUN echo "Compiling and installing GHC" &&\
ghcup -v compile -j $(nproc) -c /tmp/build.mk ${GHC_VERSION} ghc-8.4.3 &&\
rm /tmp/build.mk &&\
echo "Uninstalling GHC bootstrapping compiler" &&\
apk del ghc &&\
ghcup set ${GHC_VERSION}
################################################################################
# Intermediate layer that assembles 'stack' tooling
FROM build-ghc AS build-tooling
ENV STACK_VERSION=1.9.3
ENV STACK_SHA256="c9bf6d371b51de74f4bfd5b50965966ac57f75b0544aebb59ade22195d0b7543 stack-${STACK_VERSION}-linux-x86_64-static.tar.gz"
RUN echo "Downloading stack" &&\
cd /tmp &&\
wget -P /tmp/ "https://github.com/commercialhaskell/stack/releases/download/v${STACK_VERSION}/stack-${STACK_VERSION}-linux-x86_64-static.tar.gz" &&\
if ! echo -n "${STACK_SHA256}" | sha256sum -c -; then \
echo "stack-${STACK_VERSION} checksum failed" >&2 &&\
exit 1 ;\
fi ;\
tar -xvzf /tmp/stack-${STACK_VERSION}-linux-x86_64-static.tar.gz &&\
cp -L /tmp/stack-${STACK_VERSION}-linux-x86_64-static/stack /usr/bin/stack &&\
rm /tmp/stack-${STACK_VERSION}-linux-x86_64-static.tar.gz &&\
rm -rf /tmp/stack-${STACK_VERSION}-linux-x86_64-static
################################################################################
# Assemble the final image
FROM base
# Carry build args through to this stage
ARG GHC_BUILD_TYPE=gmp
ARG GHC_VERSION=8.6.4
COPY --from=build-ghc /.ghcup /.ghcup
COPY --from=build-tooling /usr/bin/stack /usr/bin/stack
# NOTE: 'stack --docker' needs bash + usermod/groupmod (from shadow)
RUN apk add --no-cache bash shadow
# TODO: This belongs in the 'base' layer
RUN apk add --no-cache libc-dev
RUN ghcup set ${GHC_VERSION} &&\
stack config set system-ghc --global true