Compare commits
4 commits
f16ee34782
...
d7be8aa730
Author | SHA1 | Date | |
---|---|---|---|
d7be8aa730 | |||
9efbf4dbc4 | |||
1b1d316653 | |||
20401c20b7 |
8 changed files with 59 additions and 59 deletions
|
@ -24,7 +24,7 @@ For the example configuration
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
issuer: "staging"
|
issuer: "staging"
|
||||||
websites:
|
websiteconfigs:
|
||||||
- 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"
|
||||||
|
|
|
@ -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.website-internal :as int]))
|
[dda.c4k-website.website :as web]))
|
||||||
|
|
||||||
(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 ::int/unique-name)
|
(s/def ::unique-name ::web/unique-name)
|
||||||
(s/def ::issuer ::int/issuer)
|
(s/def ::issuer ::web/issuer)
|
||||||
(s/def ::volume-size ::int/volume-size)
|
(s/def ::volume-size ::web/volume-size)
|
||||||
(s/def ::authtoken ::int/authtoken)
|
(s/def ::authtoken ::web/authtoken)
|
||||||
(s/def ::fqdns ::int/fqdns)
|
(s/def ::fqdns ::web/fqdns)
|
||||||
(s/def ::forgejo-host ::int/forgejo-host)
|
(s/def ::forgejo-host ::web/forgejo-host)
|
||||||
(s/def ::forgejo-repo ::int/forgejo-repo)
|
(s/def ::forgejo-repo ::web/forgejo-repo)
|
||||||
(s/def ::branchname ::int/branchname)
|
(s/def ::branchname ::web/branchname)
|
||||||
(s/def ::username ::int/username)
|
(s/def ::username ::web/username)
|
||||||
(s/def ::build-cpu-request ::int/build-cpu-request)
|
(s/def ::build-cpu-request ::web/build-cpu-request)
|
||||||
(s/def ::build-memory-request ::int/build-memory-request)
|
(s/def ::build-memory-request ::web/build-memory-request)
|
||||||
(s/def ::build-cpu-limit ::int/build-cpu-limit)
|
(s/def ::build-cpu-limit ::web/build-cpu-limit)
|
||||||
(s/def ::build-memory-limit ::int/build-memory-limit)
|
(s/def ::build-memory-limit ::web/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 ::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 config? (s/keys :req-un [::websites]
|
(def config? (s/keys :req-un [::websiteconfigs]
|
||||||
:opt-un [::issuer
|
:opt-un [::issuer
|
||||||
::volume-size
|
::volume-size
|
||||||
::mon-cfg]))
|
::mon-cfg]))
|
||||||
|
|
||||||
(def auth? (s/keys :req-un [::auth]
|
(def auth? (s/keys :req-un [::websiteauths]
|
||||||
: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-websites (into [] (sort-by :unique-name (unsorted-config :websites)))]
|
(let [sorted-websiteconfigs (into [] (sort-by :unique-name (unsorted-config :websiteconfigs)))]
|
||||||
(-> unsorted-config
|
(-> unsorted-config
|
||||||
(assoc-in [:websites] sorted-websites))))
|
(assoc-in [:websiteconfigs] sorted-websiteconfigs))))
|
||||||
|
|
||||||
(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 :auth)))]
|
(let [sorted-auth (into [] (sort-by :unique-name (unsorted-auth :websiteauths)))]
|
||||||
(-> unsorted-auth
|
(-> unsorted-auth
|
||||||
(assoc-in [:auth] sorted-auth))))
|
(assoc-in [:websiteauths] 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 (:websites config))]
|
[first-entry (first (:websiteconfigs 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 :auth first))
|
(-> auth :websiteauths first))
|
||||||
|
|
||||||
(defn-spec generate-ingress seq?
|
(defn-spec generate-ingress seq?
|
||||||
[config websiteconfig?]
|
[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
|
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 :websites)) (empty? (sorted-auth :auth)))
|
(if (and (empty? (config :websiteconfigs)) (empty? (sorted-auth :websiteauths)))
|
||||||
result
|
result
|
||||||
(recur (->
|
(recur (->
|
||||||
config
|
config
|
||||||
(assoc-in [:websites] (rest (config :websites))))
|
(assoc-in [:websiteconfigs] (rest (config :websiteconfigs))))
|
||||||
(->
|
(->
|
||||||
auth
|
auth
|
||||||
(assoc-in [:auth] (rest (sorted-auth :auth))))
|
(assoc-in [:websiteauths] (rest (sorted-auth :websiteauths))))
|
||||||
(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 (int/replace-dots-by-minus (:unique-name final-config))]
|
name (web/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))
|
||||||
[(int/generate-nginx-deployment final-config)
|
[(web/generate-nginx-deployment final-config)
|
||||||
(int/generate-nginx-configmap final-config)
|
(web/generate-nginx-configmap final-config)
|
||||||
(int/generate-nginx-service final-config)
|
(web/generate-nginx-service final-config)
|
||||||
(int/generate-content-pvc final-config)
|
(web/generate-content-pvc final-config)
|
||||||
(int/generate-hash-state-pvc final-config)
|
(web/generate-hash-state-pvc final-config)
|
||||||
(int/generate-build-cron final-config)
|
(web/generate-build-cron final-config)
|
||||||
(int/generate-build-secret final-config
|
(web/generate-build-secret final-config
|
||||||
(flatten-and-reduce-auth auth))]
|
(flatten-and-reduce-auth auth))]
|
||||||
(generate-ingress final-config)))))))
|
(generate-ingress final-config)))))))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(ns dda.c4k-website.website.website-internal
|
(ns dda.c4k-website.website
|
||||||
(: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 ::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?
|
(defn-spec replace-dots-by-minus string?
|
||||||
[fqdn pred/fqdn-string?]
|
[fqdn pred/fqdn-string?]
|
|
@ -24,8 +24,8 @@
|
||||||
(br/generate-group
|
(br/generate-group
|
||||||
"website-data"
|
"website-data"
|
||||||
(br/generate-text-area
|
(br/generate-text-area
|
||||||
"websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
|
"websiteconfigs" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
|
||||||
"{ :websites
|
"{ :websiteconfigs
|
||||||
[{: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\"}
|
||||||
:auth
|
:websiteauths
|
||||||
[{: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)
|
||||||
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-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
|
||||||
{:websites websites}
|
{:websiteconfigs websiteconfigs}
|
||||||
(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! "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! "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 "websites")
|
(add-validate-listener "websiteconfigs")
|
||||||
(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")
|
||||||
|
|
|
@ -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
|
||||||
{:websites
|
{:websiteconfigs
|
||||||
[{: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
|
||||||
{:websites
|
{:websiteconfigs
|
||||||
[{: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
|
||||||
{:auth
|
{:websiteauths
|
||||||
[{: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
|
||||||
{:auth
|
{:websiteauths
|
||||||
[{: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",
|
||||||
:websites
|
:websiteconfigs
|
||||||
[{: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",
|
||||||
:websites
|
:websiteconfigs
|
||||||
[{: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",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(ns dda.c4k-website.website.website-internal-test
|
(ns dda.c4k-website.website-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.website-internal :as cut]))
|
[dda.c4k-website.website :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)
|
|
@ -1,4 +1,4 @@
|
||||||
auth:
|
websiteauths:
|
||||||
- unique-name: "test.io"
|
- unique-name: "test.io"
|
||||||
username: "someuser"
|
username: "someuser"
|
||||||
authtoken: "abedjgbasdodj"
|
authtoken: "abedjgbasdodj"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
issuer: "staging"
|
issuer: "staging"
|
||||||
websites:
|
websiteconfigs:
|
||||||
- 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"
|
||||||
|
|
Loading…
Reference in a new issue