check examples & add monitoring to browser

This commit is contained in:
jerger 2022-12-28 19:52:54 +01:00
parent 656cdeb92e
commit 58fa7cc5f9
10 changed files with 89 additions and 54 deletions

View file

@ -48,7 +48,7 @@ test-schema:
stage: build_and_test stage: build_and_test
script: script:
- lein uberjar - lein uberjar
- java -jar target/uberjar/c4k-website-standalone.jar valid-config.edn valid-auth.edn | kubeconform --kubernetes-version 1.23.0 --strict --skip Certificate - - java -jar target/uberjar/c4k-website-standalone.jar src/test/resources/website-test/valid-config.yaml src/test/resources/website-test/valid-auth.yaml | kubeconform --kubernetes-version 1.23.0 --strict --skip Certificate -
artifacts: artifacts:
expire_in: 1h expire_in: 1h
paths: paths:

View file

@ -20,6 +20,10 @@ Configs generated by c4k-website consists of the following parts:
* cron job for building and build secret for storing auth data * cron job for building and build secret for storing auth data
* respective volume claims * respective volume claims
## Status
Stable - we use this setup on production.
## Try out ## Try out
Click on the image to try out in your browser: Click on the image to try out in your browser:
@ -28,6 +32,13 @@ Click on the image to try out in your browser:
Your input will stay in your browser. No server interaction is required. Your input will stay in your browser. No server interaction is required.
You will also be able to try out on cli:
```
target/graalvm/c4k-website src/test/resources/website-test/valid-config.yaml src/test/resources/website-test/valid-auth.yaml | kubeval -
target/graalvm/c4k-website src/test/resources/website-test/valid-config.yaml src/test/resources/website-test/valid-auth.yaml | kubectl apply -f -
```
## Usage ## Usage
You need: You need:

View file

