moved repo-user from auth to config

This commit is contained in:
Clemens 2024-03-07 09:16:50 +01:00
parent 248c33613a
commit e923c9d5c3
7 changed files with 55 additions and 35 deletions

View file

@ -19,17 +19,20 @@
(s/def ::authtoken ::web/authtoken) (s/def ::authtoken ::web/authtoken)
(s/def ::fqdns ::web/fqdns) (s/def ::fqdns ::web/fqdns)
(s/def ::forgejo-host ::web/forgejo-host) (s/def ::forgejo-host ::web/forgejo-host)
(s/def ::repo-user ::web/repo-user)
(s/def ::forgejo-repo ::web/forgejo-repo) (s/def ::forgejo-repo ::web/forgejo-repo)
(s/def ::branchname ::web/branchname) (s/def ::branchname ::web/branchname)
(s/def ::username ::web/username)
(s/def ::build-cpu-request ::web/build-cpu-request) (s/def ::build-cpu-request ::web/build-cpu-request)
(s/def ::build-memory-request ::web/build-memory-request) (s/def ::build-memory-request ::web/build-memory-request)
(s/def ::build-cpu-limit ::web/build-cpu-limit) (s/def ::build-cpu-limit ::web/build-cpu-limit)
(s/def ::build-memory-limit ::web/build-memory-limit) (s/def ::build-memory-limit ::web/build-memory-limit)
(s/def ::redirect ::web/redirect)
(s/def ::redirects ::web/redirects)
(def websiteconfig? (s/keys :req-un [::unique-name (def websiteconfig? (s/keys :req-un [::unique-name
::fqdns ::fqdns
::forgejo-host ::forgejo-host
::repo-user
::forgejo-repo ::forgejo-repo
::branchname] ::branchname]
:opt-un [::issuer :opt-un [::issuer
@ -37,8 +40,9 @@
::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])) ::redirects]))
(def websiteauth? (s/keys :req-un [::unique-name ::authtoken]))
(s/def ::websiteconfigs (s/coll-of websiteconfig?)) (s/def ::websiteconfigs (s/coll-of websiteconfig?))
(s/def ::websiteauths (s/coll-of websiteauth?)) (s/def ::websiteauths (s/coll-of websiteauth?))

View file

