IHaskell/Dockerfile

97 lines
2.9 KiB
Docker
Raw Normal View History

2021-08-17 11:30:27 -07:00
# should match the GHC version of the stack.yaml resolver
2021-08-18 08:59:16 -07:00
# checked in CI
2024-02-12 14:28:23 +11:00
ARG GHC_VERSION=9.6.4
2021-08-18 08:59:16 -07:00
FROM haskell:${GHC_VERSION} AS ihaskell_base
2021-08-17 11:30:27 -07:00
# Install Ubuntu packages needed for IHaskell runtime
RUN apt-get update && \
apt-get install -y libzmq5 \
2021-08-17 11:30:27 -07:00
&& \
rm -rf /var/lib/apt/lists/*
FROM ihaskell_base AS builder
2021-08-17 11:30:27 -07:00
# Install Ubuntu packages needed for IHaskell build
RUN apt-get update && \
2021-10-15 12:12:49 -04:00
apt-get install -y libzmq3-dev pkg-config \
2021-08-17 11:30:27 -07:00
&& \
rm -rf /var/lib/apt/lists/*
2021-08-17 11:30:27 -07:00
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
2021-08-17 11:30:27 -07:00
# 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
2021-08-17 11:30:27 -07:00
COPY LICENSE LICENSE
RUN stack install ihaskell --local-bin-path ./bin/
2021-08-17 11:30:27 -07:00
# Save resolver used to build IHaskell
2023-12-05 22:18:04 +11:00
RUN sed -n 's/resolver: \(.*\)#.*/\1/p' stack.yaml | tee resolver.txt
2021-08-17 11:30:27 -07:00
# 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
2021-09-15 14:30:29 +10:00
# Install JupyterLab
2021-08-17 11:30:27 -07:00
RUN apt-get update && \
apt-get install -y python3-pip && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install -U pip
2022-07-20 10:04:05 +10:00
RUN pip3 install -U jupyterlab notebook
2021-08-17 11:30:27 -07:00
# Create runtime user
ENV NB_USER jovyan
ENV NB_UID 1000
RUN adduser --disabled-password \
--gecos "Default user" \
--uid ${NB_UID} \
${NB_USER}
2021-08-17 11:30:27 -07:00
# 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}
2021-08-17 11:30:27 -07:00
# 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}
2021-08-17 11:30:27 -07:00
# Set current user + directory
WORKDIR /home/${NB_USER}/src
2021-08-25 20:45:19 -07:00
RUN chown -R ${NB_UID} /home/${NB_USER}/src
USER ${NB_UID}
2021-08-17 11:30:27 -07:00
# 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
2021-08-17 18:02:49 -07:00
# Set up env file
RUN stack exec env --system-ghc > ${IHASKELL_DATA_DIR}/env
2021-08-17 11:30:27 -07:00
# 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
2021-08-17 11:30:27 -07:00
RUN export ihaskell_datadir=${IHASKELL_DATA_DIR} && \
2021-08-17 18:02:49 -07:00
ihaskell install --env-file ${IHASKELL_DATA_DIR}/env
RUN jupyter notebook --generate-config
2021-08-17 11:30:27 -07:00
CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]