-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.edn
132 lines (108 loc) · 4.42 KB
/
bb.edn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{:tasks
{:requires ([clojure.edn :as edn]
[clojure.string :as str])
:init
(do
(defn exit!
([status]
(System/exit status))
([status msg]
(println msg)
(System/exit status)))
(defn parse-args
"Parse a seq of args into a map with edn data"
([] (parse-args *command-line-args*))
([args]
(let [parse-arg-fn (fn [x] (some-> x str/trim edn/read-string))
on-ex-fn (fn [ex] (exit! -1 (str "Error parsing cli args: " (ex-message ex))))]
(->> args
(mapv parse-arg-fn)
(apply hash-map)
(parse-args on-ex-fn))))
([on-ex-fn args]
(try
(cond
(map? args) args
(and (sequential? args)
(even? (count args))) (into {} (for [[k v] (partition 2 args)]
[(edn/read-string k) v]))
:else (on-ex-fn (ex-info "Even number of args required"
{:args args :count (count args)})))
(catch Throwable t
(on-ex-fn t))))))
clean
{:doc "Cleans up any build artifacts"
:task (shell "clojure -T:build clean")}
compile:clj
{:doc "Compiles the Clojure files"
:task (shell "clojure -T:build compile-clj")}
build:check
{:doc "Checks that source compiles."
:depends [clean compile:clj]}
build:jar
{:doc "Builds a jar file"
:task (shell "clojure -T:build jar")}
build:uberjar
{:doc "Builds a jar file"
:task (shell "clojure -T:build uber")}
build:uberjar:gcp
{:doc "Builds a jar file"
:task (shell "clojure -T:gcp:build uber :aliases [:gcp]")}
build:docker-image
{:doc "Builds a docker image. args: `:docker/registry` `:docker/image-name` and `:docker/image-tag`"
:task (let [{:keys [docker/registry
docker/image-name
docker/image-tag]
:or {image-name "kaiao"
image-tag "latest"
registry "docker.io/xfthhxk"}} (parse-args *command-line-args*)
image (format "%s/%s:%s" registry image-name image-tag)
docker-cmd (str "docker build -t " image " .")]
(println "docker cmd: " docker-cmd)
(shell docker-cmd)
(println "Docker image created: " image))}
build:docker-image:gcp
{:doc "Builds a docker image for GCP using IAM for Cloud SQL access."
:depends [build:uberjar:gcp build:docker-image]}
build:native-image
{:doc "Builds a native image"
:task (shell "native-image --no-fallback -jar target/kaiao-uber.jar")}
build:gen-native-image-config
{:doc "Builds a native image config by running the service with the agent"
:task (shell "java -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar target/kaiao-uber.jar")}
install
{:doc "Install into local Maven repo cache"
:task (shell "clojure -T:build install")}
deploy
{:doc "Deploy to clojars."
:depends [build:check build:jar]
:task (shell "clojure -T:build deploy")}
dev:cider
{:doc "Runs the repl"
:task (shell "clj -M:dev:test:flyway:debug:cider")}
test
{:doc "Runs clojure tests"
:task (shell "clojure -M:dev:flyway:test default")}
test:ff
{:doc "Runs clojure tests stopping on first failure."
:task (shell "clojure -M:dev:flyway:test default --fail-fast")}
test:focus
{:doc "Runs a specific clojure tests referenced by namespace or fully qualified var."
:task (let [named-test (first *command-line-args*)]
(when-not named-test
(exit! 1 "no namespace or fully qualified var specified"))
(shell (str "clojure -M:dev:test --focus " named-test)))}
db:migrate!
{:doc "Migrates the database using the KAIAO_DB_URL, KAIAO_DB_USER and KAIAO_DB_PASSWORD env params"
:task (shell "clojure -X:flyway flyway/migrate!")}
db:clean!
{:doc "Migrates the database using the KAIAO_DB_URL, KAIAO_DB_USER and KAIAO_DB_PASSWORD env params"
:task (shell "clojure -X:flyway flyway/clean!")}
kaiao:create-project!
{:doc "Add an entry to the projects table. Required keys :id, :name and :domain. Required ENV vars KAIAO_DB_URL, KAIAO_DB_USER and KAIAO_DB_PASSWORD."
:task (let [cmd (str "clojure -X kaiao.main/create-project! "
(->> *command-line-args*
(map (fn [s] (str \' s \')))
(str/join " ")))]
(prn cmd)
(shell cmd))}}}