From e503f8edd4741bd23e91c72d5a1aa072f9d2385e Mon Sep 17 00:00:00 2001 From: bom Date: Tue, 2 Jul 2024 15:04:57 +0200 Subject: [PATCH] Refactor main to use main-cm --- project.clj | 13 ++++++----- shadow-cljs.edn | 2 +- src/main/clj/dda/c4k_shynet/uberjar.clj | 2 +- src/main/cljc/dda/c4k_shynet/core.cljc | 18 +++++---------- src/main/cljs/dda/c4k_shynet/browser.cljs | 27 ++++++++++++++--------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/project.clj b/project.clj index 5c4418d..fe8a20c 100644 --- a/project.clj +++ b/project.clj @@ -4,13 +4,14 @@ :license {:name "Apache License, Version 2.0" :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.1"] - [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "2.0.3"] + [org.clojure/tools.reader "1.4.2"] + [org.domaindrivenarchitecture/c4k-common-clj "6.4.0"] [hickory "0.7.1" :exclusions [viebel/codox-klipse-theme]]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] - :resource-paths ["src/main/resources"] + :resource-paths ["src/main/resources" + "project.clj"] :repositories [["snapshots" :clojars] ["releases" :clojars]] :deploy-repositories [["snapshots" {:sign-releases false :url "https://clojars.org/repo"}] @@ -22,10 +23,10 @@ :uberjar {:aot :all :main dda.c4k-shynet.uberjar :uberjar-name "c4k-shynet-standalone.jar" - :dependencies [[org.clojure/tools.cli "1.0.214"] - [ch.qos.logback/logback-classic "1.4.5" + :dependencies [[org.clojure/tools.cli "1.1.230"] + [ch.qos.logback/logback-classic "1.5.6" :exclusions [com.sun.mail/javax.mail]] - [org.slf4j/jcl-over-slf4j "2.0.6"]]}} + [org.slf4j/jcl-over-slf4j "2.0.13"]]}} :release-tasks [["test"] ["vcs" "assert-committed"] ["change" "version" "leiningen.release/bump-version" "release"] diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 39ff5c8..9d2b369 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -4,7 +4,7 @@ "src/test/cljc" "src/test/cljs" "src/test/resources"] - :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "2.0.3"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.4.0"] [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-shynet.browser/init}} diff --git a/src/main/clj/dda/c4k_shynet/uberjar.clj b/src/main/clj/dda/c4k_shynet/uberjar.clj index 41a60b1..e15bcc9 100644 --- a/src/main/clj/dda/c4k_shynet/uberjar.clj +++ b/src/main/clj/dda/c4k_shynet/uberjar.clj @@ -5,4 +5,4 @@ [dda.c4k-common.uberjar :as uberjar])) (defn -main [& cmd-args] - (uberjar/main-common "c4k-shynet" core/config? core/auth? core/config-defaults core/k8s-objects cmd-args)) + (uberjar/main-cm "c4k-shynet" core/config? core/auth? core/config-defaults core/config-objects core/auth-objects cmd-args)) diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index ffaf757..60e3cee 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -16,19 +16,17 @@ (def auth? (s/keys :req-un [::shynet/django-secret-key ::postgres/postgres-db-user ::postgres/postgres-db-password])) -(defn k8s-objects [config] +(defn config-objects [config] (let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)] (map yaml/to-string [(postgres/generate-config {:postgres-size :2gb :db-name "shynet"}) - (postgres/generate-secret config) (when (contains? config :postgres-data-volume-path) (postgres/generate-persistent-volume (select-keys config [:postgres-data-volume-path :pv-storage-size-gb]))) (postgres/generate-pvc {:pv-storage-size-gb 20 :pvc-storage-class-name storage-class}) (postgres/generate-deployment {:postgres-image "postgres:14" :postgres-size :2gb}) - (postgres/generate-service) - (shynet/generate-secret config) + (postgres/generate-service config) (shynet/generate-webserver-deployment) (shynet/generate-celeryworker-deployment) (shynet/generate-ingress config) @@ -37,11 +35,7 @@ (shynet/generate-service-webserver) (shynet/generate-statefulset)]))) -; TODO: Remove once cljs release of common worked -(defn-spec generate any? - [my-config config? - my-auth auth?] - (let [resulting-config (merge config-defaults my-config my-auth)] - (cs/join - "\n---\n" - (k8s-objects resulting-config)))) +(defn auth-objects [config] + (map yaml/to-string + [(postgres/generate-secret config) + (shynet/generate-secret config)])) \ No newline at end of file diff --git a/src/main/cljs/dda/c4k_shynet/browser.cljs b/src/main/cljs/dda/c4k_shynet/browser.cljs index e68c7e5..790b13f 100644 --- a/src/main/cljs/dda/c4k_shynet/browser.cljs +++ b/src/main/cljs/dda/c4k_shynet/browser.cljs @@ -72,7 +72,7 @@ (br/validate! "issuer" ::shynet/issuer :optional true :deserializer keyword) (br/validate! "postgres-data-volume-path" ::pgc/postgres-data-volume-path :optional true) (br/validate! "auth" core/auth? :deserializer edn/read-string) - (br/set-validated!)) + (br/set-form-validated!)) (defn add-validate-listener [name] (-> (br/get-element-by-id name) @@ -81,16 +81,21 @@ (defn init [] (br/append-hickory (generate-content-div)) - (-> js/document - (.getElementById "generate-button") - (.addEventListener "click" - #(do (validate-all!) - (-> (cm/generate-common - (config-from-document) - (br/get-content-from-element "auth" :deserializer edn/read-string) - core/config-defaults - core/k8s-objects) - (br/set-output!))))) + (let [config-only false + auth-only false] + (-> js/document + (.getElementById "generate-button") + (.addEventListener "click" + #(do (validate-all!) + (-> (cm/generate-cm + (config-from-document) + (br/get-content-from-element "auth" :deserializer edn/read-string) + core/config-defaults + core/config-objects + core/auth-objects + config-only + auth-only) + (br/set-output!)))))) (add-validate-listener "fqdn") (add-validate-listener "postgres-data-volume-path") (add-validate-listener "issuer")