Move spec to gitea and instrument generate functions
This commit is contained in:
parent
08ac2ae1c2
commit
810ff3783f
4 changed files with 24 additions and 15 deletions
|
@ -2,7 +2,8 @@
|
||||||
(:gen-class)
|
(:gen-class)
|
||||||
(:require
|
(:require
|
||||||
[dda.c4k-gitea.core :as core]
|
[dda.c4k-gitea.core :as core]
|
||||||
|
[dda.c4k-gitea.gitea :as gitea]
|
||||||
[dda.c4k-common.uberjar :as uberjar]))
|
[dda.c4k-common.uberjar :as uberjar]))
|
||||||
|
|
||||||
(defn -main [& cmd-args]
|
(defn -main [& cmd-args]
|
||||||
(uberjar/main-common "c4k-gitea" core/config? core/auth? core/config-defaults core/k8s-objects cmd-args))
|
(uberjar/main-common "c4k-gitea" gitea/config? gitea/auth? gitea/config-defaults core/k8s-objects cmd-args))
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
(ns dda.c4k-gitea.core
|
(ns dda.c4k-gitea.core
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.common :as cm]
|
[dda.c4k-common.common :as cm]
|
||||||
[dda.c4k-common.postgres :as postgres]
|
|
||||||
[dda.c4k-gitea.gitea :as gitea]))
|
[dda.c4k-gitea.gitea :as gitea]))
|
||||||
|
|
||||||
(def config-defaults {:issuer "staging"})
|
|
||||||
|
|
||||||
(def config? (s/keys :req-un [::gitea/fqdn]
|
|
||||||
:opt-un [::gitea/issuer]))
|
|
||||||
|
|
||||||
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password]))
|
|
||||||
|
|
||||||
(defn k8s-objects [config]
|
(defn k8s-objects [config]
|
||||||
(let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)]
|
(let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)]
|
||||||
(cm/concat-vec
|
(cm/concat-vec
|
||||||
|
|
|
@ -2,13 +2,23 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
#?(:cljs [shadow.resource :as rc])
|
#?(:cljs [shadow.resource :as rc])
|
||||||
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.common :as cm]
|
[dda.c4k-common.common :as cm]
|
||||||
[dda.c4k-common.predicate :as pred]))
|
[dda.c4k-common.predicate :as pred]
|
||||||
|
[dda.c4k-common.postgres :as postgres]))
|
||||||
|
|
||||||
(s/def ::fqdn pred/fqdn-string?)
|
(s/def ::fqdn pred/fqdn-string?)
|
||||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||||
|
|
||||||
|
(def config-defaults {:issuer "staging"})
|
||||||
|
|
||||||
|
(def config? (s/keys :req-un [::fqdn]
|
||||||
|
:opt-un [::issuer]))
|
||||||
|
|
||||||
|
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password]))
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(defmethod yaml/load-resource :gitea [resource-name]
|
(defmethod yaml/load-resource :gitea [resource-name]
|
||||||
(case resource-name
|
(case resource-name
|
||||||
|
@ -24,7 +34,9 @@
|
||||||
(defmethod yaml/load-as-edn :gitea [resource-name]
|
(defmethod yaml/load-as-edn :gitea [resource-name]
|
||||||
(yaml/from-string (yaml/load-resource resource-name))))
|
(yaml/from-string (yaml/load-resource resource-name))))
|
||||||
|
|
||||||
(defn generate-appini-env [config]
|
(defn-spec generate-appini-env pred/map-or-seq?
|
||||||
|
; TODO: fix this to require the merged spec of auth and config instead of any
|
||||||
|
[config any?]
|
||||||
(let [{:keys [postgres-db-user postgres-db-password fqdn]} config]
|
(let [{:keys [postgres-db-user postgres-db-password fqdn]} config]
|
||||||
(->
|
(->
|
||||||
(yaml/load-as-edn "gitea/appini-env-configmap.yaml")
|
(yaml/load-as-edn "gitea/appini-env-configmap.yaml")
|
||||||
|
@ -33,7 +45,8 @@
|
||||||
(cm/replace-all-matching-values-by-new-value "DBUSER" postgres-db-user)
|
(cm/replace-all-matching-values-by-new-value "DBUSER" postgres-db-user)
|
||||||
(cm/replace-all-matching-values-by-new-value "DBPW" postgres-db-password))))
|
(cm/replace-all-matching-values-by-new-value "DBPW" postgres-db-password))))
|
||||||
|
|
||||||
(defn generate-ingress [config]
|
(defn-spec generate-ingress pred/map-or-seq?
|
||||||
|
[config config?]
|
||||||
(let [{:keys [fqdn issuer]
|
(let [{:keys [fqdn issuer]
|
||||||
:or {issuer "staging"}} config
|
:or {issuer "staging"}} config
|
||||||
letsencrypt-issuer (name issuer)]
|
letsencrypt-issuer (name issuer)]
|
||||||
|
|
|
@ -2,9 +2,13 @@
|
||||||
(:require
|
(:require
|
||||||
#?(: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]
|
||||||
[dda.c4k-common.common-test :as ct]
|
[dda.c4k-common.common-test :as ct]
|
||||||
[dda.c4k-gitea.gitea :as cut]))
|
[dda.c4k-gitea.gitea :as cut]))
|
||||||
|
|
||||||
|
(st/instrument `cut/generate-appini-env)
|
||||||
|
(st/instrument `cut/generate-ingress)
|
||||||
|
|
||||||
(deftest should-generate-appini-env
|
(deftest should-generate-appini-env
|
||||||
(is (= {:GITEA__database__USER-c1 nil,
|
(is (= {:GITEA__database__USER-c1 nil,
|
||||||
:GITEA__database__USER-c2 "pg-user",
|
:GITEA__database__USER-c2 "pg-user",
|
||||||
|
@ -18,5 +22,5 @@
|
||||||
(cut/generate-appini-env {:fqdn "test.com" :issuer "staging" :postgres-db-user "pg-user" :postgres-db-password "pg-pw"})))))
|
(cut/generate-appini-env {:fqdn "test.com" :issuer "staging" :postgres-db-user "pg-user" :postgres-db-password "pg-pw"})))))
|
||||||
|
|
||||||
(deftest should-generate-ingress
|
(deftest should-generate-ingress
|
||||||
(is (= {:hosts-c1 nil, :hosts-c2 "test.com", :host-c1 nil, :host-c2 "test.com"}
|
(is (= {:hosts-c1 "abc.de", :hosts-c2 "test.com", :host-c1 "abc.de", :host-c2 "test.com"}
|
||||||
(ct/map-diff (cut/generate-ingress {}) (cut/generate-ingress {:fqdn "test.com" :issuer "staging"})))))
|
(ct/map-diff (cut/generate-ingress {:fqdn "abc.de"}) (cut/generate-ingress {:fqdn "test.com" :issuer "staging"})))))
|
||||||
|
|
Loading…
Reference in a new issue