Giter Club home page Giter Club logo

heroku-docker-haskell-test's Introduction

Heroku + Docker + Haskell = ?

This experiment is triggered by many things:

evening-earth-1057.herokuapp.com - Working example.

Starting point

Deploying Haskell to heroku isn't simple, there are different buildpacks:

With both buildpacks, and Heroku overall, I don't like that building happens in the cloud. A bit like in the AWS ELB blog post, I'd rather build app locally (or on CI machine, or in build cloud), and deploy artifacts to Heroku.

There are two approaches!

inline-build-pack

Using inline-build-pack, we can build our app locally, bundle artifacts, and push to Heroku. All three scripts: detect, release, and compile turn out to be no-op. Looks like that on cedar14 stack, there is libgmp.so.10, so we don't need to bundle it anymore, as heroku-buildpack-ghc does. Turns out that null-buildpack could be enough too.

Still one problem still exist: how to build a heroku-runnable binary executable on e.g. OSX? Here the docker comes to help! Using two simple scripts: prebuild and compilewithdocker we produce needed executable.

But committing artifacts to the repository is highly unelegant!

Using heroku docker

We can build an own Dockerfile to build the Haskell binaries. It's actually quite easy. Unfortunately (maybe for good) Dockerfiles doesn't support multi-inheritance, so we need to install GHC manually. Fortunately I have previously done docker ghc image, so we can just copy paste GHC installing spells. After that we install few dependencies† so we don't need to rebuild everything when deploying. And finally we build our application and leave it in /app directory which is then picked up by heroku deployment.

The first build takes time as then the build image is built, it took about 15 minutes on my machine. The heroku docker:release takes under one minute. After update to use stackage-update in place of cabal update the heroku docker:release takes about half a minute.

Conclusion

Using docker deployment you can tweak the build process, which is a huge win. Heroku infrastructure makes the other parts of deployment process and devops easy too. The only negative aspect, with greater power comes greater responsibility, you can accidentally deploy uncommited changes.


Remarks

  • † we could add cabal file to docker and install exact dependencies
  • there is .dockerignore to ignore host cabal sandbox one uses for development
  • This approach could be used to deploy scala (which takes enormous time to build e.g. play2 app), or to make Clojure deploy using uberjar.

heroku-docker-haskell-test's People

Contributors

phadej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jakzale

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.