Merge branch 'split-config-and-auth-input' into 'main'

Do not merge config and auth

See merge request domaindrivenarchitecture/c4k-website!5
pull/1/head
Pat Dyn 1 year ago
commit f91269fb94

@ -21,7 +21,7 @@ Repository Settings -> Protected Tags -> set \*.\*.\* as tag and save.
``` bash ``` bash
git checkout main # for old projects replace main with master git checkout main # for old projects replace main with master
git add . git add .
git commit git commit
``` ```
Open package.json, find ":version" keyword and remove "-SNAPSHOT" from version number. Open package.json, find ":version" keyword and remove "-SNAPSHOT" from version number.
@ -67,7 +67,7 @@ git push --follow-tags
Open package.json again, increase version increment by one and add "-SNAPSHOT". Open package.json again, increase version increment by one and add "-SNAPSHOT".
``` bash ``` bash
git commit -am "version bump" git commit -am "[Skip-CI] version bump"
git push git push
``` ```

@ -23,35 +23,45 @@
(def auth? (s/keys :req-un [::website/auth] (def auth? (s/keys :req-un [::website/auth]
:opt-un [::mon-auth])) :opt-un [::mon-auth]))
(def merged-config-and-auth? (s/and website/config? website/auth?))
(defn-spec sort-config cp/map-or-seq? (defn-spec sort-config cp/map-or-seq?
[unsorted-config merged-config-and-auth?] [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)))]
sorted-auth (into [] (sort-by :unique-name (unsorted-config :auth)))]
(-> unsorted-config (-> unsorted-config
(assoc-in [:websites] sorted-websites) (assoc-in [:websites] sorted-websites))))
(defn-spec sort-auth cp/map-or-seq?
[unsorted-auth auth?]
(let [sorted-auth (into [] (sort-by :unique-name (unsorted-auth :auth)))]
(-> unsorted-auth
(assoc-in [:auth] sorted-auth)))) (assoc-in [:auth] sorted-auth))))
(defn-spec flatten-and-reduce-config cp/map-or-seq? (defn-spec flatten-and-reduce-config cp/map-or-seq?
[config merged-config-and-auth?] [config config?]
(merge (-> config :websites first) (let
(-> config :auth first) [first-entry (first (:websites config))]
(when (contains? config :issuer) (conj first-entry
{:issuer (config :issuer)}) (when (contains? config :issuer)
(when (contains? config :volume-size) {:issuer (config :issuer)})
{:volume-size (config :volume-size)}))) (when (contains? config :volume-size)
{:volume-size (config :volume-size)}))))
(defn-spec flatten-and-reduce-auth cp/map-or-seq?
[auth auth?]
(-> auth :auth first))
(defn generate-configs [config] (defn generate-configs [config auth]
(loop [config (sort-config config) (loop [config (sort-config config)
auth (sort-auth auth)
result []] result []]
(if (and (empty? (config :auth)) (empty? (config :websites))) (if (and (empty? (config :websites)) (empty? (auth :auth)))
result result
(recur (-> (recur (->
config config
(assoc-in [:websites] (rest (config :websites))) (assoc-in [:websites] (rest (config :websites))))
(assoc-in [:auth] (rest (config :auth)))) (->
auth
(assoc-in [:auth] (rest (auth :auth))))
(conj result (conj result
(website/generate-nginx-deployment (flatten-and-reduce-config config)) (website/generate-nginx-deployment (flatten-and-reduce-config config))
(website/generate-nginx-configmap (flatten-and-reduce-config config)) (website/generate-nginx-configmap (flatten-and-reduce-config config))
@ -60,8 +70,8 @@
(website/generate-hashfile-volume (flatten-and-reduce-config config)) (website/generate-hashfile-volume (flatten-and-reduce-config config))
(website/generate-website-ingress (flatten-and-reduce-config config)) (website/generate-website-ingress (flatten-and-reduce-config config))
(website/generate-website-certificate (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-cron (flatten-and-reduce-config config))
(website/generate-website-build-secret (flatten-and-reduce-config config))))))) (website/generate-website-build-secret (flatten-and-reduce-config config) (flatten-and-reduce-auth auth)))))))
(defn-spec k8s-objects cp/map-or-seq? (defn-spec k8s-objects cp/map-or-seq?
[config config? [config config?
@ -71,6 +81,6 @@
(filter (filter
#(not (nil? %)) #(not (nil? %))
(cm/concat-vec (cm/concat-vec
(generate-configs (merge config auth)) (generate-configs config auth)
(when (:contains? config :mon-cfg) (when (:contains? config :mon-cfg)
(mon/generate (:mon-cfg config) (:mon-auth auth)))))))) (mon/generate (:mon-cfg config) (:mon-auth auth))))))))

