refactor -main to main-common, update generate

This commit is contained in:
see 2022-04-27 13:04:55 +02:00
parent 8fde427215
commit fef1ea5331
3 changed files with 34 additions and 25 deletions

View file

@ -29,7 +29,13 @@
(s/explain spec args) (s/explain spec args)
(println (str "Bad commandline arguments\n" usage))) (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)] (let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
(if (= ::s/invalid parsed-args-cmd) (if (= ::s/invalid parsed-args-cmd)
(invalid-args-msg ::cmd-args cmd-args) (invalid-args-msg ::cmd-args cmd-args)
@ -43,14 +49,17 @@
auth-str (slurp auth) auth-str (slurp auth)
config-edn (edn/read-string config-str) config-edn (edn/read-string config-str)
auth-edn (edn/read-string auth-str) auth-edn (edn/read-string auth-str)
config-valid? (s/valid? core/config? config-edn) config-valid? (s/valid? config-spec? config-edn)
auth-valid? (s/valid? core/auth? auth-edn)] auth-valid? (s/valid? auth-spec? auth-edn)]
(if (and config-valid? auth-valid?) (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 (do
(when (not config-valid?) (when (not config-valid?)
(println (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?) (when (not auth-valid?)
(println (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))

View file

@ -19,24 +19,24 @@
(defn k8s-objects [config] (defn k8s-objects [config]
(let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)] (let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)]
(cm/concat-vec (map yaml/to-string
[(yaml/to-string (postgres/generate-config {:postgres-size :2gb :db-name "shynet"})) [(postgres/generate-config {:postgres-size :2gb :db-name "shynet"})
(yaml/to-string (postgres/generate-secret config))] (postgres/generate-secret config)
(when (contains? config :postgres-data-volume-path) (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])))]) (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 (postgres/generate-pvc {:pv-storage-size-gb 20
:pvc-storage-class-name storage-class})) :pvc-storage-class-name storage-class})
(yaml/to-string (postgres/generate-deployment {:postgres-image "postgres:14" (postgres/generate-deployment {:postgres-image "postgres:14"
:postgres-size :2gb})) :postgres-size :2gb})
(yaml/to-string (postgres/generate-service)) (postgres/generate-service)
(yaml/to-string (shynet/generate-secret config)) (shynet/generate-secret config)
(yaml/to-string (shynet/generate-webserver-deployment)) (shynet/generate-webserver-deployment)
(yaml/to-string (shynet/generate-celeryworker-deployment)) (shynet/generate-celeryworker-deployment)
(yaml/to-string (shynet/generate-ingress config)) (shynet/generate-ingress config)
(yaml/to-string (shynet/generate-certificate config)) (shynet/generate-certificate config)
(yaml/to-string (shynet/generate-service-redis)) (shynet/generate-service-redis)
(yaml/to-string (shynet/generate-service-webserver)) (shynet/generate-service-webserver)
(yaml/to-string (shynet/generate-statefulset))]))) (shynet/generate-statefulset)])))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config config?

View file

@ -89,7 +89,7 @@
(.getElementById "generate-button") (.getElementById "generate-button")
(.addEventListener "click" (.addEventListener "click"
#(do (validate-all!) #(do (validate-all!)
(-> (core/generate (-> (core/generate ;TODO: common/generate (?)
(config-from-document) (config-from-document)
(br/get-content-from-element "auth" :deserializer edn/read-string)) (br/get-content-from-element "auth" :deserializer edn/read-string))
(br/set-output!))))) (br/set-output!)))))