diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5643bb..a001514 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,8 @@ jobs: ./lein uberjar - name: Build native image run: | - ./lein native-image - # upx --lzma --best gitwerk - mv target/gitwerk gitwerk + make gitwerk-static + upx -9 gitwerk zip --junk-paths gitwerk-linux-amd64 gitwerk - name: Upload artifact uses: actions/upload-artifact@v1 @@ -64,15 +63,15 @@ jobs: JAVA_VERSION: java8 - name: Install dependencies run: | - brew install leiningen + brew install leiningen upx gu install native-image - name: Build uberjar run: | lein uberjar - name: Build native image run: | - lein native-image - mv target/gitwerk gitwerk + make + upx -9 gitwerk zip --junk-paths gitwerk-macos-amd64 gitwerk - name: Upload artifact uses: actions/upload-artifact@v1 diff --git a/Dockerfile b/Dockerfile index a69d3c3..b53144e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,10 @@ COPY src src RUN lein uberjar -COPY native-config native-config +COPY reflection.json reflection.json +COPY Makefile Makefile -RUN lein native-image +RUN make RUN mkdir -p /out/lib \ && cp $JAVA_HOME/jre/lib/amd64/libsunec.so /out/lib/ \ @@ -34,6 +35,6 @@ LABEL maintainer "rinx " RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* COPY --from=graalvm /out /gitwerk-libs -COPY --from=graalvm /gitwerk/target/gitwerk /gitwerk +COPY --from=graalvm /gitwerk/gitwerk /gitwerk CMD ["/gitwerk", "-Djava.library.path=/gitwerk-libs/lib", "-Djavax.net.ssl.trustStore=/gitwerk-libs"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3b0fe34 --- /dev/null +++ b/Makefile @@ -0,0 +1,95 @@ +XMS = 2g +XMX = 7g + +NATIVE_IMAGE_CONFIG_OUTPUT_DIR=native-config + +TARGET_JAR=target/gitwerk-0.1.0-SNAPSHOT-standalone.jar + +ADDITIONAL_OPTIONS="" + +.PHONY: all +all: gitwerk + +.PHONY: clean +clean: + rm -f gitwerk + rm -rf target + +.PHONY: profile/native-image-config +profile/native-image-config: \ + $(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \ + $(TARGET_JAR) + java -agentlib:native-image-agent=config-output-dir=$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \ + -jar $(TARGET_JAR) clone http://github.com/rinx/gitwerk + (cd gitwerk; \ + java -agentlib:native-image-agent=config-merge-dir=../$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \ + -jar ../$(TARGET_JAR) log) + (cd gitwerk; \ + java -agentlib:native-image-agent=config-merge-dir=../$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR) \ + -jar ../$(TARGET_JAR) tag) + rm -rf gitwerk + +$(NATIVE_IMAGE_CONFIG_OUTPUT_DIR): + mkdir -p $@ + +lein: + curl -o lein https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \ + && chmod a+x lein \ + && ./lein version + +gitwerk: \ + $(TARGET_JAR) + native-image \ + -jar $(TARGET_JAR) \ + -H:Name=gitwerk \ + -H:+ReportExceptionStackTraces \ + -H:Log=registerResource: \ + -H:ReflectionConfigurationFiles=reflection.json \ + --enable-url-protocols=http,https \ + --enable-all-security-services \ + -H:+JNI \ + --verbose \ + --no-fallback \ + --no-server \ + --report-unsupported-elements-at-runtime \ + --initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$$Digest \ + --initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner \ + --initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime \ + --initialize-at-build-time \ + -H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText \ + --allow-incomplete-classpath \ + -J-Dclojure.spec.skip-macros=true \ + -J-Dclojure.compiler.direct-linking=true \ + -J-Xms$(XMS) \ + -J-Xmx$(XMX) + +.PHONY: gitwerk-static +gitwerk-static: \ + $(TARGET_JAR) + native-image \ + -jar $(TARGET_JAR) \ + -H:Name=gitwerk \ + -H:+ReportExceptionStackTraces \ + -H:Log=registerResource: \ + -H:ReflectionConfigurationFiles=reflection.json \ + --enable-url-protocols=http,https \ + --enable-all-security-services \ + -H:+JNI \ + --verbose \ + --no-fallback \ + --no-server \ + --report-unsupported-elements-at-runtime \ + --initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$$Digest \ + --initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner \ + --initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime \ + --initialize-at-build-time \ + -H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText \ + --allow-incomplete-classpath \ + --static \ + -J-Dclojure.spec.skip-macros=true \ + -J-Dclojure.compiler.direct-linking=true \ + -J-Xms$(XMS) \ + -J-Xmx$(XMX) + +$(TARGET_JAR): lein src + ./lein uberjar diff --git a/native-config/jni-config.json b/native-config/jni-config.json deleted file mode 100644 index 88db970..0000000 --- a/native-config/jni-config.json +++ /dev/null @@ -1,6 +0,0 @@ -[ -{ - "name":"gitwerk.core", - "methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }] -} -] diff --git a/native-config/proxy-config.json b/native-config/proxy-config.json deleted file mode 100644 index 0d4f101..0000000 --- a/native-config/proxy-config.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/native-config/resource-config.json b/native-config/resource-config.json deleted file mode 100644 index dc94098..0000000 --- a/native-config/resource-config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "resources":[ - {"pattern":"META-INF/services/jdk.vm.ci.hotspot.HotSpotJVMCIBackendFactory"}, - {"pattern":"META-INF/services/jdk.vm.ci.services.JVMCIServiceLocator"}, - {"pattern":"clojure/core.clj"}, - {"pattern":"clojure/core/server.clj"}, - {"pattern":"clojure/core/server__init.class"}, - {"pattern":"clojure/core__init.class"}, - {"pattern":"gitwerk/core.clj"}, - {"pattern":"gitwerk/core__init.class"}, - {"pattern":"org/eclipse/jgit/internal/JGitText.properties"}, - {"pattern":"sun/net/idn/uidna.spp"}, - {"pattern":"sun/text/resources/unorm.icu"} - ] -} diff --git a/project.clj b/project.clj index c955ebb..257653b 100644 --- a/project.clj +++ b/project.clj @@ -4,36 +4,14 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.10.2-alpha1"] - [org.clojure/tools.cli "0.4.2"] - [metosin/jsonista "0.2.5"] - [camel-snake-kebab "0.4.0"] + [org.clojure/tools.cli "1.0.194"] + [cheshire "5.10.0"] + [clj-commons/clj-yaml "0.7.1"] [io.quarkus/quarkus-jgit "1.4.1.Final"] [borkdude/sci "0.0.13-alpha.17"] [org.martinklepsch/clj-http-lite "0.4.3"]] - :plugins [[io.taylorwood/lein-native-image "0.3.1"]] - :native-image {:name "gitwerk" - :opts ["-H:+ReportExceptionStackTraces" - "-H:Log=registerResource:" - "-H:ConfigurationFileDirectories=native-config" - "--enable-url-protocols=http,https" - "--enable-all-security-services" - "-H:+JNI" - "--verbose" - "--no-fallback" - "--no-server" - "--report-unsupported-elements-at-runtime" - "--initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$Digest" - "--initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner" - "--initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime" - "--initialize-at-build-time" - "-H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText" - "--allow-incomplete-classpath" - "-J-Xms2g" - "-J-Xmx7g"] - :jvm-opts ["-Dclojure.spec.skip-macros=true" - "-Dclojure.compiler.direct-linking=true"]} - :profiles {:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"] - [orchestra "2019.02.06-1"]] - :source-paths ["dev"]} - :uberjar {:aot :all + :profiles {:uberjar {:aot :all + :global-vars {*assert* false} + :jvm-opts ["-Dclojure.spec.skip-macros=true" + "-Dclojure.compiler.direct-linking=true"] :main gitwerk.core}}) diff --git a/native-config/reflect-config.json b/reflection.json similarity index 100% rename from native-config/reflect-config.json rename to reflection.json diff --git a/src/gitwerk/core.clj b/src/gitwerk/core.clj index 45e6d50..9f94789 100644 --- a/src/gitwerk/core.clj +++ b/src/gitwerk/core.clj @@ -3,8 +3,6 @@ [clojure.tools.cli :as cli] [clojure.string :as string] [clojure.pprint :as pprint] - [clojure.edn :as edn] - [clojure.java.io :as io] [gitwerk.service.runner :as runner]) (:gen-class)) diff --git a/src/gitwerk/internal/json.clj b/src/gitwerk/internal/json.clj index f6c2de5..2e4171f 100644 --- a/src/gitwerk/internal/json.clj +++ b/src/gitwerk/internal/json.clj @@ -1,15 +1,13 @@ (ns gitwerk.internal.json (:require - [jsonista.core :as jsonista] - [camel-snake-kebab.core :as csk])) - -(def json-mapper - (jsonista/object-mapper - {:pretty true - :decode-key-fn csk/->kebab-case-keyword})) + [cheshire.core :as cheshire])) (defn read-value [obj] - (jsonista/read-value obj json-mapper)) + (cheshire/parse-string obj true)) + +(defn write-json [obj] + (cheshire/generate-string obj)) (def exports - {'read-value read-value}) + {'read-value read-value + 'write-json write-json}) diff --git a/src/gitwerk/internal/yaml.clj b/src/gitwerk/internal/yaml.clj new file mode 100644 index 0000000..19e73d4 --- /dev/null +++ b/src/gitwerk/internal/yaml.clj @@ -0,0 +1,13 @@ +(ns gitwerk.internal.yaml + (:require + [clj-yaml.core :as yaml])) + +(defn read-value [obj] + (yaml/parse-string obj)) + +(defn write-yaml [obj] + (yaml/generate-string obj)) + +(def exports + {'read-value read-value + 'write-yaml write-yaml}) diff --git a/src/gitwerk/primitives.clj b/src/gitwerk/primitives.clj index 8436f5e..330d3c2 100644 --- a/src/gitwerk/primitives.clj +++ b/src/gitwerk/primitives.clj @@ -1,10 +1,12 @@ (ns gitwerk.primitives (:require - [clojure.pprint :as pprint])) + [clojure.pprint :as pprint] + [clojure.java.shell :as shell])) (defn getenv [e] (System/getenv e)) (def clj-primitives {'pprint pprint/pprint - 'getenv getenv}) + 'getenv getenv + 'sh shell/sh}) diff --git a/src/gitwerk/service/runner.clj b/src/gitwerk/service/runner.clj index b871b93..27d62ee 100644 --- a/src/gitwerk/service/runner.clj +++ b/src/gitwerk/service/runner.clj @@ -7,6 +7,7 @@ [gitwerk.internal.io :as internal.io] [gitwerk.internal.json :as internal.json] [gitwerk.internal.semver :as internal.semver] + [gitwerk.internal.yaml :as internal.yaml] [gitwerk.prelude :as prelude] [gitwerk.primitives :as primitives])) @@ -15,7 +16,8 @@ 'github internal.github/exports 'io internal.io/exports 'json internal.json/exports - 'semver internal.semver/exports}) + 'semver internal.semver/exports + 'yaml internal.yaml/exports}) (defn run [{:keys [command args options] :as ctx}]