public
Last active

Clojure on Heroku

  • Download Gist
gistfile1.txt
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
~/$ lein new ring-on-heroku
Created new project in: /home/jim/Development/ring-on-heroku
~/$ cd ring-on-heroku
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj
(ns ring-on-heroku.core
(:use ring.util.response
ring.adapter.jetty))
 
(defn app [req]
(response "Hello World"))
 
(defn -main []
(let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
(run-jetty app {:port port})))
 
~/ring-on-heroku$ cat > project.clj
(defproject ring-on-heroku "1.0.0-SNAPSHOT"
:description "Example Ring app running on Heroku"
:dependencies [[org.clojure/clojure "1.2.1"]
[ring/ring-core "0.3.8"]
[ring/ring-jetty-adapter "0.3.8"]])
 
~/ring-on-heroku$ git init
Initialized empty Git repository in /home/jim/Development/ring-on-heroku/.git/
~/ring-on-heroku$ git add .
~/ring-on-heroku$ git commit -m "Initial commit"
[master (root-commit) c09dde7] Initial commit
6 files changed, 40 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
create mode 100644 Procfile
create mode 100644 README
create mode 100644 project.clj
create mode 100644 src/ring_on_heroku/core.clj
create mode 100644 test/ring_on_heroku/test/core.clj
~/ring-on-heroku$ heroku create --stack cedar
Creating fierce-fog-647... done
http://fierce-fog-647.heroku.com/ | git@heroku.com:fierce-fog-647.git
Git remote heroku added
~/ring-on-heroku$ git push heroku master
Warning: Permanently added the RSA host key for IP address '50.19.85.156' to the list of known hosts.
Counting objects: 13, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (13/13), 1.30 KiB, done.
Total 13 (delta 0), reused 0 (delta 0)
 
-----> Heroku receiving push
-----> Clojure app detected
-----> Installing Leiningen
Downloading: leiningen-1.5.2-standalone.jar
Writing: lein script
-----> Installing dependencies with Leiningen
Running: lein deps :skip-dev
Downloading: org/clojure/clojure/1.2.1/clojure-1.2.1.pom from central
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.pom from central
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.pom from clojure
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.pom from clojars
Transferring 2K from clojars
Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.pom from clojure
Transferring 1K from clojure
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.pom from clojure
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.pom from clojars
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.pom from central
Downloading: org/apache/commons/commons-parent/11/commons-parent-11.pom from clojure
Downloading: org/apache/commons/commons-parent/11/commons-parent-11.pom from clojars
Downloading: org/apache/commons/commons-parent/11/commons-parent-11.pom from central
Downloading: org/apache/apache/4/apache-4.pom from clojure
Downloading: org/apache/apache/4/apache-4.pom from clojars
Downloading: org/apache/apache/4/apache-4.pom from central
Downloading: commons-io/commons-io/1.4/commons-io-1.4.pom from clojure
Downloading: commons-io/commons-io/1.4/commons-io-1.4.pom from clojars
Downloading: commons-io/commons-io/1.4/commons-io-1.4.pom from central
Downloading: org/apache/commons/commons-parent/7/commons-parent-7.pom from clojure
Downloading: org/apache/commons/commons-parent/7/commons-parent-7.pom from clojars
Downloading: org/apache/commons/commons-parent/7/commons-parent-7.pom from central
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.pom from clojure
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.pom from clojars
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.pom from central
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.pom from clojure
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.pom from clojars
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.pom from central
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.pom from central
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.pom from clojure
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.pom from clojars
Transferring 2K from clojars
Downloading: ring/ring-servlet/0.3.8/ring-servlet-0.3.8.pom from clojure
Downloading: ring/ring-servlet/0.3.8/ring-servlet-0.3.8.pom from clojars
Transferring 1K from clojars
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.pom from clojure
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.pom from clojars
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.pom from central
Downloading: org/mortbay/jetty/project/6.1.26/project-6.1.26.pom from clojure
Downloading: org/mortbay/jetty/project/6.1.26/project-6.1.26.pom from clojars
Downloading: org/mortbay/jetty/project/6.1.26/project-6.1.26.pom from central
Downloading: org/mortbay/jetty/jetty-parent/10/jetty-parent-10.pom from clojure
Downloading: org/mortbay/jetty/jetty-parent/10/jetty-parent-10.pom from clojars
Downloading: org/mortbay/jetty/jetty-parent/10/jetty-parent-10.pom from central
Downloading: org/eclipse/jetty/jetty-parent/14/jetty-parent-14.pom from clojure
Downloading: org/eclipse/jetty/jetty-parent/14/jetty-parent-14.pom from clojars
Downloading: org/eclipse/jetty/jetty-parent/14/jetty-parent-14.pom from central
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.pom from clojure
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.pom from clojars
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.pom from central
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.pom from clojure
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.pom from clojars
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.pom from central
Downloading: org/mortbay/jetty/jetty-parent/7/jetty-parent-7.pom from clojure
Downloading: org/mortbay/jetty/jetty-parent/7/jetty-parent-7.pom from clojars
Downloading: org/mortbay/jetty/jetty-parent/7/jetty-parent-7.pom from central
Downloading: org/clojure/clojure/1.2.1/clojure-1.2.1.jar from central
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.jar from central
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.jar from clojure
Downloading: ring/ring-core/0.3.8/ring-core-0.3.8.jar from clojars
Transferring 16K from clojars
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.jar from clojure
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.jar from clojars
Downloading: commons-codec/commons-codec/1.4/commons-codec-1.4.jar from central
Downloading: commons-io/commons-io/1.4/commons-io-1.4.jar from clojure
Downloading: commons-io/commons-io/1.4/commons-io-1.4.jar from clojars
Downloading: commons-io/commons-io/1.4/commons-io-1.4.jar from central
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar from clojure
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar from clojars
Downloading: commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar from central
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.jar from clojure
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.jar from clojars
Downloading: javax/servlet/servlet-api/2.5/servlet-api-2.5.jar from central
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.jar from central
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.jar from clojure
Downloading: ring/ring-jetty-adapter/0.3.8/ring-jetty-adapter-0.3.8.jar from clojars
Transferring 2K from clojars
Downloading: ring/ring-servlet/0.3.8/ring-servlet-0.3.8.jar from clojure
Downloading: ring/ring-servlet/0.3.8/ring-servlet-0.3.8.jar from clojars
Transferring 3K from clojars
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.jar from clojure
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.jar from clojars
Downloading: org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.jar from central
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.jar from clojure
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.jar from clojars
Downloading: org/mortbay/jetty/jetty-util/6.1.26/jetty-util-6.1.26.jar from central
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar from clojure
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar from clojars
Downloading: org/mortbay/jetty/servlet-api/2.5-20081211/servlet-api-2.5-20081211.jar from central
Copying 11 files to /tmp/build_3fg55ekdqxz4k/lib
-----> Discovering process types
Procfile declares types -> web
-----> Compiled slug size is 11.0MB
-----> Launching... done, v4
http://fierce-fog-647.herokuapp.com deployed to Heroku
 
To git@heroku.com:fierce-fog-647.git
* [new branch] master -> master

Had to explicitly add the PORT env var:

$ heroku config:add PORT=8080

Otherwise, kick-ass.

EDIT:

Yeah, I was off. Jetty needs to bind to a dynamically assigned port, which Heroku puts in the PORT env variable.

This is going to be HUGE!

zkim, I had to remove the PORT env var in order to get it to work.

My code is more or less verbatim, but IIRC I made a small change or two. I'll push my skeleton project soon-ish.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.