@ -5,7 +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.11.1"] :dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.reader "1.3.6"] [org.clojure/tools.reader "1.3.6"]
[org.domaindrivenarchitecture/c4k-common-clj "4.0.0"] [org.domaindrivenarchitecture/c4k-common-clj "5.0.1"]
[hickory "0.7.1"]] [hickory "0.7.1"]]
:target-path "target/%s/" :target-path "target/%s/"
:source-paths ["src/main/cljc" :source-paths ["src/main/cljc"

View file

@ -4,7 +4,7 @@
"src/test/cljc" "src/test/cljc"
"src/test/cljs" "src/test/cljs"
"src/test/resources"] "src/test/resources"]
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "4.0.0"] :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "5.0.1"]
[hickory "0.7.1"]] [hickory "0.7.1"]]
:builds {:frontend {:target :browser :builds {:frontend {:target :browser
:modules {:main {:init-fn dda.c4k-website.browser/init}} :modules {:main {:init-fn dda.c4k-website.browser/init}}

View file

@ -2,34 +2,25 @@
(:require (:require
[clojure.string :as st] [clojure.string :as st]
[clojure.tools.reader.edn :as edn] [clojure.tools.reader.edn :as edn]
[dda.c4k-common.monitoring :as mon]
[dda.c4k-website.core :as core] [dda.c4k-website.core :as core]
[dda.c4k-website.website :as website] [dda.c4k-website.website :as website]
[dda.c4k-common.browser :as br] [dda.c4k-common.common :as cm]
[dda.c4k-common.common :as cm])) [dda.c4k-common.browser :as br]
))
(defn generate-group
[name
content]
[{:type :element
:tag :div
:attrs {:class "rounded border border-3 m-3 p-2"}
:content [{:type :element
:tag :b
:attrs {:style "z-index: 1; position: relative; top: -1.3rem;"}
:content name}
{:type :element
:tag :fieldset
:content content}]}])
(defn generate-content [] (defn generate-content []
(cm/concat-vec (cm/concat-vec
[(assoc [(assoc
(br/generate-needs-validation) :content (br/generate-needs-validation) :content
(cm/concat-vec (cm/concat-vec
(generate-group (br/generate-group
"domain" "domain"
(cm/concat-vec (cm/concat-vec
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "") (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
(br/generate-input-field "mon-cluster-name" "(Optional) monitoring cluster name:" "website")
(br/generate-input-field "mon-cluster-stage" "(Optional) monitoring cluster stage:" "test")
(br/generate-input-field "mon-cloud-url" "(Optional) grafana cloud url:" "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push")
(br/generate-text-area (br/generate-text-area
"websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:" "websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
"{:websites "{:websites
@ -49,17 +40,19 @@
:build-memory-request \"512Mi\", :build-memory-request \"512Mi\",
:build-memory-limit \"1024Mi\"}]}" :build-memory-limit \"1024Mi\"}]}"
"16"))) "16")))
(generate-group (br/generate-group
"credentials" "credentials"
(br/generate-text-area (br/generate-text-area
"auth" "Your authentication data for each website or git repo:" "auth" "Your authentication data for each website or git repo:"
"{:auth "{:mon-auth {:grafana-cloud-user \"your-user-id\"
[{:unique-name \"test.io\", :grafana-cloud-password \"your-cloud-password\"}
:username \"someuser\", :auth
:authtoken \"abedjgbasdodj\"} [{:unique-name \"test.io\",
{:unique-name \"example.io\", :username \"someuser\",
:username \"someuser\", :authtoken \"abedjgbasdodj\"}
:authtoken \"abedjgbasdodj\"}]}" {:unique-name \"example.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}]}"
"7")) "7"))
[(br/generate-br)] [(br/generate-br)]
(br/generate-button "generate-button" "Generate c4k yaml")))] (br/generate-button "generate-button" "Generate c4k yaml")))]
@ -73,15 +66,25 @@
(generate-content)}) (generate-content)})
(defn config-from-document [] (defn config-from-document []
(let [issuer (br/get-content-from-element "issuer" :optional true)] (let [issuer (br/get-content-from-element "issuer" :optional true)
mon-cluster-name (br/get-content-from-element "mon-cluster-name" :optional true)
mon-cluster-stage (br/get-content-from-element "mon-cluster-stage" :optional true :deserializer keyword)
mon-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)]
(merge (merge
(br/get-content-from-element "websites" :deserializer edn/read-string) (br/get-content-from-element "websites" :deserializer edn/read-string)
(when (not (st/blank? issuer)) (when (not (st/blank? issuer))
{:issuer issuer})))) {:issuer issuer})
(when (some? mon-cluster-name)
{:mon-cfg {:cluster-name mon-cluster-name
:cluster-stage (keyword mon-cluster-stage)
:grafana-cloud-url mon-cloud-url}}))))
(defn validate-all! [] (defn validate-all! []
(br/validate! "websites" website/config? :deserializer edn/read-string) (br/validate! "websites" website/config? :deserializer edn/read-string)
(br/validate! "issuer" ::website/issuer :optional true) (br/validate! "issuer" ::website/issuer :optional true)
(br/validate! "mon-cluster-name" ::mon/cluster-name :optional true)
(br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true :deserializer keyword)
(br/validate! "mon-cloud-url" ::mon/grafana-cloud-url :optional true)
(br/validate! "auth" website/auth? :deserializer edn/read-string) (br/validate! "auth" website/auth? :deserializer edn/read-string)
(br/set-form-validated!)) (br/set-form-validated!))
@ -103,4 +106,7 @@
(br/set-output!))))) (br/set-output!)))))
(add-validate-listener "websites") (add-validate-listener "websites")
(add-validate-listener "issuer") (add-validate-listener "issuer")
(add-validate-listener "mon-cluster-name")
(add-validate-listener "mon-cluster-stage")
(add-validate-listener "mon-cloud-url")
(add-validate-listener "auth")) (add-validate-listener "auth"))

View file

@ -1,13 +1,24 @@
(ns dda.c4k-website.core-test (ns dda.c4k-website.core-test
(:require (:require
#?(:cljs [shadow.resource :as rc])
#?(: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] [clojure.spec.alpha :as s]
[dda.c4k-common.test-helper :as th] [dda.c4k-common.yaml :as yaml]
[dda.c4k-common.base64 :as b64]
[dda.c4k-website.core :as cut] [dda.c4k-website.core :as cut]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
#?(:cljs
(defmethod yaml/load-resource :website-test [resource-name]
(case resource-name
"website-test/valid-auth.yaml" (rc/inline "website-test/valid-auth.yaml")
"website-test/valid-config.yaml" (rc/inline "website-test/valid-config.yaml")
(throw (js/Error. "Undefined Resource!")))))
(deftest validate-valid-resources
(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"))))
(def websites (def websites
{:websites {:websites
[{:unique-name "example.io" [{:unique-name "example.io"

View file

@ -0,0 +1,10 @@
auth:
- unique-name: "test.io"
username: "someuser"
authtoken: "abedjgbasdodj"
- unique-name: "example.io"
username: "someuser"
authtoken: "abedjgbasdodj"
mon-auth:
grafana-cloud-user: "user"
grafana-cloud-password: "password"

View file

@ -0,0 +1,17 @@
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"

View file

@ -1,7 +0,0 @@
{:auth
[{:unique-name "test.io"
:username "someuser"
:authtoken "abedjgbasdodj"}
{:unique-name "example.io"
:username "someuser"
:authtoken "abedjgbasdodj"}]}

View file

@ -1,13 +0,0 @@
{: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"}]}