Compare commits

..

No commits in common. "7fc494c1df181d6279d8dab0abfcd7202fcb860a" and "8af984c0797cfc4bbd04a9fbc2ddd31f56a34e66" have entirely different histories.

3 changed files with 44 additions and 39 deletions

View file

@ -16,4 +16,5 @@ sequenceDiagram
j ->> j: generate.sh j ->> j: generate.sh
j ->> j: cp /target/html to website j ->> j: cp /target/html to website
deactivate j deactivate j
``` ```

View file

@ -21,8 +21,8 @@
(s/def ::volume-size pred/integer-string?) (s/def ::volume-size pred/integer-string?)
(s/def ::authtoken pred/bash-env-string?) (s/def ::authtoken pred/bash-env-string?)
(s/def ::fqdns (s/coll-of pred/fqdn-string?)) (s/def ::fqdns (s/coll-of pred/fqdn-string?))
(s/def ::forgejo-host pred/fqdn-string?) (s/def ::gitea-host pred/fqdn-string?)
(s/def ::forgejo-repo string?) (s/def ::gitea-repo string?)
(s/def ::branchname string?) (s/def ::branchname string?)
(s/def ::username string?) (s/def ::username string?)
(s/def ::build-cpu-request string?) (s/def ::build-cpu-request string?)
@ -32,11 +32,12 @@
(def websiteconfig? (s/keys :req-un [::unique-name (def websiteconfig? (s/keys :req-un [::unique-name
::fqdns ::fqdns
::forgejo-host ::gitea-host
::forgejo-repo ::gitea-repo
::branchname] ::branchname]
:opt-un [::issuer :opt-un [::issuer
::volume-size ::volume-size
::sha256sum-output
::build-cpu-request ::build-cpu-request
::build-cpu-limit ::build-cpu-limit
::build-memory-request ::build-memory-request
@ -191,8 +192,8 @@
(defn-spec generate-website-build-secret pred/map-or-seq? (defn-spec generate-website-build-secret pred/map-or-seq?
[config websiteconfig? [config websiteconfig?
auth websiteauth?] auth websiteauth?]
(let [{:keys [forgejo-host (let [{:keys [gitea-host
forgejo-repo gitea-repo
branchname]} config branchname]} config
{:keys [authtoken {:keys [authtoken
username]} auth] username]} auth]
@ -201,13 +202,13 @@
(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
forgejo-host gitea-host
forgejo-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
forgejo-host gitea-host
forgejo-repo gitea-repo
username)))))) username))))))

View file

@ -4,7 +4,9 @@
: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-website.website :as cut])) [dda.c4k-common.base64 :as b64]
[dda.c4k-website.website :as cut]
[clojure.spec.alpha :as s]))
(st/instrument `cut/generate-nginx-configmap) (st/instrument `cut/generate-nginx-configmap)
(st/instrument `cut/generate-nginx-deployment) (st/instrument `cut/generate-nginx-deployment)
@ -19,20 +21,20 @@
(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",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})))))
(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",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})))))
(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",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})))))
(is (= {:apiVersion "v1", (is (= {:apiVersion "v1",
@ -41,8 +43,8 @@
:labels {:app.kubernetes.part-of "test-io-website"}, :labels {:app.kubernetes.part-of "test-io-website"},
:namespace "default"}} :namespace "default"}}
(dissoc (cut/generate-nginx-configmap {:unique-name "test.io", (dissoc (cut/generate-nginx-configmap {:unique-name "test.io",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-repo "none", :gitea-repo "none",
:branchname "mablain", :branchname "mablain",
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :data)))) :fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :data))))
@ -86,9 +88,9 @@
{: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 {:forgejo-host "gitlab.de", (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-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",
@ -96,18 +98,18 @@
(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 {:forgejo-host "gitlab.de", (-> (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-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"})
: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 {:forgejo-host "gitlab.de", (-> (cut/generate-nginx-deployment {:gitea-host "gitlab.de",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-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",
@ -126,13 +128,13 @@
:app.kubernetes.part-of-c1 "test-io-website", :app.kubernetes.part-of-c1 "test-io-website",
:app.kubernetes.part-of-c2 "test-org-website"} :app.kubernetes.part-of-c2 "test-org-website"}
(th/map-diff (cut/generate-nginx-service {:unique-name "test.io", (th/map-diff (cut/generate-nginx-service {:unique-name "test.io",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})
(cut/generate-nginx-service {:unique-name "test.org", (cut/generate-nginx-service {:unique-name "test.org",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})))))
@ -161,9 +163,9 @@
: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 {:forgejo-host "gitlab.de", (cut/generate-website-build-cron {:gitea-host "gitlab.de",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-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",
@ -178,11 +180,12 @@
:GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==", :GITREPOURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vYXJjaGl2ZS9tYWluLnppcA==",
:GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}} :GITCOMMITURL "aHR0cHM6Ly9naXRsYWIuZGUvYXBpL3YxL3JlcG9zL3NvbWV1c2VyL3JlcG8vZ2l0L2NvbW1pdHMvSEVBRA=="}}
(cut/generate-website-build-secret {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], (cut/generate-website-build-secret {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-repo "repo", :gitea-repo "repo",
:sha256sum-output "123456789ab123cd345de script-file-name.sh",
:issuer "staging", :issuer "staging",
:branchname "main", :branchname "main",
:unique-name "test.io", :unique-name "test.io",
:forgejo-host "gitlab.de"} :gitea-host "gitlab.de"}
{:unique-name "test.io", {:unique-name "test.io",
:authtoken "abedjgbasdodj", :authtoken "abedjgbasdodj",
:username "someuser"})))) :username "someuser"}))))
@ -195,13 +198,13 @@
:app.kubernetes.part-of-c1 "test-io-website", :app.kubernetes.part-of-c1 "test-io-website",
:app.kubernetes.part-of-c2 "test-org-website"} :app.kubernetes.part-of-c2 "test-org-website"}
(th/map-diff (cut/generate-website-content-volume {:unique-name "test.io", (th/map-diff (cut/generate-website-content-volume {:unique-name "test.io",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})
(cut/generate-website-content-volume {:unique-name "test.org", (cut/generate-website-content-volume {:unique-name "test.org",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]})))))
@ -214,7 +217,7 @@
:labels {:app "test-io-nginx", :app.kubernetes.part-of "test-io-website"}}, :labels {:app "test-io-nginx", :app.kubernetes.part-of "test-io-website"}},
:spec {:storageClassName "local-path", :accessModes ["ReadWriteOnce"], :resources {:requests {:storage "16Mi"}}}} :spec {:storageClassName "local-path", :accessModes ["ReadWriteOnce"], :resources {:requests {:storage "16Mi"}}}}
(cut/generate-hashfile-volume {:unique-name "test.io", (cut/generate-hashfile-volume {:unique-name "test.io",
:forgejo-host "gitea.evilorg", :gitea-host "gitea.evilorg",
:forgejo-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"]}))))