Add build options including Docker

This commit is contained in:
@s.roertgen 2024-12-31 11:23:44 +01:00
parent 26bafba851
commit d3e60e0179
3 changed files with 75 additions and 2 deletions

32
Dockerfile Normal file
View file

@ -0,0 +1,32 @@
# Stage 1: Build the Uberjar
FROM clojure:tools-deps-bullseye AS builder
# Set environment variables
ENV APP_HOME=/usr/src/app
WORKDIR $APP_HOME
# Copy project files
COPY deps.edn .
COPY build.clj .
COPY src ./src
COPY resources ./resources
# Install Git (required for `git-count-revs` in your build script)
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
# Run the build script to create the uberjar
RUN clojure -T:build uber
# Stage 2: Run the Uberjar in a minimal image
FROM openjdk:17-jdk-slim
# Set environment variables
ENV APP_HOME=/usr/src/app
WORKDIR $APP_HOME
# Copy the uberjar from the builder stage
COPY --from=builder /usr/src/app/target/app.jar app.jar
# Define the entrypoint
ENTRYPOINT ["java", "-jar", "app.jar"]

39
build.clj Normal file
View file

@ -0,0 +1,39 @@
(ns build
(:require [clojure.tools.build.api :as b]))
(def lib 'app)
(def version (format "1.2.%s" (b/git-count-revs nil)))
(def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(def uber-file "target/app.jar")
;; delay to defer side effects (artifact downloads)
(def basis (delay (b/create-basis {:project "deps.edn"})))
(defn clean [_]
(b/delete {:path "target"}))
(defn jar [_]
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis @basis
:src-dirs ["src"]})
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file}))
(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/compile-clj {:basis @basis
:ns-compile '[typesense-indexer.system] ;; FIXME adjust here
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis @basis
:main 'typesense-indexer.system})) ;; FIXME adjust here

View file

@ -1,4 +1,4 @@
{:pahts ["src" "resources"]
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}
org.clojure/core.async {:mvn/version "1.6.673"}
com.stuartsierra/component {:mvn/version "1.1.0"}
@ -6,4 +6,6 @@
http-kit/http-kit {:mvn/version "2.8.0"}
net.clojars.laoc/nostr {:local/root "/home/laoc/coding/nostr-clj"}
aero/aero {:mvn/version "1.1.6"}
cheshire/cheshire {:mvn/version "5.10.0"}}}
cheshire/cheshire {:mvn/version "5.10.0"}}
:aliases {:build {:extra-deps {io.github.clojure/tools.build {:mvn/version "0.9.3"}}
:ns-default build}}}