duct

2019-11-20T20:30:20.233300Z

So, I managed to get coercion working okay with spec-tools, and can develop the tutorial mentioned above fine. However, I’ve tried packaging the app using Docker and am having problems attempting to run migrations on startup. My understanding is that you just have to include :duct/migrator into main.clj but reviewing the logs, this isn’t working….

(ns film-ratings.main
  (:gen-class)
  (:require [duct.core :as duct]))

(duct/load-hierarchy)

(defn -main [& args]
  (let [keys     (or (duct/parse-keys args) [:duct/migrator :duct/daemon])
        profiles [:duct.profile/prod]]
    (-> (duct/resource "film_ratings/config.edn")
        (duct/read-config)
        (duct/exec-config profiles keys))))
will@Pauls-MacBook-Pro film-ratings % docker-compose up -d && docker-compose logs -f 
Creating network "film-ratings_default" with the default driver
Creating film-ratings_postgres_1 ... done
Creating film-ratings_filmapp_1  ... done
Attaching to film-ratings_filmapp_1, film-ratings_postgres_1
postgres_1  | 2019-11-20 20:24:53.348 UTC [1] LOG:  starting PostgreSQL 12.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0) 8.3.0, 64-bit
postgres_1  | 2019-11-20 20:24:53.348 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2019-11-20 20:24:53.348 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2019-11-20 20:24:53.353 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2019-11-20 20:24:53.450 UTC [18] LOG:  database system was shut down at 2019-11-20 20:23:44 UTC
postgres_1  | 2019-11-20 20:24:53.481 UTC [1] LOG:  database system is ready to accept connections
filmapp_1   | 19-11-20 20:25:05 07de9dcec793 REPORT [duct.server.http.jetty:13] - :duct.server.http.jetty/starting-server {:port 3000}
filmapp_1   | 19-11-20 20:29:24 07de9dcec793 INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/assets/normalize.css/normalize.css", :query-string nil}
filmapp_1   | 19-11-20 20:29:24 07de9dcec793 INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/list-films", :query-string nil}
filmapp_1   | 19-11-20 20:29:24 07de9dcec793 INFO [duct.middleware.web:16] - :duct.middleware.web/request {:request-method :get, :uri "/css/site.css", :query-string nil}
postgres_1  | 2019-11-20 20:29:25.391 UTC [25] ERROR:  relation "film" does not exist at character 15

iarenaza 2019-11-20T22:36:41.235300Z

Did you rebuild the Docker container of the application after you added the :duct/migrator key to -main function? You may be running the old container, without the additional key.

iarenaza 2019-11-20T22:41:30.238200Z

By the way, we don't add the key to -main . We simply run our apps specifying the keys to initialize using something like java -jar "application-uberjar.jar" ":duct/migrator" ":duct/daemon" (we have some additional JVM options to tune some parameters, but that's the gist of it). That way we don need to change the code and rebuild the uberjar if we want to use different set of keys.