forked from IHaskell/IHaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
95 lines (76 loc) · 2.83 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
# should match the GHC version of the stack.yaml resolver
# checked in CI
ARG GHC_VERSION=8.10.7
FROM haskell:${GHC_VERSION} AS ihaskell_base
# Install Ubuntu packages needed for IHaskell runtime
RUN apt-get update && \
apt-get install -y libzmq5 \
&& \
rm -rf /var/lib/apt/lists/*
FROM ihaskell_base AS builder
# Install Ubuntu packages needed for IHaskell build
RUN apt-get update && \
apt-get install -y libzmq3-dev pkg-config \
&& \
rm -rf /var/lib/apt/lists/*
WORKDIR /build
# Build snapshot
COPY stack.yaml stack.yaml
COPY ihaskell.cabal ihaskell.cabal
COPY ipython-kernel ipython-kernel
COPY ghc-parser ghc-parser
COPY ihaskell-display ihaskell-display
RUN stack setup
RUN stack build ihaskell --only-snapshot
# Build IHaskell itself.
# Don't just `COPY .` so that changes in e.g. README.md don't trigger rebuild.
COPY src src
COPY html html
COPY main main
COPY jupyterlab-ihaskell jupyterlab-ihaskell
COPY LICENSE LICENSE
RUN stack install ihaskell --local-bin-path ./bin/
# Save resolver used to build IHaskell
RUN sed -n 's/resolver: \(.*\)/\1/p' stack.yaml | tee resolver.txt
# Save third-party data files
RUN mkdir /data && \
snapshot_install_root=$(stack path --snapshot-install-root) && \
cp $(find ${snapshot_install_root} -name hlint.yaml) /data
FROM ihaskell_base AS ihaskell
# Install JupyterLab
RUN apt-get update && \
apt-get install -y python3-pip && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install -U jupyterlab notebook
# Create runtime user
ENV NB_USER jovyan
ENV NB_UID 1000
RUN adduser --disabled-password \
--gecos "Default user" \
--uid ${NB_UID} \
${NB_USER}
# Create directory for storing ihaskell files
ENV IHASKELL_DATA_DIR /usr/local/lib/ihaskell
RUN mkdir -p ${IHASKELL_DATA_DIR} && chown ${NB_UID} ${IHASKELL_DATA_DIR}
# Set up + set hlint data directory
ENV HLINT_DATA_DIR /usr/local/lib/hlint
COPY --from=builder --chown=${NB_UID} /data/hlint.yaml ${HLINT_DATA_DIR}/
ENV hlint_datadir ${HLINT_DATA_DIR}
# Set current user + directory
WORKDIR /home/${NB_USER}/src
RUN chown -R ${NB_UID} /home/${NB_USER}/src
USER ${NB_UID}
# Set up global project
COPY --from=builder --chown=${NB_UID} /build/resolver.txt /tmp/
RUN stack setup --resolver=$(cat /tmp/resolver.txt) --system-ghc
RUN stack config set system-ghc --global true
# Set up env file
RUN stack exec env --system-ghc > ${IHASKELL_DATA_DIR}/env
# Install + setup IHaskell
COPY --from=builder --chown=${NB_UID} /build/bin/ihaskell /usr/local/bin/
COPY --from=builder --chown=${NB_UID} /build/html ${IHASKELL_DATA_DIR}/html
COPY --from=builder --chown=${NB_UID} /build/jupyterlab-ihaskell ${IHASKELL_DATA_DIR}/jupyterlab-ihaskell
RUN export ihaskell_datadir=${IHASKELL_DATA_DIR} && \
ihaskell install --env-file ${IHASKELL_DATA_DIR}/env
RUN jupyter notebook --generate-config
CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]