yesodketer

Run Keter without GHC and cabal


I have a server and want to deploy my Yesod applications without installing GHC and Cabal. I am not sure if is possible: a Teacher told me that I must first compile Keter in my machine and, after that, put keter executable on the server, though I am not sure how to do that.


Solution

  • To build Keter, first you'll need to clone the sources from its GitHub repository. Then you'll need to set up a Haskell build environment and use cabal build or cabal install to build the sources. Personally, I use a Docker container derived from an image based on the following Dockerfile:

    FROM haskell:7.10.2
    RUN apt-get update && apt-get install -y \
      git
    RUN mkdir /src
    RUN cd src && \
      git clone https://github.com/snoyberg/keter && \
      cd keter && \
      git checkout e8b5a3fd5e14dfca466f8acff2a02f0415fceeb0
    WORKDIR /src/keter
    RUN cabal update
    RUN cabal install keter
    ENTRYPOINT /bin/bash
    

    This is an image containing the Keter sources checked out at a specific revision with the minimum GHC toolchain required to build it all. The cabal command lines pull down all the project's dependencies and compiles the whole thing. Once this has completed, you can grab the keter executable from ~/.cabal/bin/keter.

    Even if you choose not to use Docker, this file should give you a rough idea how to set up your environment.

    Now you have Keter compiled, you can run it inside another Docker container. Here's a rough idea what the Dockerfile for the corresponding image might look like:

    FROM debian
    RUN apt-get update && apt-get install -y \
      libgmp-dev \
      nano \
      postgresql
    COPY keter /opt/keter/bin/
    COPY keter-config.yaml /opt/keter/etc/
    EXPOSE 80
    CMD ["/opt/keter/bin/keter", "/opt/keter/etc/keter-config.yaml"]
    

    Ths will take a base Debian image and install a minimal set of packages on top of it. It then copies the keter executable and configuration file into the image. If you then run a container from the resulting image it will start the keter executable.

    Fair warning: This whole process is fairly involved. I'm still working on tweaking the exact details myself. Good luck!