Added volume-size to config and added todo

This commit is contained in:
Clemens 2022-10-28 13:48:11 +02:00
parent 54ce871333
commit ac2a4da7b4
3 changed files with 15 additions and 13 deletions

View file

@ -5,7 +5,7 @@
:url "https://www.apache.org/licenses/LICENSE-2.0.html"} :url "https://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.10.3"] :dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/tools.reader "1.3.6"] [org.clojure/tools.reader "1.3.6"]
[org.domaindrivenarchitecture/c4k-common-clj "3.0.1"] [org.domaindrivenarchitecture/c4k-common-clj "3.0.2-SNAPSHOT"]
[hickory "0.7.1"]] [hickory "0.7.1"]]
:target-path "target/%s/" :target-path "target/%s/"
:source-paths ["src/main/cljc" :source-paths ["src/main/cljc"

View file

@ -5,13 +5,14 @@
[dda.c4k-common.common :as cm] [dda.c4k-common.common :as cm]
[dda.c4k-website.website :as website])) [dda.c4k-website.website :as website]))
(def config-defaults {:issuer "staging"}) (def config-defaults {:issuer "staging"
:volume-size "3"})
; TODO: gec 2022/10/28: That does only work if the :websites and :auth collections have the same order regarding :unique-name! ; TODO: gec 2022/10/28: That does only work if the :websites and :auth collections have the same order regarding :unique-name!
; There must be a check or the config must be sorted first! ; There must be a check or the config must be sorted first!
(defn flatten-and-reduce-config (defn flatten-and-reduce-config
[config] [config]
(merge (-> config :websites first) (-> config :auth first) {:issuer (config :issuer)})) (merge (-> config :websites first) (-> config :auth first) (dissoc config :issuer :volume-size)))
(defn generate-configs [config] (defn generate-configs [config]
(loop [config config (loop [config config

View file

@ -1,6 +1,6 @@
(ns dda.c4k-website.website (ns dda.c4k-website.website
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc]) #?(:cljs [shadow.resource :as rc])
#?(: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]])
@ -19,6 +19,7 @@
(s/def ::unique-name string?) (s/def ::unique-name string?)
(s/def ::issuer pred/letsencrypt-issuer?) (s/def ::issuer pred/letsencrypt-issuer?)
(s/def ::volume-size pred/integer-string?)
(s/def ::authtoken pred/bash-env-string?) (s/def ::authtoken pred/bash-env-string?)
(s/def ::fqdns (s/coll-of pred/fqdn-string?)) (s/def ::fqdns (s/coll-of pred/fqdn-string?))
(s/def ::gitea-host pred/fqdn-string?) (s/def ::gitea-host pred/fqdn-string?)
@ -38,10 +39,7 @@
(def auth? (s/keys :req-un [::auth])) (def auth? (s/keys :req-un [::auth]))
(def config? (s/keys :req-un [::websites] (def config? (s/keys :req-un [::websites]
:opt-un [::issuer])) :opt-un [::issuer ::volume-size]))
; TODO: Review jem 2022/10/26: move default to core/default
(def volume-size 3)
(defn-spec replace-dots-by-minus string? (defn-spec replace-dots-by-minus string?
[fqdn pred/fqdn-string?] [fqdn pred/fqdn-string?]
@ -73,8 +71,8 @@
; ToDo: Move to common? ; ToDo: Move to common?
; ToDo richtig spec-en ; ToDo richtig spec-en
(defn replace-all-matching-subvalues-in-string-start (defn replace-all-matching-subvalues-in-string-start
[col [col
value-to-partly-match value-to-partly-match
value-to-inplace] value-to-inplace]
(clojure.walk/postwalk #(if (and (= (type value-to-partly-match) (type %)) (clojure.walk/postwalk #(if (and (= (type value-to-partly-match) (type %))
@ -99,10 +97,13 @@
(defmethod yaml/load-as-edn :website [resource-name] (defmethod yaml/load-as-edn :website [resource-name]
(yaml/from-string (yaml/load-resource resource-name)))) (yaml/from-string (yaml/load-resource resource-name))))
; TODO: gec 2022/10/28: The specs for config in the following functions are not correct,
; since config is the result of "flatten-and-reduce-config".
; Use correct specs!
(defn-spec generate-website-http-ingress pred/map-or-seq? (defn-spec generate-website-http-ingress pred/map-or-seq?
[config websitedata?] [config websitedata?]
(let [{:keys [unique-name fqdns]} config] (let [{:keys [unique-name fqdns]} config]
(ing/generate-http-ingress {:fqdns fqdns (ing/generate-http-ingress {:fqdns fqdns
:ingress-name (generate-http-ingress-name unique-name) :ingress-name (generate-http-ingress-name unique-name)
:service-name (generate-service-name unique-name) :service-name (generate-service-name unique-name)
:service-port 80}))) :service-port 80})))
@ -151,11 +152,11 @@
(defn-spec generate-website-content-volume pred/map-or-seq? (defn-spec generate-website-content-volume pred/map-or-seq?
[config websitedata?] [config websitedata?]
(let [{:keys [unique-name]} config] (let [{:keys [unique-name volume-size]} config]
(-> (->
(yaml/load-as-edn "website/website-content-volume.yaml") (yaml/load-as-edn "website/website-content-volume.yaml")
(replace-all-matching-subvalues-in-string-start "NAME" (replace-dots-by-minus unique-name)) (replace-all-matching-subvalues-in-string-start "NAME" (replace-dots-by-minus unique-name))
(cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str (str volume-size) "Gi"))))) (cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str volume-size "Gi")))))
(defn-spec generate-website-build-cron pred/map-or-seq? (defn-spec generate-website-build-cron pred/map-or-seq?
[config websitedata?] [config websitedata?]