Add tests
Fix configmap generation.
This commit is contained in:
parent
f0a69e7fda
commit
bca85d1da4
4 changed files with 19 additions and 13 deletions
|
@ -5,6 +5,7 @@
|
||||||
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
||||||
:dependencies [[org.clojure/clojure "1.10.3"]
|
:dependencies [[org.clojure/clojure "1.10.3"]
|
||||||
[org.clojure/tools.reader "1.3.6"]
|
[org.clojure/tools.reader "1.3.6"]
|
||||||
|
[org.clojure/math.numeric-tower "0.0.5"]
|
||||||
[org.domaindrivenarchitecture/c4k-common-clj "3.0.1"]
|
[org.domaindrivenarchitecture/c4k-common-clj "3.0.1"]
|
||||||
[hickory "0.7.1"]]
|
[hickory "0.7.1"]]
|
||||||
:target-path "target/%s/"
|
:target-path "target/%s/"
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
[dda.c4k-common.common :as cm]
|
[dda.c4k-common.common :as cm]
|
||||||
[dda.c4k-website.website :as website]))
|
[dda.c4k-website.website :as website]))
|
||||||
|
|
||||||
(defn k8s-objects [config]
|
(defn k8s-objects [config]
|
||||||
(let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)]
|
|
||||||
(cm/concat-vec
|
(cm/concat-vec
|
||||||
(map yaml/to-string
|
(map yaml/to-string
|
||||||
(filter #(not (nil? %))
|
(filter #(not (nil? %))
|
||||||
|
@ -14,4 +13,4 @@
|
||||||
(website/generate-nginx-configmap config)
|
(website/generate-nginx-configmap config)
|
||||||
(website/generate-nginx-deployment)
|
(website/generate-nginx-deployment)
|
||||||
(website/generate-nginx-service)
|
(website/generate-nginx-service)
|
||||||
(website/generate-website-content-volume config)])))))
|
(website/generate-website-content-volume config)]))))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns dda.c4k-website.website
|
(ns dda.c4k-website.website
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.math :as m]
|
[clojure.math.numeric-tower :as m]
|
||||||
[clojure.string :as st]
|
[clojure.string :as st]
|
||||||
#?(:cljs [shadow.resource :as rc])
|
#?(:cljs [shadow.resource :as rc])
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
|
@ -21,12 +21,16 @@
|
||||||
(s/def ::fqdn pred/fqdn-string?)
|
(s/def ::fqdn pred/fqdn-string?)
|
||||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||||
(s/def ::volume-total-storage-size (partial pred/int-gt-n? 5))
|
(s/def ::volume-total-storage-size (partial pred/int-gt-n? 5))
|
||||||
|
(s/def ::mailer-user pred/bash-env-string?)
|
||||||
|
(s/def ::mailer-pw pred/bash-env-string?)
|
||||||
|
|
||||||
(def config-defaults {:issuer "staging"})
|
(def config-defaults {:issuer "staging"})
|
||||||
|
|
||||||
(def config? (s/keys :req-un [::fqdn]
|
(def config? (s/keys :req-un [::fqdn]
|
||||||
:opt-un [::issuer]))
|
:opt-un [::issuer]))
|
||||||
|
|
||||||
|
(def auth? (s/keys :opt-un [::mailer-user ::mailer-pw]))
|
||||||
|
|
||||||
(def vol? (s/keys :req-un [::volume-total-storage-size
|
(def vol? (s/keys :req-un [::volume-total-storage-size
|
||||||
::number-of-websites]))
|
::number-of-websites]))
|
||||||
|
|
||||||
|
@ -68,11 +72,13 @@
|
||||||
|
|
||||||
(defn-spec generate-nginx-configmap pred/map-or-seq?
|
(defn-spec generate-nginx-configmap pred/map-or-seq?
|
||||||
[config config?]
|
[config config?]
|
||||||
(let [{:keys [fqdn]} config]
|
(let [{:keys [fqdn]} config
|
||||||
(->
|
configmap (yaml/load-as-edn "website/nginx-configmap.yaml")]
|
||||||
(yaml/load-as-edn "website/nginx-configmap.yaml")
|
(->
|
||||||
(cm/replace-all-matching-values-by-new-value "FQDN" (str fqdn ";"))
|
configmap
|
||||||
)))
|
(assoc-in [:data :website.conf] (st/replace (-> configmap :data :website.conf) #"FQDN" fqdn))
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
(defn-spec generate-nginx-deployment pred/map-or-seq?
|
(defn-spec generate-nginx-deployment pred/map-or-seq?
|
||||||
[]
|
[]
|
|
@ -30,11 +30,11 @@
|
||||||
})))))
|
})))))
|
||||||
|
|
||||||
(deftest should-generate-nginx-configmap
|
(deftest should-generate-nginx-configmap
|
||||||
(is (= {:server_name-c1 "test.de",
|
(is (= {:website.conf-c1 "server {\n\n listen 80 default_server;\n listen [::]:80 default_server;\n\n listen 443 ssl;\n\n ssl_certificate /etc/certs/tls.crt;\n ssl_certificate_key /etc/certs/tls.key;\n\n server_name test.de\n\n # security headers\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';\n add_header Content-Security-Policy \"default-src 'self'; font-src *;img-src * data:; script-src *; style-src *\";\n add_header X-XSS-Protection \"1; mode=block\";\n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # maybe need to add:\n # add_header Permissions-Policy \"permissions here\";\n\n root /var/www/html/website/;\n # root /usr/share/nginx/html/; # testing purposes\n\n index index.html;\n\n try_files $uri /index.html;\n\n}",
|
||||||
:server_name-c2 "test.com"}
|
:website.conf-c2 "server {\n\n listen 80 default_server;\n listen [::]:80 default_server;\n\n listen 443 ssl;\n\n ssl_certificate /etc/certs/tls.crt;\n ssl_certificate_key /etc/certs/tls.key;\n\n server_name test.com\n\n # security headers\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';\n add_header Content-Security-Policy \"default-src 'self'; font-src *;img-src * data:; script-src *; style-src *\";\n add_header X-XSS-Protection \"1; mode=block\";\n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # maybe need to add:\n # add_header Permissions-Policy \"permissions here\";\n\n root /var/www/html/website/;\n # root /usr/share/nginx/html/; # testing purposes\n\n index index.html;\n\n try_files $uri /index.html;\n\n}"}
|
||||||
(th/map-diff (cut/generate-appini-env {:fqdn "test.de"
|
(th/map-diff (cut/generate-nginx-configmap {:fqdn "test.de"
|
||||||
})
|
})
|
||||||
(cut/generate-appini-env {:fqdn "test.com"
|
(cut/generate-nginx-configmap {:fqdn "test.com"
|
||||||
})))))
|
})))))
|
||||||
|
|
||||||
(deftest should-generate-website-content-volume
|
(deftest should-generate-website-content-volume
|
||||||
|
|
Loading…
Reference in a new issue