Skip to content

Commit 9aff403

Browse files
authored
[patch] Reduce binary size (#7)
* ♻️ remove native-config dir Signed-off-by: Rintaro Okamura <[email protected]> * ➕ Use cheshire instead of jsonista Signed-off-by: Rintaro Okamura <[email protected]> * 🔥 remove csk Signed-off-by: Rintaro Okamura <[email protected]> * 🔧 Add uberjar options Signed-off-by: Rintaro Okamura <[email protected]> * 🔧 Fix Signed-off-by: Rintaro Okamura <[email protected]> * 🔧 Use Makefile for native-image build Signed-off-by: Rintaro Okamura <[email protected]> * ♻️ remove redundant imports Signed-off-by: Rintaro Okamura <[email protected]> * ✨ Add yaml Signed-off-by: Rintaro Okamura <[email protected]> * ⚡ Add upx to compress binaries Signed-off-by: Rintaro Okamura <[email protected]> * 🐛 Fix static Signed-off-by: Rintaro Okamura <[email protected]> * ✨ add sh func Signed-off-by: Rintaro Okamura <[email protected]>
1 parent be6fae2 commit 9aff403

File tree

13 files changed

+138
-75
lines changed

13 files changed

+138
-75
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ jobs:
3434
./lein uberjar
3535
- name: Build native image
3636
run: |
37-
./lein native-image
38-
# upx --lzma --best gitwerk
39-
mv target/gitwerk gitwerk
37+
make gitwerk-static
38+
upx -9 gitwerk
4039
zip --junk-paths gitwerk-linux-amd64 gitwerk
4140
- name: Upload artifact
4241
uses: actions/upload-artifact@v1
@@ -64,15 +63,15 @@ jobs:
6463
JAVA_VERSION: java8
6564
- name: Install dependencies
6665
run: |
67-
brew install leiningen
66+
brew install leiningen upx
6867
gu install native-image
6968
- name: Build uberjar
7069
run: |
7170
lein uberjar
7271
- name: Build native image
7372
run: |
74-
lein native-image
75-
mv target/gitwerk gitwerk
73+
make
74+
upx -9 gitwerk
7675
zip --junk-paths gitwerk-macos-amd64 gitwerk
7776
- name: Upload artifact
7877
uses: actions/upload-artifact@v1

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ COPY src src
1919

2020
RUN lein uberjar
2121

22-
COPY native-config native-config
22+
COPY reflection.json reflection.json
23+
COPY Makefile Makefile
2324

24-
RUN lein native-image
25+
RUN make
2526

2627
RUN mkdir -p /out/lib \
2728
&& cp $JAVA_HOME/jre/lib/amd64/libsunec.so /out/lib/ \
@@ -34,6 +35,6 @@ LABEL maintainer "rinx <[email protected]>"
3435
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
3536

3637
COPY --from=graalvm /out /gitwerk-libs
37-
COPY --from=graalvm /gitwerk/target/gitwerk /gitwerk
38+
COPY --from=graalvm /gitwerk/gitwerk /gitwerk
3839

3940
CMD ["/gitwerk", "-Djava.library.path=/gitwerk-libs/lib", "-Djavax.net.ssl.trustStore=/gitwerk-libs"]

Makefile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
XMS = 2g
2+
XMX = 7g
3+
4+
NATIVE_IMAGE_CONFIG_OUTPUT_DIR=native-config
5+
6+
TARGET_JAR=target/gitwerk-0.1.0-SNAPSHOT-standalone.jar
7+
8+
ADDITIONAL_OPTIONS=""
9+
10+
.PHONY: all
11+
all: gitwerk
12+
13+
.PHONY: clean
14+
clean:
15+
rm -f gitwerk
16+
rm -rf target
17+
18+
.PHONY: profile/native-image-config
19+
profile/native-image-config: \
20+
$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \
21+
$(TARGET_JAR)
22+
java -agentlib:native-image-agent=config-output-dir=$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \
23+
-jar $(TARGET_JAR) clone http://github.com/rinx/gitwerk
24+
(cd gitwerk; \
25+
java -agentlib:native-image-agent=config-merge-dir=../$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \
26+
-jar ../$(TARGET_JAR) log)
27+
(cd gitwerk; \
28+
java -agentlib:native-image-agent=config-merge-dir=../$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \
29+
-jar ../$(TARGET_JAR) tag)
30+
rm -rf gitwerk
31+
32+
$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR):
33+
mkdir -p $@
34+
35+
lein:
36+
curl -o lein https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
37+
&& chmod a+x lein \
38+
&& ./lein version
39+
40+
gitwerk: \
41+
$(TARGET_JAR)
42+
native-image \
43+
-jar $(TARGET_JAR) \
44+
-H:Name=gitwerk \
45+
-H:+ReportExceptionStackTraces \
46+
-H:Log=registerResource: \
47+
-H:ReflectionConfigurationFiles=reflection.json \
48+
--enable-url-protocols=http,https \
49+
--enable-all-security-services \
50+
-H:+JNI \
51+
--verbose \
52+
--no-fallback \
53+
--no-server \
54+
--report-unsupported-elements-at-runtime \
55+
--initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$$Digest \
56+
--initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner \
57+
--initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime \
58+
--initialize-at-build-time \
59+
-H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText \
60+
--allow-incomplete-classpath \
61+
-J-Dclojure.spec.skip-macros=true \
62+
-J-Dclojure.compiler.direct-linking=true \
63+
-J-Xms$(XMS) \
64+
-J-Xmx$(XMX)
65+
66+
.PHONY: gitwerk-static
67+
gitwerk-static: \
68+
$(TARGET_JAR)
69+
native-image \
70+
-jar $(TARGET_JAR) \
71+
-H:Name=gitwerk \
72+
-H:+ReportExceptionStackTraces \
73+
-H:Log=registerResource: \
74+
-H:ReflectionConfigurationFiles=reflection.json \
75+
--enable-url-protocols=http,https \
76+
--enable-all-security-services \
77+
-H:+JNI \
78+
--verbose \
79+
--no-fallback \
80+
--no-server \
81+
--report-unsupported-elements-at-runtime \
82+
--initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$$Digest \
83+
--initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner \
84+
--initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime \
85+
--initialize-at-build-time \
86+
-H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText \
87+
--allow-incomplete-classpath \
88+
--static \
89+
-J-Dclojure.spec.skip-macros=true \
90+
-J-Dclojure.compiler.direct-linking=true \
91+
-J-Xms$(XMS) \
92+
-J-Xmx$(XMX)
93+
94+
$(TARGET_JAR): lein src
95+
./lein uberjar

