Permalink
Browse files

Heroku へデプロイするための設定を記述

  • Loading branch information...
1 parent 1218bf4 commit 3567218b62d6d9445c7ca8e5cc3ced5133a8166c @ayato-p committed Nov 27, 2015
Showing with 31 additions and 9 deletions.
  1. +1 −0 todo-clj/Procfile
  2. +6 −1 todo-clj/project.clj
  3. +5 −3 todo-clj/src/todo_clj/core.clj
  4. +10 −5 todo-clj/src/todo_clj/db.clj
  5. +9 −0 todo-clj/src/todo_clj/main.clj
View
@@ -0,0 +1 @@
+web: java $JVM_OPT -jar target/todo-clj.jar host 0.0.0.0 port $PORT
@@ -3,6 +3,7 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
+ :min-lein-version "2.5.3"
:dependencies [[org.clojure/clojure "1.7.0"]
[ring "1.4.0"]
[compojure "1.4.0"]
@@ -16,6 +17,10 @@
[slingshot "0.12.2"]
[potemkin "0.4.1"]]
:plugins [[lein-environ "1.0.1"]]
+ :uberjar-name "todo-clj.jar"
:profiles
{:dev {:dependencies [[prone "0.8.2"]]
- :env {:dev true}}})
+ :env {:dev true
+ :db {:dbtype "postgresql" :dbname "todo_clj_dev" :host "localhost" :port 5432 :user "username" :password "password"}}}
+ :uberjar {:aot :all
+ :main todo-clj.main}})
@@ -13,9 +13,11 @@
todo-routes
main-routes)))
-(defn start-server []
- (when-not @server
- (reset! server (server/run-jetty #'app {:port 3000 :join? false}))))
+(defn start-server [& {:keys [host port join?]
+ :or {host "localhost" port 3000 join? false}}]
+ (let [port (if (string? port) (Integer/parseInt port) port)]
+ (when-not @server
+ (reset! server (server/run-jetty #'app {:host host :port port :join? join?})))))
(defn stop-server []
(when @server
@@ -1,10 +1,15 @@
(ns todo-clj.db
- (:require [clojure.java.jdbc :as jdbc]))
+ (:require [clojure.java.jdbc :as jdbc]
+ [environ.core :refer [env]]))
(def db-spec
- {:dbtype "postgresql" :dbname "todo_clj_dev" :host "localhost" :port 5432 :user "username" :password "password"})
+ (:db env))
+
+(defn migrated? []
+ (pos? (count (jdbc/query db-spec "select tablename from pg_tables where schemaname = 'public'"))))
(defn migrate []
- (jdbc/db-do-commands
- db-spec
- (jdbc/create-table-ddl :todo [:id :serial] [:title :varchar])))
+ (when-not (migrated?)
+ (jdbc/db-do-commands
+ db-spec
+ (jdbc/create-table-ddl :todo [:id :serial] [:title :varchar]))))
@@ -0,0 +1,9 @@
+(ns todo-clj.main
+ (:require [todo-clj.core :as core]
+ [todo-clj.db :as db])
+ (:gen-class))
+
+(defn -main [& {:as args}]
+ (db/migrate)
+ (core/start-server
+ :host (get args "host") :port (get args "port") :join? true))

0 comments on commit 3567218

Please sign in to comment.