mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 22:22:43 -05:00
♻️ Refactor backend bundle build process.
Now the final artifact is a single, compiled uberjar. It considerably improves startup speed.
This commit is contained in:
parent
9488a9a1ad
commit
c48da3d316
7 changed files with 59 additions and 76 deletions
37
backend/build.clj
Normal file
37
backend/build.clj
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
(ns build
|
||||||
|
(:refer-clojure :exclude [compile])
|
||||||
|
(:require
|
||||||
|
[clojure.tools.build.api :as b]
|
||||||
|
[clojure.java.io]))
|
||||||
|
|
||||||
|
(def class-dir "target/classes")
|
||||||
|
(def basis (b/create-basis {:project "deps.edn"}))
|
||||||
|
(def jar-file "target/penpot.jar")
|
||||||
|
|
||||||
|
(defn clean [_]
|
||||||
|
(b/delete {:path "target"}))
|
||||||
|
|
||||||
|
(defn jar [_]
|
||||||
|
(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 jar-file
|
||||||
|
:main 'clojure.main
|
||||||
|
:basis basis}))
|
||||||
|
|
||||||
|
(defn compile [_]
|
||||||
|
(b/javac
|
||||||
|
{:src-dirs ["dev/java"]
|
||||||
|
:class-dir class-dir
|
||||||
|
:basis basis
|
||||||
|
:exclude [#"com.google.*" #"goog.*"]
|
||||||
|
:javac-opts ["-source" "11" "-target" "11"]}))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<Configuration status="info" monitorInterval="60">
|
<Configuration status="info" monitorInterval="60">
|
||||||
<Appenders>
|
<Appenders>
|
||||||
<Console name="console" target="SYSTEM_OUT">
|
<Console name="console" target="SYSTEM_OUT">
|
||||||
<PatternLayout pattern="[%d{YYYY-MM-dd HH:mm:ss.SSS}] [%t] %level{length=1} %logger{36} - %msg%n"/>
|
<PatternLayout pattern="[%d{YYYY-MM-dd HH:mm:ss.SSS}] %level{length=1} %logger{36} - %msg%n"/>
|
||||||
</Console>
|
</Console>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
|
|
||||||
|
|
|
@ -1,79 +1,20 @@
|
||||||
#!/usr/bin/env bb
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
CURRENT_VERSION=$1;
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
;;
|
|
||||||
;; Copyright (c) UXBOX Labs SL
|
|
||||||
|
|
||||||
(ns build
|
set -ex
|
||||||
(:require
|
|
||||||
[clojure.string :as str]
|
|
||||||
[clojure.java.io :as io]
|
|
||||||
[clojure.pprint :refer [pprint]]
|
|
||||||
[babashka.fs :as fs]
|
|
||||||
[babashka.process :refer [$ check]]))
|
|
||||||
|
|
||||||
(defn split-cp
|
rm -rf target;
|
||||||
[data]
|
mkdir -p target/classes;
|
||||||
(str/split data #":"))
|
mkdir -p target/dist;
|
||||||
|
echo "$CURRENT_VERSION" > target/classes/version.txt;
|
||||||
|
|
||||||
(def classpath
|
clojure -T:build jar;
|
||||||
(->> ($ clojure -Spath)
|
mv target/penpot.jar target/dist/penpot.jar
|
||||||
(check)
|
cp scripts/run.template.sh target/dist/run.sh;
|
||||||
(:out)
|
cp scripts/manage.template.sh target/dist/manage.sh;
|
||||||
(slurp)
|
chmod +x target/dist/run.sh;
|
||||||
(split-cp)
|
chmod +x target/dist/manage.sh;
|
||||||
(map str/trim)))
|
|
||||||
|
|
||||||
(def classpath-jars
|
|
||||||
(let [xfm (filter #(str/ends-with? % ".jar"))]
|
|
||||||
(into #{} xfm classpath)))
|
|
||||||
|
|
||||||
(def classpath-paths
|
|
||||||
(let [xfm (comp (remove #(str/ends-with? % ".jar"))
|
|
||||||
(filter #(.isDirectory (io/file %))))]
|
|
||||||
(into #{} xfm classpath)))
|
|
||||||
|
|
||||||
(def version
|
|
||||||
(or (first *command-line-args*) "%version%"))
|
|
||||||
|
|
||||||
;; Clean previous dist
|
|
||||||
(-> ($ rm -rf "./target/dist") check)
|
|
||||||
|
|
||||||
;; Create a new dist
|
|
||||||
(-> ($ mkdir -p "./target/dist/deps") check)
|
|
||||||
|
|
||||||
;; Copy all jar deps into dist
|
|
||||||
(run! (fn [item] (-> ($ cp ~item "./target/dist/deps/") check)) classpath-jars)
|
|
||||||
|
|
||||||
;; Create the application jar
|
|
||||||
(spit "./target/dist/version.txt" version)
|
|
||||||
|
|
||||||
(-> ($ jar cvf "./target/dist/deps/app.jar" -C ~(first classpath-paths) ".") check)
|
|
||||||
(-> ($ jar uvf "./target/dist/deps/app.jar" -C "./target/dist" "version.txt") check)
|
|
||||||
(run! (fn [item]
|
|
||||||
(-> ($ jar uvf "./target/dist/deps/app.jar" -C ~item ".") check))
|
|
||||||
(rest classpath-paths))
|
|
||||||
|
|
||||||
;; Copy logging configuration
|
|
||||||
(-> ($ cp "./resources/log4j2.xml" "./target/dist/") check)
|
|
||||||
|
|
||||||
;; Create classpath file
|
|
||||||
(let [jars (->> (into ["app.jar"] classpath-jars)
|
|
||||||
(map fs/file-name)
|
|
||||||
(map #(fs/path "deps" %))
|
|
||||||
(map str))]
|
|
||||||
(spit "./target/dist/classpath" (str/join ":" jars)))
|
|
||||||
|
|
||||||
;; Copy run script template
|
|
||||||
(-> ($ cp "./scripts/run.template.sh" "./target/dist/run.sh") check)
|
|
||||||
|
|
||||||
;; Copy run script template
|
|
||||||
(-> ($ cp "./scripts/manage.template.sh" "./target/dist/manage.sh") check)
|
|
||||||
|
|
||||||
;; Add exec permissions to scripts.
|
|
||||||
(-> ($ chmod +x "./target/dist/run.sh") check)
|
|
||||||
(-> ($ chmod +x "./target/dist/manage.sh") check)
|
|
||||||
|
|
||||||
nil
|
|
||||||
|
|
|
@ -16,4 +16,4 @@ if [ -f ./environ ]; then
|
||||||
source ./environ
|
source ./environ
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec $JAVA_CMD $JVM_OPTS -classpath $(cat classpath) -Dlog4j2.configurationFile=./log4j2.xml clojure.main -m app.cli.manage "$@"
|
exec $JAVA_CMD $JVM_OPTS -jar penpot.jar -m app.cli.manage "$@"
|
||||||
|
|
|
@ -17,4 +17,4 @@ if [ -f ./environ ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
exec $JAVA_CMD $JVM_OPTS -classpath "$(cat classpath)" -Dlog4j2.configurationFile=./log4j2.xml "$@" clojure.main -m app.main
|
exec $JAVA_CMD $JVM_OPTS "$@" -jar penpot.jar -m app.main
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[integrant.core :as ig]))
|
[integrant.core :as ig])
|
||||||
|
(:gen-class))
|
||||||
|
|
||||||
(def system-config
|
(def system-config
|
||||||
{:app.db/pool
|
{:app.db/pool
|
||||||
|
|
|
@ -207,6 +207,10 @@ function usage {
|
||||||
}
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
|
version)
|
||||||
|
print-current-version
|
||||||
|
;;
|
||||||
|
|
||||||
## devenv related commands
|
## devenv related commands
|
||||||
pull-devenv)
|
pull-devenv)
|
||||||
pull-devenv ${@:2};
|
pull-devenv ${@:2};
|
||||||
|
|
Loading…
Add table
Reference in a new issue