native-config/jni-config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

native-config/proxy-config.json

Lines changed: 0 additions & 2 deletions
This file was deleted.

native-config/resource-config.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

project.clj

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,14 @@
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies [[org.clojure/clojure "1.10.2-alpha1"]
7-
[org.clojure/tools.cli "0.4.2"]
8-
[metosin/jsonista "0.2.5"]
9-
[camel-snake-kebab "0.4.0"]
7+
[org.clojure/tools.cli "1.0.194"]
8+
[cheshire "5.10.0"]
9+
[clj-commons/clj-yaml "0.7.1"]
1010
[io.quarkus/quarkus-jgit "1.4.1.Final"]
1111
[borkdude/sci "0.0.13-alpha.17"]
1212
[org.martinklepsch/clj-http-lite "0.4.3"]]
13-
:plugins [[io.taylorwood/lein-native-image "0.3.1"]]
14-
:native-image {:name "gitwerk"
15-
:opts ["-H:+ReportExceptionStackTraces"
16-
"-H:Log=registerResource:"
17-
"-H:ConfigurationFileDirectories=native-config"
18-
"--enable-url-protocols=http,https"
19-
"--enable-all-security-services"
20-
"-H:+JNI"
21-
"--verbose"
22-
"--no-fallback"
23-
"--no-server"
24-
"--report-unsupported-elements-at-runtime"
25-
"--initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$Digest"
26-
"--initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner"
27-
"--initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime"
28-
"--initialize-at-build-time"
29-
"-H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText"
30-
"--allow-incomplete-classpath"
31-
"-J-Xms2g"
32-
"-J-Xmx7g"]
33-
:jvm-opts ["-Dclojure.spec.skip-macros=true"
34-
"-Dclojure.compiler.direct-linking=true"]}
35-
:profiles {:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"]
36-
[orchestra "2019.02.06-1"]]
37-
:source-paths ["dev"]}
38-
:uberjar {:aot :all
13+
:profiles {:uberjar {:aot :all
14+
:global-vars {*assert* false}
15+
:jvm-opts ["-Dclojure.spec.skip-macros=true"
16+
"-Dclojure.compiler.direct-linking=true"]
3917
:main gitwerk.core}})
File renamed without changes.

src/gitwerk/core.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[clojure.tools.cli :as cli]
44
[clojure.string :as string]
55
[clojure.pprint :as pprint]
6-
[clojure.edn :as edn]
7-
[clojure.java.io :as io]
86
[gitwerk.service.runner :as runner])
97
(:gen-class))
108

src/gitwerk/internal/json.clj

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
(ns gitwerk.internal.json
22
(:require
3-
[jsonista.core :as jsonista]
4-
[camel-snake-kebab.core :as csk]))
5-
6-
(def json-mapper
7-
(jsonista/object-mapper
8-
{:pretty true
9-
:decode-key-fn csk/->kebab-case-keyword}))
3+
[cheshire.core :as cheshire]))
104

115
(defn read-value [obj]
12-
(jsonista/read-value obj json-mapper))
6+
(cheshire/parse-string obj true))
7+
8+
(defn write-json [obj]
9+
(cheshire/generate-string obj))
1310

1411
(def exports
15-
{'read-value read-value})
12+
{'read-value read-value
13+
'write-json write-json})

0 commit comments

Comments
 (0)