@ -22,7 +22,7 @@
(s/def ::forgejo-host pred/fqdn-string?) (s/def ::forgejo-host pred/fqdn-string?)
(s/def ::forgejo-repo string?) (s/def ::forgejo-repo string?)
(s/def ::branchname string?) (s/def ::branchname string?)
(s/def ::username string?) (s/def ::repo-user string?)
(s/def ::build-cpu-request string?) (s/def ::build-cpu-request string?)
(s/def ::build-memory-request string?) (s/def ::build-memory-request string?)
(s/def ::build-cpu-limit string?) (s/def ::build-cpu-limit string?)
@ -30,10 +30,11 @@
(s/def ::redirect (s/tuple string? string?)) (s/def ::redirect (s/tuple string? string?))
(s/def ::redirects (s/coll-of ::redirect)) (s/def ::redirects (s/coll-of ::redirect))
; TODO: is this websiteconfig? & websiteauth? used or the ones in core?
(def websiteconfig? (s/keys :req-un [::unique-name (def websiteconfig? (s/keys :req-un [::unique-name
::fqdns ::fqdns
::forgejo-host ::forgejo-host
::repo-user
::forgejo-repo ::forgejo-repo
::branchname ::branchname
::issuer ::issuer
@ -44,7 +45,7 @@
::build-memory-limit ::build-memory-limit
::redirects])) ::redirects]))
(def websiteauth? (s/keys :req-un [::unique-name ::username ::authtoken])) (def websiteauth? (s/keys :req-un [::unique-name ::authtoken]))
(s/def ::websiteconfigs (s/coll-of websiteconfig?)) (s/def ::websiteconfigs (s/coll-of websiteconfig?))
@ -112,18 +113,15 @@
#"REDIRECTS" #"REDIRECTS"
(generate-redirects config 2))))))) (generate-redirects config 2)))))))
; TODO generate git path without username
; TODO add test ; TODO add test
(defn-spec generate-build-configmap pred/map-or-seq? (defn-spec generate-build-configmap pred/map-or-seq?
[config websiteconfig?] [config websiteconfig?]
(let [{:keys [unique-name (let [{:keys [unique-name
forgejo-host forgejo-host
repo-user
forgejo-repo forgejo-repo
branchname]} config branchname]} config
name (replace-dots-by-minus unique-name) name (replace-dots-by-minus unique-name)]
username "TODO"]
(-> (->
(yaml/load-as-edn "website/build-configmap.yaml") (yaml/load-as-edn "website/build-configmap.yaml")
(replace-all-matching-prefixes "NAME" name) (replace-all-matching-prefixes "NAME" name)
@ -131,20 +129,20 @@
(generate-gitrepourl (generate-gitrepourl
forgejo-host forgejo-host
forgejo-repo forgejo-repo
username repo-user
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 forgejo-host
forgejo-repo forgejo-repo
username)))))) repo-user))))))
; TODO: remove config
(defn-spec generate-build-secret pred/map-or-seq? (defn-spec generate-build-secret pred/map-or-seq?
[config websiteconfig? [config websiteconfig?
auth websiteauth?] auth websiteauth?]
(let [{:keys [unique-name]} config (let [{:keys [unique-name]} config
{:keys [authtoken {:keys [unique-name
username]} auth authtoken]} auth
name (replace-dots-by-minus unique-name)] name (replace-dots-by-minus unique-name)]
(-> (->
(yaml/load-as-edn "website/build-secret.yaml") (yaml/load-as-edn "website/build-secret.yaml")

View file

@ -28,14 +28,16 @@
"{ :websiteconfigs "{ :websiteconfigs
[{:unique-name \"test.io\", [{:unique-name \"test.io\",
:fqdns [\"test.de\" \"www.test.de\"], :fqdns [\"test.de\" \"www.test.de\"],
:gitea-host \"githost.de\", :forgejo-host \"githost.de\",
:gitea-repo \"repo\", :repo-user \"someuser\",
:forgejo-repo \"repo\",
:branchname \"main\", :branchname \"main\",
:sha256sum-output \"123456789ab123cd345de script-file-name.sh\"} :sha256sum-output \"123456789ab123cd345de script-file-name.sh\"}
{:unique-name \"example.io \", {:unique-name \"example.io \",
:fqdns [\"example.org\" \"www.example.org\"], :fqdns [\"example.org\" \"www.example.org\"],
:gitea-host \"githost.org\", :forgejo-host \"githost.org\",
:gitea-repo \"repo\", :repo-user \"someuser\",
:forgejo-repo \"repo\",
:branchname \"main\", :branchname \"main\",
:build-cpu-request \"1500m\", :build-cpu-request \"1500m\",
:build-cpu-limit \"3000m\", :build-cpu-limit \"3000m\",
@ -51,10 +53,8 @@
:grafana-cloud-password \"your-cloud-password\"} :grafana-cloud-password \"your-cloud-password\"}
:websiteauths :websiteauths
[{:unique-name \"test.io\", [{:unique-name \"test.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"} :authtoken \"abedjgbasdodj\"}
{:unique-name \"example.io\", {:unique-name \"example.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}]}" :authtoken \"abedjgbasdodj\"}]}"
"7")) "7"))
[(br/generate-br)] [(br/generate-br)]

View file

@ -30,11 +30,13 @@
[{:unique-name "example.io" [{:unique-name "example.io"
:fqdns ["example.org", "www.example.com"] :fqdns ["example.org", "www.example.com"]
:forgejo-host "finegitehost.net" :forgejo-host "finegitehost.net"
:repo-user "someuser"
:forgejo-repo "repo" :forgejo-repo "repo"
:branchname "main"} :branchname "main"}
{:unique-name "test.io" {:unique-name "test.io"
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"] :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:forgejo-host "gitlab.de" :forgejo-host "gitlab.de"
:repo-user "someuser"
:forgejo-repo "repo" :forgejo-repo "repo"
:branchname "main"}]}) :branchname "main"}]})
@ -43,42 +45,40 @@
[{:unique-name "test.io" [{:unique-name "test.io"
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"] :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
:forgejo-host "gitlab.de" :forgejo-host "gitlab.de"
:repo-user "someuser"
:forgejo-repo "repo" :forgejo-repo "repo"
:branchname "main"} :branchname "main"}
{:unique-name "example.io" {:unique-name "example.io"
:fqdns ["example.org", "www.example.com"] :fqdns ["example.org", "www.example.com"]
:forgejo-host "finegitehost.net" :forgejo-host "finegitehost.net"
:repo-user "someuser"
:forgejo-repo "repo" :forgejo-repo "repo"
:branchname "main"}]}) :branchname "main"}]})
(def auth1 (def auth1
{:websiteauths {:websiteauths
[{:unique-name "example.io" [{:unique-name "example.io"
:username "someuser"
:authtoken "abedjgbasdodj"} :authtoken "abedjgbasdodj"}
{:unique-name "test.io" {:unique-name "test.io"
:username "someuser"
:authtoken "abedjgbasdodj"}]}) :authtoken "abedjgbasdodj"}]})
(def auth2 (def auth2
{:websiteauths {:websiteauths
[{:unique-name "test.io" [{:unique-name "test.io"
:username "someuser"
:authtoken "abedjgbasdodj"} :authtoken "abedjgbasdodj"}
{:unique-name "example.io" {:unique-name "example.io"
:username "someuser"
:authtoken "abedjgbasdodj"}]}) :authtoken "abedjgbasdodj"}]})
(def flattened-and-reduced-config (def flattened-and-reduced-config
{:unique-name "example.io", {:unique-name "example.io",
:fqdns ["example.org" "www.example.com"], :fqdns ["example.org" "www.example.com"],
:forgejo-host "finegitehost.net", :forgejo-host "finegitehost.net",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-repo "repo",
:branchname "main"}) :branchname "main"})
(def flattened-and-reduced-auth (def flattened-and-reduced-auth
{:unique-name "example.io", {:unique-name "example.io",
:username "someuser",
:authtoken "abedjgbasdodj"}) :authtoken "abedjgbasdodj"})
(deftest sorts-config (deftest sorts-config
@ -87,11 +87,13 @@
[{:unique-name "example.io", [{:unique-name "example.io",
:fqdns ["example.org" "www.example.com"], :fqdns ["example.org" "www.example.com"],
:forgejo-host "finegitehost.net", :forgejo-host "finegitehost.net",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-repo "repo",
:branchname "main"}, :branchname "main"},
{:unique-name "test.io", {:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de", :forgejo-host "gitlab.de",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-repo "repo",
:branchname "main", :branchname "main",
:sha256sum-output "123456789ab123cd345de script-file-name.sh"}], :sha256sum-output "123456789ab123cd345de script-file-name.sh"}],
@ -102,12 +104,14 @@
[{:unique-name "test.io", [{:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de", :forgejo-host "gitlab.de",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-repo "repo",
:branchname "main", :branchname "main",
:sha256sum-output "123456789ab123cd345de script-file-name.sh"} :sha256sum-output "123456789ab123cd345de script-file-name.sh"}
{:unique-name "example.io", {:unique-name "example.io",
:fqdns ["example.org" "www.example.com"], :fqdns ["example.org" "www.example.com"],
:forgejo-host "finegitehost.net", :forgejo-host "finegitehost.net",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-repo "repo",
:branchname "main"}], :branchname "main"}],
:mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}})))) :mon-cfg {:grafana-cloud-url "url-for-your-prom-remote-write-endpoint", :cluster-name "jitsi", :cluster-stage "test"}}))))
@ -158,13 +162,14 @@
:path "/", :path "/",
:backend {:service {:name "test-io", :port {:number 80}}}}]}}] :backend {:service {:name "test-io", :port {:number 80}}}}]}}]
(get-in (get-in
(cut/generate-ingress {:forgejo-host "gitlab.de", (cut/generate-ingress {:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-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"
:build-cpu-request "500m" :build-cpu-request "500m"
:build-cpu-limit "1700m" :build-cpu-limit "1700m"
:build-memory-request "256Mi" :build-memory-request "256Mi"
@ -174,13 +179,14 @@
[2 :spec :rules]))) [2 :spec :rules])))
(is (= "test-io" (is (= "test-io"
(get-in (get-in
(cut/generate-ingress {:forgejo-host "gitlab.de", (cut/generate-ingress {:unique-name "test.io",
:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"], :fqdns ["test.de" "test.org" "www.test.de" "www.test.org"],
:forgejo-host "gitlab.de",
:repo-user "someuser",
:forgejo-repo "repo", :forgejo-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"
:build-cpu-request "500m" :build-cpu-request "500m"
:build-cpu-limit "1700m" :build-cpu-limit "1700m"
:build-memory-request "256Mi" :build-memory-request "256Mi"

View file

@ -31,6 +31,7 @@
:redirects [["/products.html", "/offer.html"] :redirects [["/products.html", "/offer.html"]
["/one-more", "/redirect"]] ["/one-more", "/redirect"]]
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]}
@ -45,6 +46,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [] :redirects []
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]}
@ -54,6 +56,7 @@
(deftest should-generate-resource-requests (deftest should-generate-resource-requests
(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 {:forgejo-host "gitlab.de",
:repo-user "someuser",
: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", :forgejo-repo "repo",
:issuer "staging", :issuer "staging",
@ -68,6 +71,7 @@
:spec :template :spec :initContainers first :resources))) :spec :template :spec :initContainers first :resources)))
(is (= "test-io" (is (= "test-io"
(-> (cut/generate-nginx-deployment {:forgejo-host "gitlab.de", (-> (cut/generate-nginx-deployment {:forgejo-host "gitlab.de",
:repo-user "someuser",
: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", :forgejo-repo "repo",
:issuer "staging", :issuer "staging",
@ -92,6 +96,7 @@
:redirects [["/products.html", "/offer.html"] :redirects [["/products.html", "/offer.html"]
["/one-more", "/redirect"]] ["/one-more", "/redirect"]]
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]})))
@ -107,6 +112,7 @@
:redirects [["/products.html", "/offer.html"] :redirects [["/products.html", "/offer.html"]
["/one-more", "/redirect"]] ["/one-more", "/redirect"]]
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]})))
@ -121,6 +127,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]})))
@ -139,6 +146,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]})
@ -162,6 +170,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]}))))
@ -204,6 +213,7 @@
:build-memory-limit "512Mi" :build-memory-limit "512Mi"
:volume-size "3" :volume-size "3"
:forgejo-host "gitlab.de", :forgejo-host "gitlab.de",
:repo-user "someuser",
: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", :forgejo-repo "repo",
:branchname "main", :branchname "main",
@ -225,14 +235,14 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitlab.de" :forgejo-host "gitlab.de"
:repo-user "someuser",
:build-cpu-request "500m" :build-cpu-request "500m"
:build-cpu-limit "1700m" :build-cpu-limit "1700m"
:build-memory-request "256Mi" :build-memory-request "256Mi"
:build-memory-limit "512Mi" :build-memory-limit "512Mi"
:volume-size "3"} :volume-size "3"}
{:unique-name "test.io", {:unique-name "test.io",
:authtoken "abedjgbasdodj", :authtoken "abedjgbasdodj"}))))
:username "someuser"}))))
(deftest should-generate-content-pvc (deftest should-generate-content-pvc
(is (= {:apiVersion "v1", (is (= {:apiVersion "v1",
@ -254,6 +264,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]}))))
@ -278,6 +289,7 @@
:unique-name "test.io", :unique-name "test.io",
:redirects [], :redirects [],
:forgejo-host "gitea.evilorg", :forgejo-host "gitea.evilorg",
:repo-user "someuser",
:forgejo-repo "none", :forgejo-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"]}))))

View file

@ -1,9 +1,7 @@
websiteauths: websiteauths:
- unique-name: "test.io" - unique-name: "test.io"
username: "someuser"
authtoken: "abedjgbasdodj" authtoken: "abedjgbasdodj"
- unique-name: "example.io" - unique-name: "example.io"
username: "someuser"
authtoken: "abedjgbasdodj" authtoken: "abedjgbasdodj"
mon-auth: mon-auth:
grafana-cloud-user: "user" grafana-cloud-user: "user"

View file

@ -3,6 +3,7 @@ websiteconfigs:
- unique-name: "test.io" - unique-name: "test.io"
fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"] fqdns: ["test.de", "test.org", "www.test.de", "www.test.org"]
forgejo-host: "codeberg.org" forgejo-host: "codeberg.org"
repo-user: "someuser"
forgejo-repo: "repo" forgejo-repo: "repo"
branchname: "main" branchname: "main"
redirects: redirects:
@ -11,6 +12,7 @@ websiteconfigs:
- unique-name: "example.io" - unique-name: "example.io"
fqdns: ["example.org", "www.example.com"] fqdns: ["example.org", "www.example.com"]
forgejo-host: "fineForgejoHost.net" forgejo-host: "fineForgejoHost.net"
repo-user: "someotheruser"
forgejo-repo: "repo" forgejo-repo: "repo"
branchname: "main" branchname: "main"
mon-cfg: mon-cfg: