Compare commits

..

No commits in common. "d7be8aa7306b20df090770c80579b2d036c8f005" and "f16ee3478256db9474bf65352d0f6f56bfef774b" have entirely different histories.

8 changed files with 59 additions and 59 deletions

View file

@ -24,7 +24,7 @@ For the example configuration
```yaml ```yaml
issuer: "staging" issuer: "staging"
websiteconfigs: websites:
- unique-name: "test.io" - unique-name: "test.io"
fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"] fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"]
forgejo-host: "codeberg.org" forgejo-host: "codeberg.org"

View file

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

View file

@ -1,4 +1,4 @@
(ns dda.c4k-website.website (ns dda.c4k-website.website.website-internal
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as str] [clojure.string :as str]
@ -46,13 +46,13 @@
(def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken])) (def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken]))
(s/def ::websiteconfigs (s/coll-of websiteconfig?)) (s/def ::websites (s/coll-of websiteconfig?))
(s/def ::websiteauths (s/coll-of websiteauth?)) (s/def ::auth (s/coll-of websiteauth?))
(def websiteconfigs? (s/keys :req-un [::websiteconfigs])) (def websites? (s/keys :req-un [::websites]))
(def auth? (s/keys :req-un [::websiteauths])) (def auth? (s/keys :req-un [::auth]))
(defn-spec replace-dots-by-minus string? (defn-spec replace-dots-by-minus string?
[fqdn pred/fqdn-string?] [fqdn pred/fqdn-string?]

View file

@ -24,8 +24,8 @@
(br/generate-group (br/generate-group
"website-data" "website-data"
(br/generate-text-area (br/generate-text-area
"websiteconfigs" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:" "websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
"{ :websiteconfigs "{ :websites
[{:unique-name \"test.io\", [{:unique-name \"test.io\",
:fqdns [\"test.de\" \"www.test.de\"], :fqdns [\"test.de\" \"www.test.de\"],
:gitea-host \"githost.de\", :gitea-host \"githost.de\",
@ -49,7 +49,7 @@
"{:mon-auth "{:mon-auth
{:grafana-cloud-user \"your-user-id\" {:grafana-cloud-user \"your-user-id\"
:grafana-cloud-password \"your-cloud-password\"} :grafana-cloud-password \"your-cloud-password\"}
:websiteauths :auth
[{:unique-name \"test.io\", [{:unique-name \"test.io\",
:username \"someuser\", :username \"someuser\",
:authtoken \"abedjgbasdodj\"} :authtoken \"abedjgbasdodj\"}
@ -70,12 +70,12 @@
(defn config-from-document [] (defn config-from-document []
(let [issuer (br/get-content-from-element "issuer" :optional true) (let [issuer (br/get-content-from-element "issuer" :optional true)
websiteconfigs (br/get-content-from-element "websiteconfigs" :deserializer edn/read-string) websites (br/get-content-from-element "websites" :deserializer edn/read-string)
mon-cluster-name (br/get-content-from-element "mon-cluster-name" :optional true) mon-cluster-name (br/get-content-from-element "mon-cluster-name" :optional true)
mon-cluster-stage (br/get-content-from-element "mon-cluster-stage" :optional true) mon-cluster-stage (br/get-content-from-element "mon-cluster-stage" :optional true)
mon-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)] mon-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)]
(merge (merge
{:websiteconfigs websiteconfigs} {:websites websites}
(when (not (st/blank? issuer)) (when (not (st/blank? issuer))
{:issuer issuer}) {:issuer issuer})
(when (some? mon-cluster-name) (when (some? mon-cluster-name)
@ -84,7 +84,7 @@
:grafana-cloud-url mon-cloud-url}})))) :grafana-cloud-url mon-cloud-url}}))))
(defn validate-all! [] (defn validate-all! []
(br/validate! "websiteconfigs" website/websiteconfigs? :deserializer edn/read-string) (br/validate! "websites" website/websites? :deserializer edn/read-string)
(br/validate! "issuer" ::website/issuer :optional true) (br/validate! "issuer" ::website/issuer :optional true)
(br/validate! "mon-cluster-name" ::mon/cluster-name :optional true) (br/validate! "mon-cluster-name" ::mon/cluster-name :optional true)
(br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true) (br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true)
@ -108,7 +108,7 @@
core/config-defaults core/config-defaults
core/k8s-objects) core/k8s-objects)
(br/set-output!))))) (br/set-output!)))))
(add-validate-listener "websiteconfigs") (add-validate-listener "websites")
(add-validate-listener "issuer") (add-validate-listener "issuer")
(add-validate-listener "mon-cluster-name") (add-validate-listener "mon-cluster-name")
(add-validate-listener "mon-cluster-stage") (add-validate-listener "mon-cluster-stage")

View file

@ -26,7 +26,7 @@
(is (s/valid? cut/auth? (yaml/load-as-edn "website-test/valid-auth.yaml")))) (is (s/valid? cut/auth? (yaml/load-as-edn "website-test/valid-auth.yaml"))))
(def websites1 (def websites1
{:websiteconfigs {:websites
[{:unique-name "example.io" [{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"] :fqdns ["example.org", "www.example.com"]
:forgejo-host "finegitehost.net" :forgejo-host "finegitehost.net"
@ -39,7 +39,7 @@
:branchname "main"}]}) :branchname "main"}]})
(def websites2 (def websites2
{:websiteconfigs {:websites
[{:unique-name "test.io" [{:unique-name "test.io"
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"] :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:forgejo-host "gitlab.de" :forgejo-host "gitlab.de"
@ -52,7 +52,7 @@
:branchname "main"}]}) :branchname "main"}]})
(def auth1 (def auth1
{:websiteauths {:auth
[{:unique-name "example.io" [{:unique-name "example.io"
:username "someuser" :username "someuser"
:authtoken "abedjgbasdodj"} :authtoken "abedjgbasdodj"}
@ -61,7 +61,7 @@
:authtoken "abedjgbasdodj"}]}) :authtoken "abedjgbasdodj"}]})
(def auth2 (def auth2
{:websiteauths {:auth
[{:unique-name "test.io" [{:unique-name "test.io"
:username "someuser" :username "someuser"
:authtoken "abedjgbasdodj"} :authtoken "abedjgbasdodj"}
@ -83,7 +83,7 @@
(deftest sorts-config (deftest sorts-config
(is (= {:issuer "staging", (is (= {:issuer "staging",
:websiteconfigs :websites
[{:unique-name "example.io", [{:unique-name "example.io",
:fqdns ["example.org" "www.example.com"], :fqdns ["example.org" "www.example.com"],
:forgejo-host "finegitehost.net", :forgejo-host "finegitehost.net",
@ -98,7 +98,7 @@
:mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}} :mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}}
(cut/sort-config (cut/sort-config
{:issuer "staging", {:issuer "staging",
:websiteconfigs :websites
[{:unique-name "test.io", [{:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de", :forgejo-host "gitlab.de",

View file

@ -1,10 +1,10 @@
(ns dda.c4k-website.website-test (ns dda.c4k-website.website.website-internal-test
(:require (:require
[clojure.string :as str] [clojure.string :as str]
#?(:clj [clojure.test :refer [deftest is are testing run-tests]] #?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) :cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[clojure.spec.test.alpha :as st] [clojure.spec.test.alpha :as st]
[dda.c4k-website.website :as cut])) [dda.c4k-website.website.website-internal :as cut]))
(st/instrument `cut/replace-dots-by-minus) (st/instrument `cut/replace-dots-by-minus)
(st/instrument `cut/generate-gitrepourl) (st/instrument `cut/generate-gitrepourl)

View file

@ -1,4 +1,4 @@
websiteauths: auth:
- unique-name: "test.io" - unique-name: "test.io"
username: "someuser" username: "someuser"
authtoken: "abedjgbasdodj" authtoken: "abedjgbasdodj"

View file

@ -1,5 +1,5 @@
issuer: "staging" issuer: "staging"
websiteconfigs: websites:
- unique-name: "test.io" - unique-name: "test.io"
fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"] fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"]
forgejo-host: "codeberg.org" forgejo-host: "codeberg.org"