standardized uberjar

This commit is contained in:
jerger 2022-12-23 18:09:30 +01:00
parent 5bd198b80f
commit b852a74dc5
3 changed files with 23 additions and 62 deletions

View file

@ -1,56 +1,15 @@
(ns dda.c4k-jitsi.uberjar
(:gen-class)
(:require
[clojure.spec.alpha :as s]
[clojure.string :as cs]
[clojure.tools.reader.edn :as edn]
[expound.alpha :as expound]
[dda.c4k-jitsi.core :as core]))
(def usage
"usage:
c4k-jitsi {your configuraton file} {your authorization file}")
(s/def ::options (s/* #{"-h"}))
(s/def ::filename (s/and string?
#(not (cs/starts-with? % "-"))))
(s/def ::cmd-args (s/cat :options ::options
:args (s/?
(s/cat :config ::filename
:auth ::filename))))
(defn expound-config
[config]
(expound/expound ::core/config config))
(defn invalid-args-msg
[spec args]
(s/explain spec args)
(println (str "Bad commandline arguments\n" usage)))
[dda.c4k-common.uberjar :as uberjar]
[dda.c4k-jitsi.core :as core]
[dda.c4k-jitsi.jitsi :as jitsi]))
(defn -main [& 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)
(let [{:keys [options args]} parsed-args-cmd
{:keys [config auth]} args]
(cond
(some #(= "-h" %) options)
(println usage)
:default
(let [config-str (slurp config)
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)]
(if (and config-valid? auth-valid?)
(println (core/generate config-edn auth-edn))
(do
(when (not config-valid?)
(println
(expound/expound-str core/config? config-edn {:print-specs? false})))
(when (not auth-valid?)
(println
(expound/expound-str core/auth? auth-edn {:print-specs? false})))))))))))
(uberjar/main-common
"c4k-jitsi"
jitsi/config?
jitsi/auth?
core/config-defaults
core/generate
cmd-args))

View file

@ -9,11 +9,6 @@
(def config-defaults {:issuer :staging})
(def config? (s/keys :req-un [::jitsi/fqdn]
:opt-un [::jitsi/issuer ::jitsi/ingress-type]))
(def auth? (s/keys :req-un [::jitsi/jvb-auth-password ::jitsi/jicofo-auth-password ::jitsi/jicofo-component-secret]))
(defn k8s-objects [config]
(map yaml/to-string
[(jitsi/generate-secret-jitsi config)
@ -27,9 +22,9 @@
(jitsi/generate-deployment config)]))
(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))))
[my-config jitsi/config?
my-auth jitsi/auth?]
(cm/concat-vec
(map yaml/to-string
(filter #(not (nil? %))
(merge config-defaults my-config my-auth)))))

View file

@ -13,6 +13,13 @@
(s/def ::jicofo-auth-password pred/bash-env-string?)
(s/def ::jicofo-component-secret pred/bash-env-string?)
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer ::ingress-type]))
(def auth? (s/keys :req-un [::jvb-auth-password
::jicofo-auth-password
::jicofo-component-secret]))
#?(:cljs
(defmethod yaml/load-resource :jitsi [resource-name]
(case resource-name