Compare commits

..

4 commits

8 changed files with 59 additions and 59 deletions

View file

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

View file

@ -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)))))))

View file

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

View file

@ -24,8 +24,8 @@
(br/generate-group
"website-data"
(br/generate-text-area
"websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
"{ :websites
"websiteconfigs" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
"{ :websiteconfigs
[{:unique-name \"test.io\",
:fqdns [\"test.de\" \"www.test.de\"],
:gitea-host \"githost.de\",
@ -49,7 +49,7 @@
"{:mon-auth
{:grafana-cloud-user \"your-user-id\"
:grafana-cloud-password \"your-cloud-password\"}
:auth
:websiteauths
[{:unique-name \"test.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}
@ -70,12 +70,12 @@
(defn config-from-document []
(let [issuer (br/get-content-from-element "issuer" :optional true)
websites (br/get-content-from-element "websites" :deserializer edn/read-string)
websiteconfigs (br/get-content-from-element "websiteconfigs" :deserializer edn/read-string)
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-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)]
(merge
{:websites websites}
{:websiteconfigs websiteconfigs}
(when (not (st/blank? issuer))
{:issuer issuer})
(when (some? mon-cluster-name)
@ -84,7 +84,7 @@
:grafana-cloud-url mon-cloud-url}}))))
(defn validate-all! []
(br/validate! "websites" website/websites? :deserializer edn/read-string)
(br/validate! "websiteconfigs" website/websiteconfigs? :deserializer edn/read-string)
(br/validate! "issuer" ::website/issuer :optional true)
(br/validate! "mon-cluster-name" ::mon/cluster-name :optional true)
(br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true)
@ -108,7 +108,7 @@
core/config-defaults
core/k8s-objects)
(br/set-output!)))))
(add-validate-listener "websites")
(add-validate-listener "websiteconfigs")
(add-validate-listener "issuer")
(add-validate-listener "mon-cluster-name")
(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"))))
(def websites1
{:websites
{:websiteconfigs
[{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"]
:forgejo-host "finegitehost.net"
@ -39,7 +39,7 @@
:branchname "main"}]})
(def websites2
{:websites
{:websiteconfigs
[{:unique-name "test.io"
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:forgejo-host "gitlab.de"
@ -52,7 +52,7 @@
:branchname "main"}]})
(def auth1
{:auth
{:websiteauths
[{:unique-name "example.io"
:username "someuser"
:authtoken "abedjgbasdodj"}
@ -61,7 +61,7 @@
:authtoken "abedjgbasdodj"}]})
(def auth2
{:auth
{:websiteauths
[{:unique-name "test.io"
:username "someuser"
:authtoken "abedjgbasdodj"}
@ -83,7 +83,7 @@
(deftest sorts-config
(is (= {:issuer "staging",
:websites
:websiteconfigs
[{:unique-name "example.io",
:fqdns ["example.org" "www.example.com"],
: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"}}
(cut/sort-config
{:issuer "staging",
:websites
:websiteconfigs
[{:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de",

View file

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

View file

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

View file

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