get docker uberjar working
This commit is contained in:
parent
4acc4e2201
commit
c28c398a14
9 changed files with 91 additions and 27 deletions
17
Dockerfile
17
Dockerfile
|
|
@ -13,21 +13,17 @@
|
||||||
# it uses alpine for a small image
|
# it uses alpine for a small image
|
||||||
FROM clojure:temurin-21-tools-deps-alpine AS jre-build
|
FROM clojure:temurin-21-tools-deps-alpine AS jre-build
|
||||||
|
|
||||||
ENV TAILWIND_VERSION=v3.2.4
|
|
||||||
|
|
||||||
# Install the missing packages and applications in a single layer
|
# Install the missing packages and applications in a single layer
|
||||||
RUN apk add curl rlwrap && curl -L -o /usr/local/bin/tailwindcss \
|
RUN apk add curl rlwrap
|
||||||
https://github.com/tailwindlabs/tailwindcss/releases/download/$TAILWIND_VERSION/tailwindcss-linux-x64 \
|
|
||||||
&& chmod +x /usr/local/bin/tailwindcss
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY deps.edn ./
|
||||||
|
RUN clj -P
|
||||||
|
COPY build.clj config.edn ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY dev ./dev
|
|
||||||
COPY resources ./resources
|
|
||||||
COPY deps.edn .
|
|
||||||
|
|
||||||
# construct the application jar
|
# construct the application jar
|
||||||
RUN clj -M:dev uberjar && cp target/jar/app.jar . && rm -r target
|
RUN clj -T:build uber && cp target/snippets-standalone.jar ./app.jar && rm -r target
|
||||||
|
|
||||||
# This stage (see multi-stage builds) is a bare Java container
|
# This stage (see multi-stage builds) is a bare Java container
|
||||||
# copy over the uberjar from the builder image and run the application
|
# copy over the uberjar from the builder image and run the application
|
||||||
|
|
@ -36,11 +32,12 @@ WORKDIR /app
|
||||||
|
|
||||||
# Take the uberjar from the base image and put it in the final image
|
# Take the uberjar from the base image and put it in the final image
|
||||||
COPY --from=jre-build /app/app.jar /app/app.jar
|
COPY --from=jre-build /app/app.jar /app/app.jar
|
||||||
|
COPY --from=jre-build /app/config.edn /app/
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# By default, run in PROD profile
|
# By default, run in PROD profile
|
||||||
ENV BIFF_PROFILE=prod
|
# ENV BIFF_PROFILE=prod
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=8080
|
ENV PORT=8080
|
||||||
CMD ["/opt/java/openjdk/bin/java", "-XX:-OmitStackTraceInFastThrow", "-XX:+CrashOnOutOfMemoryError", "-jar", "app.jar"]
|
CMD ["/opt/java/openjdk/bin/java", "-XX:-OmitStackTraceInFastThrow", "-XX:+CrashOnOutOfMemoryError", "-jar", "app.jar"]
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,19 @@
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
".git"
|
".git"
|
||||||
]
|
],
|
||||||
|
"size": 0.0006971359252929688,
|
||||||
|
"filesCount": 5,
|
||||||
|
"proxy": {
|
||||||
|
"bypassProxy": "",
|
||||||
|
"enabled": false,
|
||||||
|
"auth": {
|
||||||
|
"enabled": false,
|
||||||
|
"username": "",
|
||||||
|
"password": ""
|
||||||
|
},
|
||||||
|
"port": null,
|
||||||
|
"hostname": "",
|
||||||
|
"protocol": "http"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
3
bruno/CodeSnippets/environments/homelab.bru
Normal file
3
bruno/CodeSnippets/environments/homelab.bru
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
vars:secret [
|
||||||
|
host
|
||||||
|
]
|
||||||
|
|
@ -5,14 +5,14 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{host}}/api/snippet?limit=10&skip=10
|
url: 192.168.1.157:29406/api/snippet?limit=4&skip=0
|
||||||
body: none
|
body: none
|
||||||
auth: none
|
auth: none
|
||||||
}
|
}
|
||||||
|
|
||||||
params:query {
|
params:query {
|
||||||
limit: 10
|
limit: 4
|
||||||
skip: 10
|
skip: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
|
|
|
||||||
25
build.clj
Normal file
25
build.clj
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
(ns build
|
||||||
|
(:require [clojure.tools.build.api :as b]))
|
||||||
|
|
||||||
|
(def lib 'snippets)
|
||||||
|
|
||||||
|
(def class-dir "target/classes")
|
||||||
|
(def uber-file (format "target/%s-standalone.jar" (name lib)))
|
||||||
|
|
||||||
|
;; delay to defer side effects (artifact downloads)
|
||||||
|
(def basis (delay (b/create-basis {:project "deps.edn"})))
|
||||||
|
|
||||||
|
(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
|
||||||
|
:ns-compile '[snippets.main]
|
||||||
|
:class-dir class-dir})
|
||||||
|
(b/uber {:class-dir class-dir
|
||||||
|
:uber-file uber-file
|
||||||
|
:basis @basis
|
||||||
|
:main 'snippets.main}))
|
||||||
9
deps.edn
9
deps.edn
|
|
@ -10,6 +10,9 @@
|
||||||
org.postgresql/postgresql {:mvn/version "42.7.6"}
|
org.postgresql/postgresql {:mvn/version "42.7.6"}
|
||||||
frontmatter/frontmatter {:mvn/version "0.0.1"}
|
frontmatter/frontmatter {:mvn/version "0.0.1"}
|
||||||
|
|
||||||
|
;; environment variables
|
||||||
|
environ/environ {:mvn/version "1.2.0"}
|
||||||
|
|
||||||
;; schema validation
|
;; schema validation
|
||||||
metosin/malli {:mvn/version "0.18.0"}
|
metosin/malli {:mvn/version "0.18.0"}
|
||||||
|
|
||||||
|
|
@ -22,7 +25,11 @@
|
||||||
;; convenient package of "default" middleware:
|
;; convenient package of "default" middleware:
|
||||||
;; ring/ring-defaults {:mvn/version "0.5.0"}
|
;; ring/ring-defaults {:mvn/version "0.5.0"}
|
||||||
|
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}}}
|
org.clojure/clojure {:mvn/version "1.12.1"}}
|
||||||
|
:aliases
|
||||||
|
{;; Run with clj -T:build function-in-build
|
||||||
|
:build {:deps {io.github.clojure/tools.build {:git/tag "v0.10.9" :git/sha "e405aac"}}
|
||||||
|
:ns-default build}}}
|
||||||
|
|
||||||
;; :aliases
|
;; :aliases
|
||||||
;; {:dev {:extra-deps {com.biffweb/tasks {:git/url "https://github.com/jacobobryant/biff", :git/sha "1570ccc", :git/tag "v1.8.29", :deps/root "libs/tasks"}}
|
;; {:dev {:extra-deps {com.biffweb/tasks {:git/url "https://github.com/jacobobryant/biff", :git/sha "1570ccc", :git/tag "v1.8.29", :deps/root "libs/tasks"}}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
[ring.adapter.jetty :as jetty]
|
[ring.adapter.jetty :as jetty]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[snippets.db :as db]
|
[snippets.db :as db]
|
||||||
|
[snippets.config :as config]
|
||||||
[muuntaja.middleware :as mm]
|
[muuntaja.middleware :as mm]
|
||||||
[ring.middleware.params]
|
[ring.middleware.params]
|
||||||
[reitit.ring :as rr]))
|
[reitit.ring :as rr]))
|
||||||
|
|
@ -43,9 +44,15 @@
|
||||||
;; (def app
|
;; (def app
|
||||||
;; ;; use #' prefix for REPL-friendly code -- see note below
|
;; ;; use #' prefix for REPL-friendly code -- see note below
|
||||||
;; (wrap-defaults #'app-routes site-defaults))
|
;; (wrap-defaults #'app-routes site-defaults))
|
||||||
|
;;
|
||||||
|
(defn run-server []
|
||||||
|
(let [jetty-config (:jetty (config/get-config))
|
||||||
|
port (:port jetty-config)
|
||||||
|
host (:host jetty-config)]
|
||||||
|
(jetty/run-jetty #'app {:port port :host host})))
|
||||||
|
|
||||||
(defn -main []
|
(defn -main []
|
||||||
(jetty/run-jetty #'app {:port 3000}))
|
(run-server))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
;; evaluate this def form to start the webapp via the REPL:
|
;; evaluate this def form to start the webapp via the REPL:
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
(ns snippets.config)
|
(ns snippets.config
|
||||||
|
(:require [environ.core :refer [env]]))
|
||||||
|
|
||||||
;; (require '[environ.core :refer [env]])
|
(defn- static-config [] (read-string (slurp "config.edn")))
|
||||||
(defn get-config [] (read-string (slurp "config.edn")))
|
|
||||||
|
|
||||||
;; (def config
|
(defn assoc-in-not-nil [config keys value]
|
||||||
;; (merge
|
(if (nil? value)
|
||||||
;; (read-string (slurp "config.edn"))
|
config
|
||||||
;; {:db {:host (env :db-host)
|
(assoc-in config keys value)))
|
||||||
;; :port (Integer. (env :db-port))
|
|
||||||
;; :user (env :db-user)
|
(defn safe-parse-int [value]
|
||||||
;; :password (env :db-password)
|
(if (nil? value) nil (Integer/parseInt value)))
|
||||||
;; :dbname (env :db-name)}}))
|
|
||||||
|
(defn get-config []
|
||||||
|
(->
|
||||||
|
(static-config)
|
||||||
|
(assoc-in-not-nil [:jetty :host] (env :host))
|
||||||
|
(assoc-in-not-nil [:jetty :port] (safe-parse-int (env :port)))))
|
||||||
|
|
|
||||||
6
src/snippets/main.clj
Normal file
6
src/snippets/main.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
(ns snippets.main
|
||||||
|
(:require [snippets.api :as api])
|
||||||
|
(:gen-class))
|
||||||
|
|
||||||
|
(defn -main []
|
||||||
|
(api/run-server))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue