You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
c4k-website/src/main/cljc/dda/c4k_website/core.cljc

43 lines
1.9 KiB
Clojure

(ns dda.c4k-website.core
(:require
[clojure.spec.alpha :as s]
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]
[dda.c4k-website.website :as website]))
(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!
; There must be a check or the config must be sorted first!
(defn flatten-and-reduce-config
[config]
(merge (-> config :websites first) (-> config :auth first) (dissoc config :issuer :volume-size)))
(defn generate-configs [config]
(loop [config config
result []]
(if (and (empty? (config :auth)) (empty? (config :websites)))
result
(recur (->
config
(assoc-in [:websites] (rest (config :websites)))
(assoc-in [:auth] (rest (config :auth))))
(conj result
(website/generate-nginx-deployment (flatten-and-reduce-config config))
(website/generate-nginx-configmap (flatten-and-reduce-config config))
(website/generate-nginx-service (flatten-and-reduce-config config))
(website/generate-website-content-volume (flatten-and-reduce-config config))
(website/generate-website-http-ingress (flatten-and-reduce-config config))
(website/generate-website-https-ingress (flatten-and-reduce-config config))
(website/generate-website-certificate (flatten-and-reduce-config config))
(website/generate-website-build-cron (flatten-and-reduce-config config))
(website/generate-website-build-secret (flatten-and-reduce-config config)))))))
(defn k8s-objects [config]
(cm/concat-vec
(map yaml/to-string
(filter #(not (nil? %))
(generate-configs config)))))