docker-ifyed.

This commit is contained in:
Bryce Covert
2017-12-20 10:57:08 -08:00
parent ee3ea0be2c
commit 4625ef4474
15 changed files with 63 additions and 32 deletions

View File

@@ -3,4 +3,5 @@ RUN apk update
RUN apk add poppler RUN apk add poppler
RUN apk add poppler-utils RUN apk add poppler-utils
COPY target/auto-ap.jar /usr/local/ COPY target/auto-ap.jar /usr/local/
COPY config /usr/local/config/
CMD java -jar /usr/local/auto-ap.jar CMD java -jar /usr/local/auto-ap.jar

1
config/dev.edn Normal file
View File

@@ -0,0 +1 @@
{:db {:server "localhost"}}

1
config/prod.edn Normal file
View File

@@ -0,0 +1 @@
{:db {:server "database"}}

21
docker-compose.yml Normal file
View File

@@ -0,0 +1,21 @@
version: '2'
services:
app:
build: .
ports:
- 3000:3000
depends_on:
- database
environment:
config: /usr/local/config/prod.edn
database:
image: postgres:9-alpine
ports:
- 5432:5432
volumes:
- ./init-db:/docker-entrypoint-initdb.d/
environment:
POSTGRES_USER: ap
POSTGRES_PASSWORD: fifteen-invoices-imported!
POSTGRES_DB: autoap

4
init-db/0001.sql Normal file
View File

@@ -0,0 +1,4 @@
CREATE TABLE invoices (id serial primary key, invoice_number varchar(255), date varchar(255), total varchar(255), customer_identifier varchar(255), imported boolean, status varchar(255), vendor varchar(255), potential_duplicate boolean, company varchar(255));
CREATE TABLE users (id serial primary key, provider varchar(255), provider_id varchar(255), data text);

1
init-db/0002.sql Normal file
View File

@@ -0,0 +1 @@
insert into users (provider, provider_id, data) values('google', '104596437663417983775', '{:companies ["Brown Chicken Brown Cow" "Campbell Brewing Company"]}');

View File

