1
votes

I've tried to get a Compojure/Ring application running on Heroku's Cedar stack (but failed). I've followed these guides

First, I deployed B), then seemed to successfully set off a web dyno C). But I don't see anything, when going to my app's URL. Running a heroku ps displayes the running processes, but I can't access my app from the web. Anything in particular I'm missing? Do I need to use git's master branch ? If I use lein run in my Procfile (I've tried several commands), how does Heroku (or foreman) know which http handler to run (again a Compojure/Ring app) ?

B)


    $ git push heroku  
    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 293 bytes, done.
    Total 3 (delta 1), reused 0 (delta 0)
    To [email protected]:high-night-9597.git
       36e7c18..050ea6d  account-chooser -> 

C)


    $ heroku ps:scale web=1
    Scaling web processes... done, now running 1

D)


    $ heroku ps
    Process  State             Command        
    -------  ----------------  ---------  
    run.1    complete for 11m  lein repl  
    web.1    created for 8m                   

E)


    $ heroku run lein repl
    Running lein repl attached to terminal... up, run.1 

F) Procfile:


    -web: lein exec src/.clj
    +web: lein run 

3

3 Answers

2
votes

You can use any branch you like, however you need to specify which branch you want to push to heroku - if you're not in that branch already:

$ git push heroku your_branch_name

Provided your app runs fine locally, Heroku knows how to run it based on what you have in your Procfile, which in your case seems to have something missing.

Say your main handler is under $YOUR_APP_ROOT/src/my-clj-app/core.clj.

Then, your Procfile should probably look something like this:

web: lein run -m my-clj-app.core

That's how Heroku knows how to run your app.

Make sure that file has the correct namespace definition:

(ns my-clj-app.core)

Can you give that a try?

1
votes

I'm also new, but I'll try to share some of the problems I've encountered.
If it is a port error like what you suspected, did you set the port correctly?

(ns demo.web
  (:use ring.adapter.jetty))  

(defn app [req]
  {:status 200
   :headers {"Content-Type" "text/plain"}
   :body "Hello, world"})  

(defn -main []
  (let [port (Integer/parseInt (System/getenv "PORT"))]
  (run-jetty app {:port port})))

I will list some of the problems I encountered, perhaps it might help you.

Procfile

The Procfile should look like:
web: lein run -m http.handler
and not
'web: lein run -m http.handler'
If the Procfile is detected properly, you should see this:
Heroku output
-----> Discovering process types
Procfile declares types -> web ;; <- This line should appear
-----> Compiled slug size is 14.2MB
-----> Launching... done, v15

"lein repl" conflicting with "web dyno"

I also noticed a problem (bug?) when I was running lein repl before I started a web dyno. You should try shutting down your "repl" first:
heroku ps:stop run.1
then run the web dyno:
heroku ps:scale web=1.

At least 1 web dyno must exist

If you accidentally shut down your web dyno:
heroku ps:scale web=0
Heroku does not automatically start a web dyno the next time you push to Heroku. So check that you have a web dyno running before you commit to heroku. You can also start a web dyno after committing.

Reference tutorial

For me, I was able to successfully follow this nicely written tutorial - http://thecomputersarewinning.com/post/clojure-heroku-noir-mongo. If you are using Noir 1.2.2, you will need to remove:
(:require [myapp.views.noir.content.getting-started] :as content)
from "welcome.clj".

0
votes

This is a follow on question. As outlined in the abouve comments, I was able to push my app to Heroku's master, and that deploys it.

But when I try to go to my app's URL, I get the below error. It's a bizarre port error, but I didn't think I had control over those details when deploying a Clojure app on Heroku. I think my setup's pretty straighforward. Is there anything I can do to address this error?

Procfile


    web: lein run -m http.handler

http.handler


    ...
    (def app
      (handler/site main))

Error


    2011-12-31T04:10:02+00:00 app[web.1]: Listening for transport dt_socket at address: 41208
    2011-12-31T04:10:03+00:00 heroku[web.1]: Stopping process with SIGKILL
    2011-12-31T04:10:03+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 41208, should be 55032 (see environment variable PORT)
    2011-12-31T04:10:04+00:00 heroku[web.1]: State changed from starting to crashed
    2011-12-31T04:10:05+00:00 heroku[web.1]: Process exited
    2011-12-31T04:20:08+00:00 heroku[web.1]: State changed from crashed to created
    2011-12-31T04:20:08+00:00 heroku[web.1]: State changed from created to starting
    2011-12-31T04:20:12+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler`
    2011-12-31T04:20:16+00:00 app[web.1]: Listening for transport dt_socket at address: 49151
    2011-12-31T04:20:16+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 49151, should be 39092 (see environment variable PORT)
    2011-12-31T04:20:16+00:00 heroku[web.1]: Stopping process with SIGKILL
    2011-12-31T04:20:17+00:00 heroku[web.1]: State changed from starting to crashed
    2011-12-31T04:20:18+00:00 heroku[web.1]: Process exited
    2011-12-31T04:31:13+00:00 heroku[web.1]: State changed from crashed to created
    2011-12-31T04:31:13+00:00 heroku[web.1]: State changed from created to starting
    2011-12-31T04:31:16+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler`
    2011-12-31T04:31:20+00:00 app[web.1]: Listening for transport dt_socket at address: 44321
    2011-12-31T04:31:20+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 44321, should be 17211 (see environment variable PORT)
    2011-12-31T04:31:20+00:00 heroku[web.1]: Stopping process with SIGKILL
    2011-12-31T04:31:22+00:00 heroku[web.1]: State changed from starting to crashed
    2011-12-31T04:31:22+00:00 heroku[web.1]: Process exited
    2011-12-31T04:44:59+00:00 heroku[web.1]: State changed from crashed to created
    2011-12-31T04:44:59+00:00 heroku[web.1]: State changed from created to starting
    2011-12-31T04:45:02+00:00 heroku[web.1]: Starting process with command `lein run -m http.handler`
    2011-12-31T04:45:05+00:00 app[web.1]: Listening for transport dt_socket at address: 37500
    2011-12-31T04:45:06+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 37500, should be 14046 (see environment variable PORT)
    2011-12-31T04:45:06+00:00 heroku[web.1]: Stopping process with SIGKILL
    2011-12-31T04:45:07+00:00 heroku[web.1]: State changed from starting to crashed
    2011-12-31T04:45:07+00:00 heroku[web.1]: Process exited
    2011-12-31T04:49:22+00:00 heroku[router]: Error H10 (App crashed) -> GET bkeeping.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
    2011-12-31T04:49:31+00:00 heroku[router]: Error H10 (App crashed) -> GET bkeeping.herokuapp.com/favicon.ico dyno= queue= wait= service= status=503 bytes=