@ -32,32 +32,25 @@
(s/def ::build-cpu-limit string?) (s/def ::build-cpu-limit string?)
(s/def ::build-memory-limit string?) (s/def ::build-memory-limit string?)
(def websitedata? (s/keys :req-un [::unique-name (def websiteconfig? (s/keys :req-un [::unique-name
::fqdns ::fqdns
::gitea-host ::gitea-host
::gitea-repo ::gitea-repo
::branchname] ::branchname]
:opt-un [::issuer :opt-un [::issuer
::volume-size ::volume-size
::sha256sum-output ::sha256sum-output
::build-cpu-request ::build-cpu-request
::build-cpu-limit ::build-cpu-limit
::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]))
(def flattened-and-reduced-config? (s/and websitedata? websiteauth?)) (s/def ::websites (s/coll-of websiteconfig?))
(s/def ::auth (s/coll-of websiteauth?)) (s/def ::auth (s/coll-of websiteauth?))
(s/def ::websites (s/coll-of websitedata?))
(def auth? (s/keys :req-un [::auth]))
(def config? (s/keys :req-un [::websites]
:opt-un [::issuer ::volume-size]))
(defn-spec get-hash-from-sha256sum-output string? (defn-spec get-hash-from-sha256sum-output string?
[sha256sum-output string?] [sha256sum-output string?]
(if (nil? sha256sum-output) (if (nil? sha256sum-output)
@ -116,7 +109,7 @@
(defn-spec replace-common-data pred/map-or-seq? (defn-spec replace-common-data pred/map-or-seq?
[resource-file string? [resource-file string?
config flattened-and-reduced-config?] config websiteconfig?]
(let [{:keys [unique-name]} config] (let [{:keys [unique-name]} config]
(-> (->
(yaml/load-as-edn resource-file) (yaml/load-as-edn resource-file)
@ -125,7 +118,7 @@
(defn-spec replace-build-data pred/map-or-seq? (defn-spec replace-build-data pred/map-or-seq?
[resource-file string? [resource-file string?
config flattened-and-reduced-config?] config websiteconfig?]
(let [{:keys [sha256sum-output build-cpu-request build-cpu-limit build-memory-request build-memory-limit] (let [{:keys [sha256sum-output build-cpu-request build-cpu-limit build-memory-request build-memory-limit]
:or {build-cpu-request "500m" build-cpu-limit "1700m" build-memory-request "256Mi" build-memory-limit "512Mi"}} config] :or {build-cpu-request "500m" build-cpu-limit "1700m" build-memory-request "256Mi" build-memory-limit "512Mi"}} config]
(-> (->
@ -149,26 +142,12 @@
"website/hashfile-volume.yaml" (rc/inline "website/hashfile-volume.yaml") "website/hashfile-volume.yaml" (rc/inline "website/hashfile-volume.yaml")
(throw (js/Error. "Undefined Resource!"))))) (throw (js/Error. "Undefined Resource!")))))
(defn-spec generate-website-ingress pred/map-or-seq? (defn-spec generate-nginx-deployment pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(let [{:keys [unique-name fqdns]} config] (replace-build-data "website/nginx-deployment.yaml" config))
(ing/generate-ingress {:fqdns fqdns
:app-name (generate-app-name unique-name)
:ingress-name (generate-ingress-name unique-name)
:service-name (generate-service-name unique-name)
:service-port 80})))
(defn-spec generate-website-certificate pred/map-or-seq?
[config flattened-and-reduced-config?]
(let [{:keys [unique-name issuer fqdns]
:or {issuer "staging"}} config]
(ing/generate-certificate {:fqdns fqdns
:app-name (generate-app-name unique-name)
:cert-name (generate-cert-name unique-name)
:issuer issuer})))
(defn-spec generate-nginx-configmap pred/map-or-seq? (defn-spec generate-nginx-configmap pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(let [{:keys [fqdns]} config] (let [{:keys [fqdns]} config]
(-> (->
(replace-common-data "website/nginx-configmap.yaml" config) (replace-common-data "website/nginx-configmap.yaml" config)
@ -177,16 +156,12 @@
(str/replace (str/replace
(-> % :data :website.conf) #"FQDN" (str (str/join " " fqdns) ";"))))))) (-> % :data :website.conf) #"FQDN" (str (str/join " " fqdns) ";")))))))
(defn-spec generate-nginx-deployment pred/map-or-seq?
[config flattened-and-reduced-config?]
(replace-build-data "website/nginx-deployment.yaml" config))
(defn-spec generate-nginx-service pred/map-or-seq? (defn-spec generate-nginx-service pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(replace-common-data "website/nginx-service.yaml" config)) (replace-common-data "website/nginx-service.yaml" config))
(defn-spec generate-website-content-volume pred/map-or-seq? (defn-spec generate-website-content-volume pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(let [{:keys [volume-size] (let [{:keys [volume-size]
:or {volume-size "3"}} config] :or {volume-size "3"}} config]
(-> (->
@ -194,32 +169,52 @@
(cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str volume-size "Gi"))))) (cm/replace-all-matching-values-by-new-value "WEBSITESTORAGESIZE" (str volume-size "Gi")))))
(defn-spec generate-hashfile-volume pred/map-or-seq? (defn-spec generate-hashfile-volume pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(replace-common-data "website/hashfile-volume.yaml" config)) (replace-common-data "website/hashfile-volume.yaml" config))
(defn-spec generate-website-ingress pred/map-or-seq?
[config websiteconfig?]
(let [{:keys [unique-name fqdns]} config]
(ing/generate-ingress {:fqdns fqdns
:app-name (generate-app-name unique-name)
:ingress-name (generate-ingress-name unique-name)
:service-name (generate-service-name unique-name)
:service-port 80})))
(defn-spec generate-website-certificate pred/map-or-seq?
[config websiteconfig?]
(let [{:keys [unique-name issuer fqdns]
:or {issuer "staging"}} config]
(ing/generate-certificate {:fqdns fqdns
:app-name (generate-app-name unique-name)
:cert-name (generate-cert-name unique-name)
:issuer issuer})))
(defn-spec generate-website-build-cron pred/map-or-seq? (defn-spec generate-website-build-cron pred/map-or-seq?
[config flattened-and-reduced-config?] [config websiteconfig?]
(replace-build-data "website/website-build-cron.yaml" config)) (replace-build-data "website/website-build-cron.yaml" config))
(defn-spec generate-website-build-secret pred/map-or-seq? (defn-spec generate-website-build-secret pred/map-or-seq?
[auth flattened-and-reduced-config?] [config websiteconfig?
(let [{:keys [authtoken auth websiteauth?]
gitea-host (let [{:keys [gitea-host
gitea-repo gitea-repo
username branchname]} config
branchname]} auth] {:keys [authtoken
username]} auth]
(-> (->
(replace-common-data "website/website-build-secret.yaml" auth) (replace-common-data "website/website-build-secret.yaml" config)
(cm/replace-all-matching-values-by-new-value "TOKEN" (b64/encode authtoken)) (cm/replace-all-matching-values-by-new-value "TOKEN" (b64/encode authtoken))
(cm/replace-all-matching-values-by-new-value "REPOURL" (b64/encode (cm/replace-all-matching-values-by-new-value "REPOURL" (b64/encode
(generate-gitrepourl (generate-gitrepourl
gitea-host gitea-host
gitea-repo gitea-repo
username username
branchname))) branchname)))
(cm/replace-all-matching-values-by-new-value "COMMITURL" (b64/encode (cm/replace-all-matching-values-by-new-value "COMMITURL" (b64/encode
(generate-gitcommiturl (generate-gitcommiturl
gitea-host gitea-host
gitea-repo gitea-repo
username)))))) username))))))

@ -19,7 +19,7 @@
(is (s/valid? cut/config? (yaml/load-as-edn "website-test/valid-config.yaml"))) (is (s/valid? cut/config? (yaml/load-as-edn "website-test/valid-config.yaml")))
(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 websites (def websites1
{:websites {:websites
[{:unique-name "example.io" [{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"] :fqdns ["example.org", "www.example.com"]
@ -32,6 +32,19 @@
:gitea-repo "repo" :gitea-repo "repo"
:branchname "main"}]}) :branchname "main"}]})
(def websites2
{:websites
[{:unique-name "test.io"
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:gitea-host "gitlab.de"
:gitea-repo "repo"
:branchname "main"}
{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"]
:gitea-host "finegitehost.net"
:gitea-repo "repo"
:branchname "main"}]})
(def auth1 (def auth1
{:auth {:auth
[{:unique-name "example.io" [{:unique-name "example.io"
@ -55,14 +68,54 @@
:fqdns ["example.org" "www.example.com"], :fqdns ["example.org" "www.example.com"],
:gitea-host "finegitehost.net", :gitea-host "finegitehost.net",
:gitea-repo "repo", :gitea-repo "repo",
:branchname "main", :branchname "main"})
(def flattened-and-reduced-auth
{:unique-name "example.io",
:username "someuser", :username "someuser",
:authtoken "abedjgbasdodj"}) :authtoken "abedjgbasdodj"})
(deftest sorts-config
(is (= {:issuer "staging",
:websites
[{:unique-name "example.io",
:fqdns ["example.org" "www.example.com"],
:gitea-host "finegitehost.net",
:gitea-repo "repo",
:branchname "main"},
{:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-host "gitlab.de",
:gitea-repo "repo",
:branchname "main",
:sha256sum-output "123456789ab123cd345de script-file-name.sh"}],
:mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}}
(cut/sort-config
{:issuer "staging",
:websites
[{:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-host "gitlab.de",
:gitea-repo "repo",
:branchname "main",
:sha256sum-output "123456789ab123cd345de script-file-name.sh"}
{:unique-name "example.io",
:fqdns ["example.org" "www.example.com"],
:gitea-host "finegitehost.net",
:gitea-repo "repo",
:branchname "main"}],
:mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}}))))
(deftest test-flatten-and-reduce-config (deftest test-flatten-and-reduce-config
(is (= (is (=
(cut/flatten-and-reduce-config (cut/sort-config (merge websites auth1))) flattened-and-reduced-config
flattened-and-reduced-config)) (cut/flatten-and-reduce-config (cut/sort-config websites1))))
(is (= (is (=
(cut/flatten-and-reduce-config (cut/sort-config (merge websites auth2))) flattened-and-reduced-config
flattened-and-reduced-config))) (cut/flatten-and-reduce-config (cut/sort-config websites2)))))
(deftest test-flatten-and-reduce-auth
(is (= flattened-and-reduced-auth
(cut/flatten-and-reduce-auth (cut/sort-auth auth1))))
(is (= flattened-and-reduced-auth
(cut/flatten-and-reduce-auth (cut/sort-auth auth2)))))

@ -4,7 +4,7 @@
: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-common.test-helper :as th] [dda.c4k-common.test-helper :as th]
[dda.c4k-common.base64 :as b64] [dda.c4k-common.base64 :as b64]
[dda.c4k-website.website :as cut] [dda.c4k-website.website :as cut]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
@ -18,54 +18,25 @@
(st/instrument `cut/generate-website-build-cron) (st/instrument `cut/generate-website-build-cron)
(st/instrument `cut/generate-website-build-secret) (st/instrument `cut/generate-website-build-secret)
(deftest should-be-valid-website-auth-spec
(is (true? (s/valid? cut/auth? {:auth
[{:unique-name "test.io"
:username "someuser"
:authtoken "abedjgbasdodj"}
{:unique-name "example.io"
:username "someuser"
:authtoken "abedjgbasdodj"}]}))))
(deftest should-be-valid-website-conf-spec
(is (true? (s/valid? cut/config? {:issuer "staging"
:websites
[{:unique-name "test.io" ;
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:gitea-host "gitlab.de"
:gitea-repo "repo"
:branchname "main"}
{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"]
:gitea-host "finegitehost.net"
:gitea-repo "repo"
:branchname "main"}]}))))
(deftest should-generate-nginx-configmap-website (deftest should-generate-nginx-configmap-website
(is (= "server {\n listen 80 default_server;\n listen [::]:80 default_server;\n server_name test.de www.test.de test-it.de www.test-it.de;\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload'; \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # add_header Permissions-Policy \"permissions here\";\n root /var/www/html/website/;\n index index.html;\n location / {\n try_files $uri $uri/ /index.html =404;\n }\n}\n" (is (= "server {\n listen 80 default_server;\n listen [::]:80 default_server;\n server_name test.de www.test.de test-it.de www.test-it.de;\n add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload'; \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options nosniff;\n add_header Referrer-Policy \"strict-origin\";\n # add_header Permissions-Policy \"permissions here\";\n root /var/www/html/website/;\n index index.html;\n location / {\n try_files $uri $uri/ /index.html =404;\n }\n}\n"
(:website.conf (:data (cut/generate-nginx-configmap {:unique-name "test.io", (:website.conf (:data (cut/generate-nginx-configmap {:unique-name "test.io",
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
:username "someuser"
:authtoken "abedjgbasdodj"})))))
(is (= "types {\n text/html html htm shtml;\n text/css css;\n text/xml xml rss;\n image/gif gif;\n image/jpeg jpeg jpg;\n application/x-javascript js;\n text/plain txt;\n text/x-component htc;\n text/mathml mml;\n image/svg+xml svg svgz;\n image/png png;\n image/x-icon ico;\n image/x-jng jng;\n image/vnd.wap.wbmp wbmp;\n application/java-archive jar war ear;\n application/mac-binhex40 hqx;\n application/pdf pdf;\n application/x-cocoa cco;\n application/x-java-archive-diff jardiff;\n application/x-java-jnlp-file jnlp;\n application/x-makeself run;\n application/x-perl pl pm;\n application/x-pilot prc pdb;\n application/x-rar-compressed rar;\n application/x-redhat-package-manager rpm;\n application/x-sea sea;\n application/x-shockwave-flash swf;\n application/x-stuffit sit;\n application/x-tcl tcl tk;\n application/x-x509-ca-cert der pem crt;\n application/x-xpinstall xpi;\n application/zip zip;\n application/octet-stream deb;\n application/octet-stream bin exe dll;\n application/octet-stream dmg;\n application/octet-stream eot;\n application/octet-stream iso img;\n application/octet-stream msi msp msm;\n audio/mpeg mp3;\n audio/x-realaudio ra;\n video/mpeg mpeg mpg;\n video/quicktime mov;\n video/x-flv flv;\n video/x-msvideo avi;\n video/x-ms-wmv wmv;\n video/x-ms-asf asx asf;\n video/x-mng mng;\n}\n" (is (= "types {\n text/html html htm shtml;\n text/css css;\n text/xml xml rss;\n image/gif gif;\n image/jpeg jpeg jpg;\n application/x-javascript js;\n text/plain txt;\n text/x-component htc;\n text/mathml mml;\n image/svg+xml svg svgz;\n image/png png;\n image/x-icon ico;\n image/x-jng jng;\n image/vnd.wap.wbmp wbmp;\n application/java-archive jar war ear;\n application/mac-binhex40 hqx;\n application/pdf pdf;\n application/x-cocoa cco;\n application/x-java-archive-diff jardiff;\n application/x-java-jnlp-file jnlp;\n application/x-makeself run;\n application/x-perl pl pm;\n application/x-pilot prc pdb;\n application/x-rar-compressed rar;\n application/x-redhat-package-manager rpm;\n application/x-sea sea;\n application/x-shockwave-flash swf;\n application/x-stuffit sit;\n application/x-tcl tcl tk;\n application/x-x509-ca-cert der pem crt;\n application/x-xpinstall xpi;\n application/zip zip;\n application/octet-stream deb;\n application/octet-stream bin exe dll;\n application/octet-stream dmg;\n application/octet-stream eot;\n application/octet-stream iso img;\n application/octet-stream msi msp msm;\n audio/mpeg mp3;\n audio/x-realaudio ra;\n video/mpeg mpeg mpg;\n video/quicktime mov;\n video/x-flv flv;\n video/x-msvideo avi;\n video/x-ms-wmv wmv;\n video/x-ms-asf asx asf;\n video/x-mng mng;\n}\n"
(:mime.types (:data (cut/generate-nginx-configmap {:unique-name "test.io", (:mime.types (:data (cut/generate-nginx-configmap {:unique-name "test.io",
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
:username "someuser"
:authtoken "abedjgbasdodj"})))))
(is (= "user nginx;\nworker_processes 3;\nerror_log /var/log/nginx/error.log;\npid /var/log/nginx/nginx.pid;\nworker_rlimit_nofile 8192;\nevents {\n worker_connections 4096;\n}\nhttp {\n include /etc/nginx/mime.types;\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status'\n '\"$request\" $body_bytes_sent \"$http_referer\"'\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n access_log /var/log/nginx/access.log main;\n sendfile on;\n tcp_nopush on;\n keepalive_timeout 65;\n server_names_hash_bucket_size 128;\n include /etc/nginx/conf.d/website.conf;\n}\n" (is (= "user nginx;\nworker_processes 3;\nerror_log /var/log/nginx/error.log;\npid /var/log/nginx/nginx.pid;\nworker_rlimit_nofile 8192;\nevents {\n worker_connections 4096;\n}\nhttp {\n include /etc/nginx/mime.types;\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status'\n '\"$request\" $body_bytes_sent \"$http_referer\"'\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n access_log /var/log/nginx/access.log main;\n sendfile on;\n tcp_nopush on;\n keepalive_timeout 65;\n server_names_hash_bucket_size 128;\n include /etc/nginx/conf.d/website.conf;\n}\n"
(:nginx.conf (:data (cut/generate-nginx-configmap {:unique-name "test.io", (:nginx.conf (:data (cut/generate-nginx-configmap {:unique-name "test.io",
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
:username "someuser"
:authtoken "abedjgbasdodj"})))))
(is (= {:apiVersion "v1", (is (= {:apiVersion "v1",
:kind "ConfigMap", :kind "ConfigMap",
:metadata {:name "test-io-configmap", :metadata {:name "test-io-configmap",
@ -75,9 +46,7 @@
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :data))))
:username "someuser"
:authtoken "abedjgbasdodj"}) :data))))
(deftest should-generate-nginx-deployment (deftest should-generate-nginx-deployment
(is (= {:apiVersion "apps/v1", (is (= {:apiVersion "apps/v1",
@ -119,9 +88,7 @@
{:name "log", :emptyDir {}} {:name "log", :emptyDir {}}
{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}} {:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}}
{:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}]}}}} {:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}]}}}}
(cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:gitea-host "gitlab.de",
:username "someuser",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh", :sha256sum-output "123456789ab123cd345de script-file-name.sh",
@ -131,9 +98,7 @@
(deftest should-generate-resource-requests (deftest should-generate-resource-requests
(is (= {:requests {:cpu "500m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}} (is (= {:requests {:cpu "500m", :memory "256Mi"}, :limits {:cpu "1700m", :memory "512Mi"}}
(-> (cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", (-> (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:gitea-host "gitlab.de",
:username "someuser",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh", :sha256sum-output "123456789ab123cd345de script-file-name.sh",
@ -142,9 +107,7 @@
:unique-name "test.io"}) :unique-name "test.io"})
:spec :template :spec :initContainers first :resources ))) :spec :template :spec :initContainers first :resources )))
(is (= {:requests {:cpu "1500m", :memory "512Mi"}, :limits {:cpu "3000m", :memory "1024Mi"}} (is (= {:requests {:cpu "1500m", :memory "512Mi"}, :limits {:cpu "3000m", :memory "1024Mi"}}
(-> (cut/generate-nginx-deployment {:authtoken "abedjgbasdodj", (-> (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:gitea-host "gitlab.de",
:username "someuser",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh", :sha256sum-output "123456789ab123cd345de script-file-name.sh",
@ -168,16 +131,12 @@
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})
:username "someuser"
:authtoken "abedjgbasdodj"})
(cut/generate-nginx-service {:unique-name "test.org", (cut/generate-nginx-service {:unique-name "test.org",
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
:username "someuser"
:authtoken "abedjgbasdodj"})))))
(deftest should-generate-website-build-cron (deftest should-generate-website-build-cron
(is (= {:apiVersion "batch/v1", (is (= {:apiVersion "batch/v1",
@ -204,9 +163,7 @@
:volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}} :volumes [{:name "content-volume", :persistentVolumeClaim {:claimName "test-io-content-volume"}}
{:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}], {:name "hashfile-volume", :persistentVolumeClaim {:claimName "test-io-hashfile-volume"}}],
:restartPolicy "OnFailure"}}}}}} :restartPolicy "OnFailure"}}}}}}
(cut/generate-website-build-cron {:authtoken "abedjgbasdodj", (cut/generate-website-build-cron {:gitea-host "gitlab.de",
:gitea-host "gitlab.de",
:username "someuser",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh", :sha256sum-output "123456789ab123cd345de script-file-name.sh",
@ -214,8 +171,6 @@
:branchname "main", :branchname "main",
:unique-name "test.io"})))) :unique-name "test.io"}))))
(deftest should-generate-website-build-secret (deftest should-generate-website-build-secret
(is (= {:apiVersion "v1", (is (= {:apiVersion "v1",
:kind "Secret", :kind "Secret",
@ -224,15 +179,16 @@
{:AUTHTOKEN "YWJlZGpnYmFzZG9kag==", {:AUTHTOKEN "YWJlZGpnYmFzZG9kag==",
:GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==", :GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==",
:GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}} :GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}}
(cut/generate-website-build-secret {:authtoken "abedjgbasdodj", (cut/generate-website-build-secret {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-host "gitlab.de",
:username "someuser",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:gitea-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh", :sha256sum-output "123456789ab123cd345de script-file-name.sh",
:issuer "staging", :issuer "staging",
:branchname "main", :branchname "main",
:unique-name "test.io"})))) :unique-name "test.io",
:gitea-host "gitlab.de"}
{:unique-name "test.io",
:authtoken "abedjgbasdodj",
:username "someuser"}))))
(deftest should-generate-website-content-volume (deftest should-generate-website-content-volume
(is (= {:name-c1 "test-io-content-volume", (is (= {:name-c1 "test-io-content-volume",
@ -245,16 +201,12 @@
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})
:username "someuser"
:authtoken "abedjgbasdodj"})
(cut/generate-website-content-volume {:unique-name "test.org", (cut/generate-website-content-volume {:unique-name "test.org",
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
:username "someuser"
:authtoken "abedjgbasdodj"})))))
(deftest should-generate-hashfile-volume (deftest should-generate-hashfile-volume
(is (= {:apiVersion "v1", (is (= {:apiVersion "v1",
@ -268,6 +220,4 @@
:gitea-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:gitea-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"] :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}))))
:username "someuser"
:authtoken "abedjgbasdodj"}))))

Loading…
Cancel
Save