@@ -31,6 +31,7 @@
:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"] :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]
:ring {:handler auto-ap.handler/app} :ring {:handler auto-ap.handler/app}
:source-paths ["src/clj"] :source-paths ["src/clj"]
:resource-paths ["resources"]
:figwheel {:css-dirs ["resources/public/css"] :figwheel {:css-dirs ["resources/public/css"]
:ring-handler auto-ap.handler/app} :ring-handler auto-ap.handler/app}
@@ -49,7 +50,8 @@
[com.cemerick/piggieback "0.2.2"]] [com.cemerick/piggieback "0.2.2"]]
:plugins [[lein-figwheel "0.5.13"] :plugins [[lein-figwheel "0.5.13"]
[lein-pdo "0.1.1"]]}} [lein-pdo "0.1.1"]]
:jvm-opts ["-Dconfig=config/dev.edn"]}}
:cljsbuild :cljsbuild
{:builds {:builds

View File

@@ -1,28 +1,28 @@
(ns auto-ap.db.invoices (ns auto-ap.db.invoices
(:require [clojure.java.jdbc :as j] (:require [clojure.java.jdbc :as j]
[auto-ap.db.utils :refer [clj->db db->clj conn]])) [auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
(defn insert-multi! [rows] (defn insert-multi! [rows]
(j/insert-multi! conn (j/insert-multi! (get-conn)
:invoices :invoices
(map clj->db rows))) (map clj->db rows)))
(defn get-all [] (defn get-all []
(map db->clj (j/query conn "SELECT * FROM invoices"))) (map db->clj (j/query (get-conn) "SELECT * FROM invoices")))
(defn approve [] (defn approve []
(map db->clj (j/update! conn :invoices {:imported true} [] ))) (map db->clj (j/update! (get-conn) :invoices {:imported true} [] )))
(defn reject [] (defn reject []
(j/delete! conn :invoices ["imported = false"])) (j/delete! (get-conn) :invoices ["imported = false"]))
(defn get-unpaid [company] (defn get-unpaid [company]
(if company (if company
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE imported=true AND company = ?" company])) (map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE imported=true AND company = ?" company]))
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))) (map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=true"))))
(defn get-pending [company] (defn get-pending [company]
(if company (if company
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" company])) (map db->clj (j/query (get-conn) ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" company]))
(map db->clj (j/query conn"SELECT * FROM invoices WHERE imported=false or imported is null")))) (map db->clj (j/query (get-conn) "SELECT * FROM invoices WHERE imported=false or imported is null"))))

View File

@@ -1,10 +1,10 @@
(ns auto-ap.db.users (ns auto-ap.db.users
(:require [clojure.java.jdbc :as j] (:require [clojure.java.jdbc :as j]
[clojure.edn :as edn] [clojure.edn :as edn]
[auto-ap.db.utils :refer [clj->db db->clj conn]])) [auto-ap.db.utils :refer [clj->db db->clj get-conn]]))
(defn find-or-insert! [row] (defn find-or-insert! [row]
(let [user (first (j/find-by-keys conn (let [user (first (j/find-by-keys (get-conn)
:users :users
{:provider_id (:provider_id row) {:provider_id (:provider_id row)
:provider (:provider row)}))] :provider (:provider row)}))]

View File

@@ -1,4 +1,5 @@
(ns auto-ap.db.utils (ns auto-ap.db.utils
(:require [config.core :refer [env]])
(:require [clojure.string :as str])) (:require [clojure.string :as str]))
(defn snake->kebab [s] (defn snake->kebab [s]
@@ -21,19 +22,18 @@
[(keyword (kebab->snake (name k))) v]) [(keyword (kebab->snake (name k))) v])
x))) x)))
(let [db-host "ec2-54-235-123-153.compute-1.amazonaws.com" (defn get-conn []
db-port 5432 (let [db-host (:server (:db env))
db-name "dbfemhppkdksfp"] db-port 5432
db-name "autoap"]
(println "envt" env)
(println (:db env))
(def conn {:classname "org.postgresql.Driver" ; must be in classpath {:classname "org.postgresql.Driver" ; must be in classpath
:ssl true #_#_:ssl true
:sslfactory "org.postgresql.ssl.NonValidatingFactory" #_#_:sslfactory "org.postgresql.ssl.NonValidatingFactory"
:subprotocol "postgresql" :subprotocol "postgresql"
:subname (str "//" db-host ":" db-port "/" db-name) :subname (str "//" db-host ":" db-port "/" db-name)
; Any additional :user "ap"
; keys are passed :password "fifteen-invoices-imported!"}))
; to the driver
; as driver-specific properties.
:user "tkilrhrhzlumol"
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"}))

View File

@@ -41,14 +41,14 @@
(defroutes unauthenticated-routes (defroutes unauthenticated-routes
(GET "/" [] (GET "/" []
(response/resource-response "index.html" {:root "public"})) (response/resource-response "index.html" {:root "public"}))
(GET "/api/oauth" {{:strs [code]} :query-params} (GET "/api/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers}
(try (try
(let [auth (-> "https://accounts.google.com/o/oauth2/token" (let [auth (-> "https://accounts.google.com/o/oauth2/token"
(http/post (http/post
{:form-params {"client_id" google-client-id {:form-params {"client_id" google-client-id
"client_secret" google-client-secret "client_secret" google-client-secret
"code" code "code" code
"redirect_uri" "http://localhost:3449/api/oauth" "redirect_uri" (str (name scheme) "://" host "/api/oauth")
"grant_type" "authorization_code"} "grant_type" "authorization_code"}
:as :json}) :as :json})
:body) :body)

View File

@@ -6,7 +6,7 @@
[auto-ap.config :as config] [auto-ap.config :as config]
[auto-ap.effects :as effects] [auto-ap.effects :as effects]
[pushy.core :as pushy] [pushy.core :as pushy]
[auto-ap.pushy :as p] [auto-ap.history :as p]
[bidi.bidi :as bidi])) [bidi.bidi :as bidi]))
(defn dev-setup [] (defn dev-setup []

View File

@@ -3,7 +3,7 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[cljs-http.client :as http] [cljs-http.client :as http]
[cljs.core.async :refer [<!]] [cljs.core.async :refer [<!]]
[auto-ap.pushy :as p] [auto-ap.history :as p]
[pushy.core :as pushy])) [pushy.core :as pushy]))
(re-frame/reg-fx (re-frame/reg-fx

View File

@@ -1,4 +1,4 @@
(ns auto-ap.pushy (ns auto-ap.history
(:require [bidi.bidi :as bidi] (:require [bidi.bidi :as bidi]
[pushy.core :as pushy] [pushy.core :as pushy]
[auto-ap.routes :as routes] [auto-ap.routes :as routes]

View File

@@ -5,5 +5,5 @@
(def login-url (def login-url
(let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com" (let [client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com"
redirect-uri "http%3A%2F%2Flocalhost%3A3449%2Fapi%2Foauth"] redirect-uri (js/encodeURI (str (.-origin (.-location js/window)) "/api/oauth"))]
(str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"))) (str "https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=" client-id "&redirect_uri=" redirect-uri "&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile")))