Use standardized uberjar

This commit is contained in:
bom 2023-02-02 13:40:56 +01:00
parent 107b8c3872
commit 88a077e776
3 changed files with 30 additions and 72 deletions

View file

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

View file

@ -1,9 +1,9 @@
(ns dda.c4k-nextcloud.core (ns dda.c4k-nextcloud.core
(:require (:require
[clojure.string :as cs]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:clj [orchestra.core :refer [defn-spec]] #?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]]) :cljs [orchestra.core :refer-macros [defn-spec]])
[dda.c4k-common.common :as cm]
[dda.c4k-common.yaml :as yaml] [dda.c4k-common.yaml :as yaml]
[dda.c4k-common.postgres :as postgres] [dda.c4k-common.postgres :as postgres]
[dda.c4k-nextcloud.nextcloud :as nextcloud] [dda.c4k-nextcloud.nextcloud :as nextcloud]
@ -13,22 +13,8 @@
(def config-defaults {:issuer "staging"}) (def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::nextcloud/fqdn]
:opt-un [::nextcloud/issuer
::nextcloud/restic-repository
::nextcloud/pv-storage-size-gb
::nextcloud/pvc-storage-class-name]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password
::nextcloud/nextcloud-admin-user ::nextcloud/nextcloud-admin-password
::aws-access-key-id ::aws-secret-access-key
::restic-password]))
(s/def ::config config?)
(s/def ::auth auth?)
(defn-spec k8s-objects any? (defn-spec k8s-objects any?
[config (s/merge config? auth?)] [config (s/merge nextcloud/config? nextcloud/auth?)]
(let [nextcloud-default-storage-config {:pvc-storage-class-name default-storage-class (let [nextcloud-default-storage-config {:pvc-storage-class-name default-storage-class
:pv-storage-size-gb 200}] :pv-storage-size-gb 200}]
(into (into
@ -52,9 +38,9 @@
(yaml/to-string (backup/generate-backup-restore-deployment config))]))))) (yaml/to-string (backup/generate-backup-restore-deployment config))])))))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config nextcloud/config?
my-auth auth?] my-auth nextcloud/auth?]
(let [resulting-config (merge config-defaults my-config my-auth)] (cm/concat-vec
(cs/join (map yaml/to-string
"\n---\n" (filter #(not (nil? %))
(k8s-objects resulting-config)))) (merge config-defaults my-config my-auth)))))

View file

@ -7,6 +7,7 @@
[dda.c4k-common.yaml :as yaml] [dda.c4k-common.yaml :as yaml]
[dda.c4k-common.base64 :as b64] [dda.c4k-common.base64 :as b64]
[dda.c4k-common.predicate :as cp] [dda.c4k-common.predicate :as cp]
[dda.c4k-common.postgres :as postgres]
[dda.c4k-common.common :as cm])) [dda.c4k-common.common :as cm]))
(s/def ::fqdn cp/fqdn-string?) (s/def ::fqdn cp/fqdn-string?)
@ -21,6 +22,17 @@
::pvc-storage-class-name] ::pvc-storage-class-name]
:opt-un [::restic-repository])) :opt-un [::restic-repository]))
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer
::restic-repository
::pv-storage-size-gb
::pvc-storage-class-name]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password
::nextcloud-admin-user ::nextcloud-admin-password
::aws-access-key-id ::aws-secret-access-key
::restic-password]))
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :nextcloud [resource-name] (defmethod yaml/load-resource :nextcloud [resource-name]
(case resource-name (case resource-name