Giter Site home page Giter Site logo

heroku-buildpack-clojure's Introduction

Heroku buildpack: Clojure

This is a Heroku buildpack for Clojure apps. It uses Leiningen.

Note that you don't have to do anything special to use this buildpack with Clojure apps on Heroku; it will be used by default for all projects containing a project.clj file, though it may be an older revision than current master.

This repository is made available so users can fork for their own needs and contribute patches back as well as for transparency.

Usage

Example usage for an app already stored in git:

$ tree
|-- Procfile
|-- project.clj
|-- README
`-- src
    `-- sample
        `-- core.clj

$ heroku create --stack cedar --buildpack http://github.com/heroku/heroku-buildpack-clojure.git

$ git push heroku master
...
-----> Heroku receiving push
-----> Fetching custom buildpack
-----> Clojure app detected
-----> Installing Leiningen
       Downloading: leiningen-2.0.0-preview7-standalone.jar
       Writing: lein script
-----> Building with Leiningen
       Running: with-profile production do compile :all, clean-m2
       Downloading: org/clojure/clojure/1.2.1/clojure-1.2.1.pom from central
       Downloading: org/clojure/clojure/1.2.1/clojure-1.2.1.jar from central
       Copying 1 file to /tmp/build_2e5yol0778bcw/lib
-----> Discovering process types
       Procfile declares types -> core
-----> Compiled slug size is 10.0MB
-----> Launching... done, v4
       http://gentle-water-8841.herokuapp.com deployed to Heroku

The buildpack will detect your app as Clojure if it has a project.clj file in the root. If you use the clojure-maven-plugin, the standard Java buildpack should work instead. Leiningen 1.7.1 will be used by default, but if you have :min-lein-version "2.0.0" in project.clj then Leiningen 2.x will be used instead.

Configuration

By default your project is built by running lein deps under Leiningen 1.x and lein compile :all under Leiningen 2.x. To customize this, check in a bin/build script into your project and it will be run instead of invoking lein directly.

If you are using Leiningen 2.x, it's highly recommended that you use the :production profile to avoid having tests and development dependencies on your classpath in production. By default the :production profile configures a mirror setting for faster dependency fetching from S3; if you place a :production profile in your project.clj you should do the same:

  :production {:misc "configuration"
               :mirrors {#"central|clojars"
                         "http://s3pository.herokuapp.com/clojure"}}

You should reduce memory consumption by using the trampoline task in your Procfile. This will cause Leiningen to calculate the classpath and code to run for your project, then exit and execute your project's JVM:

web: lein trampoline with-profile production run -m myapp.web

Hacking

To change this buildpack, fork it on GitHub. Push up changes to your fork, then create a test app with --buildpack YOUR_GITHUB_URL and push to it. If you already have an existing app you may use heroku config:add BUILDPACK_URL=YOUR_GITHUB_URL instead.

For example, you could adapt it to generate an uberjar at build time.

Open bin/compile in your editor, and replace the block labeled "fetch deps with lein" with something like this:

echo "-----> Generating uberjar with Leiningen:"
echo "       Running: LEIN_NO_DEV=y lein uberjar"
cd $BUILD_DIR
PATH=.lein/bin:/usr/local/bin:/usr/bin:/bin JAVA_OPTS="-Xmx500m -Duser.home=$BUILD_DIR" LEIN_NO_DEV=y lein uberjar 2>&1 | sed -u 's/^/       /'
if [ "${PIPESTATUS[*]}" != "0 0" ]; then
  echo " !     Failed to create uberjar with Leiningen"
  exit 1
fi

Commit and push the changes to your buildpack to your GitHub fork, then push your sample app to Heroku to test. The output should include:

-----> Generating uberjar with Leiningen:

If it's something other users would find useful, pull requests are welcome.

Troubleshooting

To see what the buildpack has produced, do heroku run bash and you will be logged into an environment with your compiled app available. From there you can explore the filesystem and run lein commands.

heroku-buildpack-clojure's People

Contributors

technomancy avatar mmcgrana avatar

Watchers

Jeroen van Dijk avatar

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.