部署到heroku与clojure项目,生产环境问题 [英] Deploying to heroku with clojure project, production environment issues

查看:131
本文介绍了部署到heroku与clojure项目,生产环境问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图片库应用程序,我从Web开发与Clojure书,我正在部署到Heroku的点。我试着让它工作作为一个独立的uberjar和蹦床。我试图在开始使用environ,但不断获取数据库值错误db-spec,所以我停止使用它,使其在本地运行良好。我试图设置我自己的环境变量,还要使用一个main.clj文件。我编辑了我的配置文件设置信息,可以让它部署,但不能在heroku上正常运行。有时我得到一个空白屏幕,可以导航到我的几个页面,然后有时我得到一个h10应用程序崩溃的错误,在GET,寻找一个favicon,这是很难排除故障。

I have a picture gallery application I made from the "Web Development with Clojure" book and I am at the point of deploying it to Heroku. I have tried making it work as both a standalone uberjar and with trampoline. I tried to use environ in the beginning, but kept getting database value errors on "db-spec" so I stopped using it to make it run fine locally. I tried to set my own environment variables, and also to use a main.clj file. I edited my profile settings info and can get it to deploy but not run properly on heroku. Sometimes I get a blank screen and can navigate to a few of my pages and then sometimes I get an h10 app crashed error on a GET that is looking for a favicon, which is hard to troubleshoot.

有经验的人能告诉我我需要写什么以及在什么文件中使它在Heroku的生产中工作?奖励点,如果你也可以解释环境变量和db连接设置与Postgres在Heroku为我。

Could someone with experience tell me specifically what I need to write and in what files to make it work in production on Heroku? Bonus points if you can also demystify the environment variables and db connections settings with Postgres in Heroku for me.

我已经学习了heroku,environ和leiningen文档。我也在堆栈上搜索了同样的问题,当然三个工作通过我的书中的所有例子,这是由luminus docs镜像,因为同一个人写他们。我的应用程序的链接如下。以下是我在github上放置的项目的一个版本的链接。

I have scoured the heroku, environ and leiningen docs. I have also searched for the same problem on stack and of course triple worked through all the examples in my book, which are mirrored by the luminus docs, cause the same guy wrote them. The link to my app is below. Below is a link to one version of the project I put up on github.

https://github.com/gamma235/picture-gallery

这是我如何定义数据库:

This is how I have defined my database:

(def db 
  {:subprotocol "postgresql"
   :subname "//localhost/gallery"
   :user "admin"
   :password "admin"})

.clj文件:

(ns picture-gallery.main
  (:use picture-gallery.handler
        [org.httpkit.server :only [run-server]]
        [ring.middleware file-info file])
  (:gen-class))

(defn -main [& [port]]
  (let [port (if port (Integer/parseInt port) 3000)]
    (run-server app {:port port})
    (println (str "You can view the site at http://localhost:" port)))))

我使用 [org.clojure / java.jdbc0.2.3] 为我的数据库需要。这是旧版本,但我跟着这本书。

I am using [org.clojure/java.jdbc "0.2.3"] for my database needs. It is the old version but I am following along with the book.

这里是我的project.clj文件的重要部分:

Here are significant parts of my project.clj file:

...    
:main picture-gallery.main
      :min-lein-version "2.0.0"
      :plugins [[lein-ring "0.8.7"]]
      :ring {:handler picture-gallery.handler/app
             :init picture-gallery.handler/init
             :destroy picture-gallery.handler/destroy}
      :profiles
      {:uberjar {:main picture-gallery.main, :aot :all}}
      )

我按照heroku shouter应用程序教程这里,并轻松部署它。我无法弄清楚如何改变我的图片库应用程序中的代码,基于这个项目,但是。在Procfile中的 $ JVM_OPTS 对我来说是神秘的。欢迎任何解释或转介。请浏览源代码的heroku应用程序,并成功我失败的地方。

I followed the heroku shouter app tutorial here and deployed it with little fuss. I am unable to figure out how alter the code in my picture-gallery app, based on this project, however. Things like $JVM_OPTS in the Procfile are mysterious to me. Any explanations or referrals are welcome. Please browse the source-code for the heroku app and succeed where I have failed.

推荐答案

我重构了用Korma包装我的数据库的代码:

I refactored the code to wrap my db with Korma:

(ns picture-gallery.models.db
  (:require [clojure.java.jdbc :as sql]
            [korma.db :refer [defdb transaction]]
            [korma.core :refer :all]))

(def db (or (System/getenv "DATABASE_URL")
             "postgresql://localhost:5432/gallery"))

(defdb korma-db db)

重新部署和它工作正常。我仍然不知道为什么它不工作之前,它只开始工作后,我使用Korma,将数据库定义更改为DATABASE_URL单独没有这样做。我认为它要么与Heroku只支持最新版本的JDBC(我使用0.2.3)或连接池。因为我不知道为什么会发生这种情况,我觉得这个问题还是开放的,但对于跟在后面,遇到同样问题的其他人,使用Korma。作为最后一点,我还将模板从Hiccup更改为Selmer,所以有一个机会,这是问题的原因。

redeployed it and it worked fine. I still have no idea why it wasn't working before and it only started working after I used Korma, changing the db definition to the DATABASE_URL alone didn't do it. I think that it either had something to do with Heroku only supporting the latest version of JDBC (I was using 0.2.3) or connection pooling. As I have no idea why this happened, I feel that this question is still open, but for others who come after me and run into the same problem, use Korma. As a final note, I also changed the templating from Hiccup to Selmer, so there is a chance that this was the cause of the problem.

这篇关于部署到heroku与clojure项目,生产环境问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