merge happens in uberjar -> website is obsoloete
This commit is contained in:
parent
18ec39549e
commit
f16ee34782
6 changed files with 143 additions and 194 deletions
|
@ -2,7 +2,6 @@
|
||||||
(:gen-class)
|
(:gen-class)
|
||||||
(:require
|
(:require
|
||||||
[dda.c4k-common.uberjar :as uberjar]
|
[dda.c4k-common.uberjar :as uberjar]
|
||||||
[dda.c4k-website.website :as website]
|
|
||||||
[dda.c4k-website.core :as core]))
|
[dda.c4k-website.core :as core]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +10,6 @@
|
||||||
"c4k-website"
|
"c4k-website"
|
||||||
core/config?
|
core/config?
|
||||||
core/auth?
|
core/auth?
|
||||||
website/config-defaults
|
core/config-defaults
|
||||||
core/k8s-objects
|
core/k8s-objects
|
||||||
cmd-args))
|
cmd-args))
|
||||||
|
|
|
@ -7,19 +7,59 @@
|
||||||
[dda.c4k-common.common :as cm]
|
[dda.c4k-common.common :as cm]
|
||||||
[dda.c4k-common.predicate :as cp]
|
[dda.c4k-common.predicate :as cp]
|
||||||
[dda.c4k-common.monitoring :as mon]
|
[dda.c4k-common.monitoring :as mon]
|
||||||
[dda.c4k-website.website :as website]))
|
[dda.c4k-common.namespace :as ns]
|
||||||
|
[dda.c4k-common.ingress :as ing]
|
||||||
|
[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 ::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)
|
||||||
|
|
||||||
(def config? (s/keys :req-un [::website/websites]
|
(def websiteconfig? (s/keys :req-un [::unique-name
|
||||||
:opt-un [::website/issuer
|
::fqdns
|
||||||
::website/volume-size
|
::forgejo-host
|
||||||
|
::forgejo-repo
|
||||||
|
::branchname]
|
||||||
|
:opt-un [::issuer
|
||||||
|
::volume-size
|
||||||
|
::build-cpu-request
|
||||||
|
::build-cpu-limit
|
||||||
|
::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?))
|
||||||
|
|
||||||
|
(def config? (s/keys :req-un [::websites]
|
||||||
|
:opt-un [::issuer
|
||||||
|
::volume-size
|
||||||
::mon-cfg]))
|
::mon-cfg]))
|
||||||
|
|
||||||
(def auth? (s/keys :req-un [::website/auth]
|
(def auth? (s/keys :req-un [::auth]
|
||||||
:opt-un [::mon-auth]))
|
:opt-un [::mon-auth]))
|
||||||
|
|
||||||
|
(def config-defaults {:issuer "staging"})
|
||||||
|
|
||||||
|
|
||||||
|
(def website-config-defaults {:build-cpu-request "500m"
|
||||||
|
:build-cpu-limit "1700m"
|
||||||
|
:build-memory-request "256Mi"
|
||||||
|
:build-memory-limit "512Mi"
|
||||||
|
:volume-size "3"
|
||||||
|
:redirects []})
|
||||||
|
|
||||||
(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-websites (into [] (sort-by :unique-name (unsorted-config :websites)))]
|
||||||
|
@ -37,43 +77,57 @@
|
||||||
(let
|
(let
|
||||||
[first-entry (first (:websites 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)})
|
||||||
(when (contains? config :volume-size)
|
(when (contains? config :volume-size)
|
||||||
{:volume-size (config :volume-size)}))))
|
{:volume-size (config :volume-size)}))))
|
||||||
|
|
||||||
(defn-spec flatten-and-reduce-auth map?
|
(defn-spec flatten-and-reduce-auth map?
|
||||||
[auth auth?]
|
[auth auth?]
|
||||||
(-> auth :auth first))
|
(-> auth :auth first))
|
||||||
|
|
||||||
|
(defn-spec generate-ingress seq?
|
||||||
|
[config websiteconfig?]
|
||||||
|
(let [name (int/replace-dots-by-minus (:unique-name config))
|
||||||
|
final-config (merge website-config-defaults
|
||||||
|
{:service-name name
|
||||||
|
:service-port 80
|
||||||
|
:namespace name}
|
||||||
|
config)]
|
||||||
|
(ing/generate-simple-ingress final-config)))
|
||||||
|
|
||||||
(defn-spec generate seq?
|
(defn-spec generate seq?
|
||||||
[config config?
|
[config config?
|
||||||
auth auth?]
|
auth auth?]
|
||||||
(loop [config (sort-config config)
|
(loop [config (sort-config config)
|
||||||
auth (sort-auth auth)
|
sorted-auth (sort-auth auth)
|
||||||
result []]
|
result []]
|
||||||
|
|
||||||
(if (and (empty? (config :websites)) (empty? (auth :auth)))
|
(if (and (empty? (config :websites)) (empty? (sorted-auth :auth)))
|
||||||
result
|
result
|
||||||
(recur (->
|
(recur (->
|
||||||
config
|
config
|
||||||
(assoc-in [:websites] (rest (config :websites))))
|
(assoc-in [:websites] (rest (config :websites))))
|
||||||
(->
|
(->
|
||||||
auth
|
auth
|
||||||
(assoc-in [:auth] (rest (auth :auth))))
|
(assoc-in [:auth] (rest (sorted-auth :auth))))
|
||||||
(cm/concat-vec
|
(let [final-config
|
||||||
result
|
(merge
|
||||||
(website/generate-namespcae (flatten-and-reduce-config config))
|
website-config-defaults
|
||||||
[(website/generate-nginx-deployment (flatten-and-reduce-config config))
|
(flatten-and-reduce-config config))
|
||||||
(website/generate-nginx-configmap (flatten-and-reduce-config config))
|
name (int/replace-dots-by-minus (:unique-name final-config))]
|
||||||
(website/generate-nginx-service (flatten-and-reduce-config config))
|
(cm/concat-vec
|
||||||
(website/generate-content-pvc (flatten-and-reduce-config config))
|
result
|
||||||
(website/generate-hash-state-pvc (flatten-and-reduce-config config))
|
(ns/generate (merge {:namespace name} final-config))
|
||||||
(website/generate-build-cron (flatten-and-reduce-config config))
|
[(int/generate-nginx-deployment final-config)
|
||||||
(website/generate-build-secret (flatten-and-reduce-config config)
|
(int/generate-nginx-configmap final-config)
|
||||||
(flatten-and-reduce-auth auth))]
|
(int/generate-nginx-service final-config)
|
||||||
(website/generate-ingress (flatten-and-reduce-config 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
|
||||||
|
(flatten-and-reduce-auth auth))]
|
||||||
|
(generate-ingress final-config)))))))
|
||||||
|
|
||||||
(defn-spec k8s-objects cp/map-or-seq?
|
(defn-spec k8s-objects cp/map-or-seq?
|
||||||
[config config?
|
[config config?
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
(ns dda.c4k-website.website
|
|
||||||
(:require
|
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
|
||||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
|
||||||
[dda.c4k-common.ingress :as ing]
|
|
||||||
[dda.c4k-common.namespace :as ns]
|
|
||||||
[dda.c4k-website.website.website-internal :as int]))
|
|
||||||
|
|
||||||
(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)
|
|
||||||
|
|
||||||
(def websiteconfig? (s/keys :req-un [::unique-name
|
|
||||||
::fqdns
|
|
||||||
::forgejo-host
|
|
||||||
::forgejo-repo
|
|
||||||
::branchname]
|
|
||||||
:opt-un [::issuer
|
|
||||||
::volume-size
|
|
||||||
::build-cpu-request
|
|
||||||
::build-cpu-limit
|
|
||||||
::build-memory-request
|
|
||||||
::build-memory-limit]))
|
|
||||||
|
|
||||||
(def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken]))
|
|
||||||
|
|
||||||
(def config-defaults {:issuer "staging"
|
|
||||||
:build-cpu-request "500m"
|
|
||||||
:build-cpu-limit "1700m"
|
|
||||||
:build-memory-request "256Mi"
|
|
||||||
:build-memory-limit "512Mi"
|
|
||||||
:volume-size "3"
|
|
||||||
:redirects []})
|
|
||||||
|
|
||||||
(defn-spec generate-nginx-deployment map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-nginx-deployment final-config)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec generate-nginx-configmap map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-nginx-configmap final-config)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec generate-nginx-service map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-nginx-service final-config)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec generate-content-pvc map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-content-pvc final-config)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec generate-hash-state-pvc map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-hash-state-pvc final-config)))
|
|
||||||
|
|
||||||
(defn-spec generate-build-cron map?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-build-cron final-config)))
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec generate-build-secret map?
|
|
||||||
[config websiteconfig?
|
|
||||||
auth websiteauth?]
|
|
||||||
(let [final-config (merge config-defaults
|
|
||||||
config)]
|
|
||||||
(int/generate-build-secret final-config auth)))
|
|
||||||
|
|
||||||
(defn-spec generate-namespcae seq?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [name (int/replace-dots-by-minus (:unique-name config))
|
|
||||||
final-config (merge config-defaults
|
|
||||||
{:namespace name}
|
|
||||||
config)]
|
|
||||||
(ns/generate final-config)))
|
|
||||||
|
|
||||||
(defn-spec generate-ingress seq?
|
|
||||||
[config websiteconfig?]
|
|
||||||
(let [name (int/replace-dots-by-minus (:unique-name config))
|
|
||||||
final-config (merge config-defaults
|
|
||||||
{:service-name name
|
|
||||||
:service-port 80
|
|
||||||
:namespace name}
|
|
||||||
config)]
|
|
||||||
(ing/generate-simple-ingress final-config)))
|
|
|
@ -105,7 +105,7 @@
|
||||||
(-> (cm/generate-common
|
(-> (cm/generate-common
|
||||||
(config-from-document)
|
(config-from-document)
|
||||||
(br/get-content-from-element "auth" :deserializer edn/read-string)
|
(br/get-content-from-element "auth" :deserializer edn/read-string)
|
||||||
website/config-defaults
|
core/config-defaults
|
||||||
core/k8s-objects)
|
core/k8s-objects)
|
||||||
(br/set-output!)))))
|
(br/set-output!)))))
|
||||||
(add-validate-listener "websites")
|
(add-validate-listener "websites")
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
(st/instrument `cut/sort-config)
|
(st/instrument `cut/sort-config)
|
||||||
(st/instrument `cut/flattened-and-reduced-config)
|
(st/instrument `cut/flattened-and-reduced-config)
|
||||||
(st/instrument `cut/flatten-and-reduce-auth)
|
(st/instrument `cut/flatten-and-reduce-auth)
|
||||||
|
(st/instrument `cut/generate-ingress)
|
||||||
(st/instrument `cut/generate)
|
(st/instrument `cut/generate)
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
|
@ -127,5 +128,63 @@
|
||||||
|
|
||||||
(deftest test-generate
|
(deftest test-generate
|
||||||
(is (= 22
|
(is (= 22
|
||||||
(count (cut/generate (yaml/load-as-edn "website-test/valid-config.yaml")
|
(count (cut/generate
|
||||||
(yaml/load-as-edn "website-test/valid-auth.yaml"))))))
|
(yaml/load-as-edn "website-test/valid-config.yaml")
|
||||||
|
(yaml/load-as-edn "website-test/valid-auth.yaml"))))))
|
||||||
|
|
||||||
|
(deftest should-generate-ingress
|
||||||
|
(is (= [{:host "test.de",
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:pathType "Prefix",
|
||||||
|
:path "/",
|
||||||
|
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
||||||
|
{:host "test.org",
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:pathType "Prefix",
|
||||||
|
:path "/",
|
||||||
|
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
||||||
|
{:host "www.test.de",
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:pathType "Prefix",
|
||||||
|
:path "/",
|
||||||
|
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
||||||
|
{:host "www.test.org",
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:pathType "Prefix",
|
||||||
|
:path "/",
|
||||||
|
:backend {:service {:name "test-io", :port {:number 80}}}}]}}]
|
||||||
|
(get-in
|
||||||
|
(cut/generate-ingress {:forgejo-host "gitlab.de",
|
||||||
|
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
|
||||||
|
:forgejo-repo "repo",
|
||||||
|
:sha256sum-output "123456789ab123cd345de script-file-name.sh",
|
||||||
|
:issuer "staging",
|
||||||
|
:branchname "main",
|
||||||
|
:unique-name "test.io"
|
||||||
|
:build-cpu-request "500m"
|
||||||
|
:build-cpu-limit "1700m"
|
||||||
|
:build-memory-request "256Mi"
|
||||||
|
:build-memory-limit "512Mi"
|
||||||
|
:volume-size "3"
|
||||||
|
:redirects []})
|
||||||
|
[2 :spec :rules])))
|
||||||
|
(is (= "test-io"
|
||||||
|
(get-in
|
||||||
|
(cut/generate-ingress {:forgejo-host "gitlab.de",
|
||||||
|
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
|
||||||
|
:forgejo-repo "repo",
|
||||||
|
:sha256sum-output "123456789ab123cd345de script-file-name.sh",
|
||||||
|
:issuer "staging",
|
||||||
|
:branchname "main",
|
||||||
|
:unique-name "test.io"
|
||||||
|
:build-cpu-request "500m"
|
||||||
|
:build-cpu-limit "1700m"
|
||||||
|
:build-memory-request "256Mi"
|
||||||
|
:build-memory-limit "512Mi"
|
||||||
|
:volume-size "3"
|
||||||
|
:redirects []})
|
||||||
|
[2 :metadata :namespace]))))
|
|
@ -1,53 +0,0 @@
|
||||||
(ns dda.c4k-website.website-test
|
|
||||||
(:require
|
|
||||||
#?(: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 :as cut]))
|
|
||||||
|
|
||||||
(st/instrument `cut/generate-ingress)
|
|
||||||
|
|
||||||
(deftest should-generate-ingress
|
|
||||||
(is (= [{:host "test.de",
|
|
||||||
:http
|
|
||||||
{:paths
|
|
||||||
[{:pathType "Prefix",
|
|
||||||
:path "/",
|
|
||||||
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
|
||||||
{:host "test.org",
|
|
||||||
:http
|
|
||||||
{:paths
|
|
||||||
[{:pathType "Prefix",
|
|
||||||
:path "/",
|
|
||||||
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
|
||||||
{:host "www.test.de",
|
|
||||||
:http
|
|
||||||
{:paths
|
|
||||||
[{:pathType "Prefix",
|
|
||||||
:path "/",
|
|
||||||
:backend {:service {:name "test-io", :port {:number 80}}}}]}}
|
|
||||||
{:host "www.test.org",
|
|
||||||
:http
|
|
||||||
{:paths
|
|
||||||
[{:pathType "Prefix",
|
|
||||||
:path "/",
|
|
||||||
:backend {:service {:name "test-io", :port {:number 80}}}}]}}]
|
|
||||||
(get-in
|
|
||||||
(cut/generate-ingress {:forgejo-host "gitlab.de",
|
|
||||||
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
|
|
||||||
:forgejo-repo "repo",
|
|
||||||
:sha256sum-output "123456789ab123cd345de script-file-name.sh",
|
|
||||||
:issuer "staging",
|
|
||||||
:branchname "main",
|
|
||||||
:unique-name "test.io"})
|
|
||||||
[2 :spec :rules])))
|
|
||||||
(is (= "test-io"
|
|
||||||
(get-in
|
|
||||||
(cut/generate-ingress {:forgejo-host "gitlab.de",
|
|
||||||
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
|
|
||||||
:forgejo-repo "repo",
|
|
||||||
:sha256sum-output "123456789ab123cd345de script-file-name.sh",
|
|
||||||
:issuer "staging",
|
|
||||||
:branchname "main",
|
|
||||||
:unique-name "test.io"})
|
|
||||||
[2 :metadata :namespace]))))
|
|
Loading…
Reference in a new issue