diff --git a/src/main/clj/dda/c4k_shynet/uberjar.clj b/src/main/clj/dda/c4k_shynet/uberjar.clj index 57a2995..49aed56 100644 --- a/src/main/clj/dda/c4k_shynet/uberjar.clj +++ b/src/main/clj/dda/c4k_shynet/uberjar.clj @@ -29,7 +29,13 @@ (s/explain spec args) (println (str "Bad commandline arguments\n" usage))) -(defn -main [& cmd-args] +(defn generate-common [my-config my-auth config-defaults k8s-objects] + (let [resulting-config (merge config-defaults my-config my-auth)] + (cs/join + "\n---\n" + (k8s-objects resulting-config)))) + +(defn main-common [config-spec? auth-spec? config-defaults k8s-objects cmd-args] (let [parsed-args-cmd (s/conform ::cmd-args cmd-args)] (if (= ::s/invalid parsed-args-cmd) (invalid-args-msg ::cmd-args cmd-args) @@ -43,14 +49,17 @@ auth-str (slurp auth) config-edn (edn/read-string config-str) auth-edn (edn/read-string auth-str) - config-valid? (s/valid? core/config? config-edn) - auth-valid? (s/valid? core/auth? auth-edn)] + config-valid? (s/valid? config-spec? config-edn) + auth-valid? (s/valid? auth-spec? auth-edn)] (if (and config-valid? auth-valid?) - (println (core/generate config-edn auth-edn)) + (println (generate-common config-edn auth-edn config-defaults k8s-objects)) (do (when (not config-valid?) (println - (expound/expound-str core/config? config-edn {:print-specs? false}))) + (expound/expound-str config-spec? config-edn {:print-specs? false}))) (when (not auth-valid?) (println - (expound/expound-str core/auth? auth-edn {:print-specs? false}))))))))))) + (expound/expound-str auth-spec? auth-edn {:print-specs? false}))))))))))) + +(defn -main [& cmd-args] + (main-common core/config? core/auth? core/config-defaults core/k8s-objects cmd-args)) diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index 7bf818c..1c0099e 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -19,24 +19,24 @@ (defn k8s-objects [config] (let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)] - (cm/concat-vec - [(yaml/to-string (postgres/generate-config {:postgres-size :2gb :db-name "shynet"})) - (yaml/to-string (postgres/generate-secret config))] - (when (contains? config :postgres-data-volume-path) - [(yaml/to-string (postgres/generate-persistent-volume (select-keys config [:postgres-data-volume-path :pv-storage-size-gb])))]) - [(yaml/to-string (postgres/generate-pvc {:pv-storage-size-gb 20 - :pvc-storage-class-name storage-class})) - (yaml/to-string (postgres/generate-deployment {:postgres-image "postgres:14" - :postgres-size :2gb})) - (yaml/to-string (postgres/generate-service)) - (yaml/to-string (shynet/generate-secret config)) - (yaml/to-string (shynet/generate-webserver-deployment)) - (yaml/to-string (shynet/generate-celeryworker-deployment)) - (yaml/to-string (shynet/generate-ingress config)) - (yaml/to-string (shynet/generate-certificate config)) - (yaml/to-string (shynet/generate-service-redis)) - (yaml/to-string (shynet/generate-service-webserver)) - (yaml/to-string (shynet/generate-statefulset))]))) + (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) + (shynet/generate-webserver-deployment) + (shynet/generate-celeryworker-deployment) + (shynet/generate-ingress config) + (shynet/generate-certificate config) + (shynet/generate-service-redis) + (shynet/generate-service-webserver) + (shynet/generate-statefulset)]))) (defn-spec generate any? [my-config config? diff --git a/src/main/cljs/dda/c4k_shynet/browser.cljs b/src/main/cljs/dda/c4k_shynet/browser.cljs index a93174b..cf24cad 100644 --- a/src/main/cljs/dda/c4k_shynet/browser.cljs +++ b/src/main/cljs/dda/c4k_shynet/browser.cljs @@ -89,7 +89,7 @@ (.getElementById "generate-button") (.addEventListener "click" #(do (validate-all!) - (-> (core/generate + (-> (core/generate ;TODO: common/generate (?) (config-from-document) (br/get-content-from-element "auth" :deserializer edn/read-string)) (br/set-output!)))))