|
|
|
@ -9,23 +9,23 @@
|
|
|
|
|
[dda.c4k-common.monitoring :as mon]
|
|
|
|
|
[dda.c4k-common.namespace :as ns]
|
|
|
|
|
[dda.c4k-common.ingress :as ing]
|
|
|
|
|
[dda.c4k-website.website.website-internal :as int]))
|
|
|
|
|
[dda.c4k-website.website :as web]))
|
|
|
|
|
|
|
|
|
|
(s/def ::mon-cfg ::mon/mon-cfg)
|
|
|
|
|
(s/def ::mon-auth ::mon/mon-auth)
|
|
|
|
|
(s/def ::unique-name ::int/unique-name)
|
|
|
|
|
(s/def ::issuer ::int/issuer)
|
|
|
|
|
(s/def ::volume-size ::int/volume-size)
|
|
|
|
|
(s/def ::authtoken ::int/authtoken)
|
|
|
|
|
(s/def ::fqdns ::int/fqdns)
|
|
|
|
|
(s/def ::forgejo-host ::int/forgejo-host)
|
|
|
|
|
(s/def ::forgejo-repo ::int/forgejo-repo)
|
|
|
|
|
(s/def ::branchname ::int/branchname)
|
|
|
|
|
(s/def ::username ::int/username)
|
|
|
|
|
(s/def ::build-cpu-request ::int/build-cpu-request)
|
|
|
|
|
(s/def ::build-memory-request ::int/build-memory-request)
|
|
|
|
|
(s/def ::build-cpu-limit ::int/build-cpu-limit)
|
|
|
|
|
(s/def ::build-memory-limit ::int/build-memory-limit)
|
|
|
|
|
(s/def ::unique-name ::web/unique-name)
|
|
|
|
|
(s/def ::issuer ::web/issuer)
|
|
|
|
|
(s/def ::volume-size ::web/volume-size)
|
|
|
|
|
(s/def ::authtoken ::web/authtoken)
|
|
|
|
|
(s/def ::fqdns ::web/fqdns)
|
|
|
|
|
(s/def ::forgejo-host ::web/forgejo-host)
|
|
|
|
|
(s/def ::forgejo-repo ::web/forgejo-repo)
|
|
|
|
|
(s/def ::branchname ::web/branchname)
|
|
|
|
|
(s/def ::username ::web/username)
|
|
|
|
|
(s/def ::build-cpu-request ::web/build-cpu-request)
|
|
|
|
|
(s/def ::build-memory-request ::web/build-memory-request)
|
|
|
|
|
(s/def ::build-cpu-limit ::web/build-cpu-limit)
|
|
|
|
|
(s/def ::build-memory-limit ::web/build-memory-limit)
|
|
|
|
|
|
|
|
|
|
(def websiteconfig? (s/keys :req-un [::unique-name
|
|
|
|
|
::fqdns
|
|
|
|
@ -39,15 +39,15 @@
|
|
|
|
|
::build-memory-request
|
|
|
|
|
::build-memory-limit]))
|
|
|
|
|
(def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken]))
|
|
|
|
|
(s/def ::websites (s/coll-of websiteconfig?))
|
|
|
|
|
(s/def ::auth (s/coll-of websiteauth?))
|
|
|
|
|
(s/def ::websiteconfigs (s/coll-of websiteconfig?))
|
|
|
|
|
(s/def ::websiteauths (s/coll-of websiteauth?))
|
|
|
|
|
|
|
|
|
|
(def config? (s/keys :req-un [::websites]
|
|
|
|
|
(def config? (s/keys :req-un [::websiteconfigs]
|
|
|
|
|
:opt-un [::issuer
|
|
|
|
|
::volume-size
|
|
|
|
|
::mon-cfg]))
|
|
|
|
|
|
|
|
|
|
(def auth? (s/keys :req-un [::auth]
|
|
|
|
|
(def auth? (s/keys :req-un [::websiteauths]
|
|
|
|
|
:opt-un [::mon-auth]))
|
|
|
|
|
|
|
|
|
|
(def config-defaults {:issuer "staging"})
|
|
|
|
@ -62,20 +62,20 @@
|
|
|
|
|
|
|
|
|
|
(defn-spec sort-config map?
|
|
|
|
|
[unsorted-config config?]
|
|
|
|
|
(let [sorted-websites (into [] (sort-by :unique-name (unsorted-config :websites)))]
|
|
|
|
|
(let [sorted-websiteconfigs (into [] (sort-by :unique-name (unsorted-config :websiteconfigs)))]
|
|
|
|
|
(-> unsorted-config
|
|
|
|
|
(assoc-in [:websites] sorted-websites))))
|
|
|
|
|
(assoc-in [:websiteconfigs] sorted-websiteconfigs))))
|
|
|
|
|
|
|
|
|
|
(defn-spec sort-auth map?
|
|
|
|
|
[unsorted-auth auth?]
|
|
|
|
|
(let [sorted-auth (into [] (sort-by :unique-name (unsorted-auth :auth)))]
|
|
|
|
|
(let [sorted-auth (into [] (sort-by :unique-name (unsorted-auth :websiteauths)))]
|
|
|
|
|
(-> unsorted-auth
|
|
|
|
|
(assoc-in [:auth] sorted-auth))))
|
|
|
|
|
(assoc-in [:websiteauths] sorted-auth))))
|
|
|
|
|
|
|
|
|
|
(defn-spec flatten-and-reduce-config map?
|
|
|
|
|
[config config?]
|
|
|
|
|
(let
|
|
|
|
|
[first-entry (first (:websites config))]
|
|
|
|
|
[first-entry (first (:websiteconfigs config))]
|
|
|
|
|
(conj first-entry
|
|
|
|
|
(when (contains? config :issuer)
|
|
|
|
|
{:issuer (config :issuer)})
|
|
|
|
@ -84,11 +84,11 @@
|
|
|
|
|
|
|
|
|
|
(defn-spec flatten-and-reduce-auth map?
|
|
|
|
|
[auth auth?]
|
|
|
|
|
(-> auth :auth first))
|
|
|
|
|
(-> auth :websiteauths first))
|
|
|
|
|
|
|
|
|
|
(defn-spec generate-ingress seq?
|
|
|
|
|
[config websiteconfig?]
|
|
|
|
|
(let [name (int/replace-dots-by-minus (:unique-name config))
|
|
|
|
|
(let [name (web/replace-dots-by-minus (:unique-name config))
|
|
|
|
|
final-config (merge website-config-defaults
|
|
|
|
|
{:service-name name
|
|
|
|
|
:service-port 80
|
|
|
|
@ -103,29 +103,29 @@
|
|
|
|
|
sorted-auth (sort-auth auth)
|
|
|
|
|
result []]
|
|
|
|
|
|
|
|
|
|
(if (and (empty? (config :websites)) (empty? (sorted-auth :auth)))
|
|
|
|
|
(if (and (empty? (config :websiteconfigs)) (empty? (sorted-auth :websiteauths)))
|
|
|
|
|
result
|
|
|
|
|
(recur (->
|
|
|
|
|
config
|
|
|
|
|
(assoc-in [:websites] (rest (config :websites))))
|
|
|
|
|
(assoc-in [:websiteconfigs] (rest (config :websiteconfigs))))
|
|
|
|
|
(->
|
|
|
|
|
auth
|
|
|
|
|
(assoc-in [:auth] (rest (sorted-auth :auth))))
|
|
|
|
|
(assoc-in [:websiteauths] (rest (sorted-auth :websiteauths))))
|
|
|
|
|
(let [final-config
|
|
|
|
|
(merge
|
|
|
|
|
website-config-defaults
|
|
|
|
|
(flatten-and-reduce-config config))
|
|
|
|
|
name (int/replace-dots-by-minus (:unique-name final-config))]
|
|
|
|
|
name (web/replace-dots-by-minus (:unique-name final-config))]
|
|
|
|
|
(cm/concat-vec
|
|
|
|
|
result
|
|
|
|
|
(ns/generate (merge {:namespace name} final-config))
|
|
|
|
|
[(int/generate-nginx-deployment final-config)
|
|
|
|
|
(int/generate-nginx-configmap final-config)
|
|
|
|
|
(int/generate-nginx-service final-config)
|
|
|
|
|
(int/generate-content-pvc final-config)
|
|
|
|
|
(int/generate-hash-state-pvc final-config)
|
|
|
|
|
(int/generate-build-cron final-config)
|
|
|
|
|
(int/generate-build-secret final-config
|
|
|
|
|
[(web/generate-nginx-deployment final-config)
|
|
|
|
|
(web/generate-nginx-configmap final-config)
|
|
|
|
|
(web/generate-nginx-service final-config)
|
|
|
|
|
(web/generate-content-pvc final-config)
|
|
|
|
|
(web/generate-hash-state-pvc final-config)
|
|
|
|
|
(web/generate-build-cron final-config)
|
|
|
|
|
(web/generate-build-secret final-config
|
|
|
|
|
(flatten-and-reduce-auth auth))]
|
|
|
|
|
(generate-ingress final-config)))))))
|
|
|
|
|
|
|
|
|
|