atomisthq / jibbit

Dockerless Clojure Image builds using deps.edn
Eclipse Public License 1.0
112 stars 9 forks source link

There is no way to provide `$JAVA_OPTS` in the default `entrypoint` #23

Open skydread1 opened 7 months ago

skydread1 commented 7 months ago

Problem

In entry-point, the following is used for the entrypoint:

["java" "-Dclojure.main.report=stderr" "-Dfile.encoding=UTF-8"] and the -cp and -m args are concatenated to it.

It is common to start an app with custom JAVA_OPTS.

In the current implementation, the only way to do so seems to provide a custom entrypoint script such as:

java $JAVA_OPTS -cp ... clojure.main -m my.app.core

But providing the value of -cp is not ideal as it can be very long since jibbit does not provide a way to generate a uberjar.

Suggestion

In my case I would like entry-point to look like this for instance:

(defn entry-point
  [{:keys [basis aot jar-name main working-dir]}]
  (->> (concat
        ["java ${JAVA_OPTS} -Dclojure.main.report=stderr -Dfile.encoding=UTF-8"]
        (-> basis :argmap :jvm-opts)
        (if aot
          ["-jar" jar-name]
          (concat
           ["-cp" (container-cp basis working-dir) "clojure.main"]
           (if-let [main-opts (-> basis :argmap :main-opts)]
             main-opts
             ["-m" (pr-str main)]))))
       (interpose " ")
       (apply str)
       (conj ["sh" "-c"])))

Maybe the user could provide his own custom-entry-point in the jib config?

And in jib-build we could replace:

(.setEntrypoint (entry-point c))

by

(.setEntrypoint ((or (load-entry-point custom-entry-point) entry-point) c)) ;; with custom-entry-point the eventual custom fn provided in jib.edn for instance

Let me know if it makes sense.