Skip to content

Commit

Permalink
feat: add uberjar
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesmg committed Jul 6, 2023
1 parent d72ed50 commit 2062f8d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ jobs:
echo "${{ secrets.CONFIG_EDN }}" > config.edn
clojure -X:test :includes '[:integration]'
fi
- name: build uberjar
run: clojure -T:build uber
23 changes: 23 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns build
(:require [clojure.tools.build.api :as b]))

(def lib 'emqx-snowflake-sidecar)
(def version "0.0.0")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

(defn clean [_]
(b/delete {:path "target"}))

(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:src-dirs ["src"]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis
:main 'emqx.core}))
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ clj
(server/start)
```
## uberjar
```sh
clj -T:build uber
java -jar target/emqx-snowflake-sidecar-0.0.0-standalone.jar
java -jar target/emqx-snowflake-sidecar-0.0.0-standalone.jar -D taoensso.timbre.config.edn='{:min-level :info}'
```
## testing
```sh
Expand Down
10 changes: 8 additions & 2 deletions src/emqx/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[emqx.channel :as chan]
[emqx.config :as config]
[emqx.http :as http-server]
[taoensso.timbre :as log]))
[taoensso.timbre :as log])
(:gen-class))

(defn -main
[& args]
Expand All @@ -25,4 +26,9 @@
(chan/start-client client)
(doseq [chan-params channels]
(chan/ensure-streaming-agent app-name chan-params))
(http-server/start server)))
(try
(http-server/start (assoc server :join? true))
(catch Exception e
(println (.getMessage e))
(.printStackTrace e)
(System/exit 1)))))
13 changes: 8 additions & 5 deletions src/emqx/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,21 @@
{::http/routes routes
::http/request-logger (interceptor log-request)
::http/type :jetty
;; FIXME: for repl
::http/join? false
::http/join? (get params :join? false)
::http/host (get params :host "0.0.0.0")
::http/port (get params :port 9099)}))

(defn start
[params]
(http/start (create-server params)))

(defonce server (atom nil))

(defn start
(defn start-dev
[params]
(reset! server (http/start (create-server params))))

(defn restart
(defn restart-dev
[params]
(swap! server http/stop)
(reset! server (start params)))
(reset! server (start-dev params)))

0 comments on commit 2062f8d

Please sign in to comment.