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
script:
- 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:
expire_in: 1h
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
* respective volume claims
## Status
Stable - we use this setup on production.
## Try out
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.
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
You need:

View file

@ -5,7 +5,7 @@
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.11.1"]
[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"]]
:target-path "target/%s/"
:source-paths ["src/main/cljc"

View file

@ -4,7 +4,7 @@
"src/test/cljc"
"src/test/cljs"
"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"]]
:builds {:frontend {:target :browser
:modules {:main {:init-fn dda.c4k-website.browser/init}}

View file

@ -2,34 +2,25 @@
(:require
[clojure.string :as st]
[clojure.tools.reader.edn :as edn]
[dda.c4k-common.monitoring :as mon]
[dda.c4k-website.core :as core]
[dda.c4k-website.website :as website]
[dda.c4k-common.browser :as br]
[dda.c4k-common.common :as cm]))
(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}]}])
[dda.c4k-common.common :as cm]
[dda.c4k-common.browser :as br]
))
(defn generate-content []
(cm/concat-vec
[(assoc
(br/generate-needs-validation) :content
(cm/concat-vec
(generate-group
(br/generate-group
"domain"
(cm/concat-vec
(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
"websites" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each website:"
"{:websites
@ -49,17 +40,19 @@
:build-memory-request \"512Mi\",
:build-memory-limit \"1024Mi\"}]}"
"16")))
(generate-group
(br/generate-group
"credentials"
(br/generate-text-area
"auth" "Your authentication data for each website or git repo:"
"{:auth
[{:unique-name \"test.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}
{:unique-name \"example.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}]}"
"{:mon-auth {:grafana-cloud-user \"your-user-id\"
:grafana-cloud-password \"your-cloud-password\"}
:auth
[{:unique-name \"test.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}
{:unique-name \"example.io\",
:username \"someuser\",
:authtoken \"abedjgbasdodj\"}]}"
"7"))
[(br/generate-br)]
(br/generate-button "generate-button" "Generate c4k yaml")))]
@ -73,15 +66,25 @@
(generate-content)})
(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
(br/get-content-from-element "websites" :deserializer edn/read-string)
(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! []
(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! "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/set-form-validated!))
@ -103,4 +106,7 @@
(br/set-output!)))))
(add-validate-listener "websites")
(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"))

View file

@ -1,13 +1,24 @@
(ns dda.c4k-website.core-test
(:require
#?(:cljs [shadow.resource :as rc])
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[clojure.spec.test.alpha :as st]
[dda.c4k-common.test-helper :as th]
[dda.c4k-common.base64 :as b64]
[clojure.spec.alpha :as s]
[dda.c4k-common.yaml :as yaml]
[dda.c4k-website.core :as cut]
[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
{:websites
[{: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"}]}