From 5ef80e77108cee11d9794c4f923d36a9a1a78a93 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 18 Oct 2022 13:09:13 +0200 Subject: [PATCH] Fix browser.cljs bug Add automation for testing browser code. --- copy-and-build-dda-io.sh | 22 ++++++++++++++++ src/main/cljc/dda/c4k_website/ingress.cljc | 13 ++++++++++ src/main/cljc/dda/c4k_website/website.cljc | 7 ++---- src/main/cljs/dda/c4k_website/browser.cljs | 25 ++++++++++--------- .../cljc/dda/c4k_website/ingress_test.cljc | 5 +--- 5 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 copy-and-build-dda-io.sh diff --git a/copy-and-build-dda-io.sh b/copy-and-build-dda-io.sh new file mode 100644 index 0000000..4ee2491 --- /dev/null +++ b/copy-and-build-dda-io.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# set things +set -o nounset +set -o xtrace +set -o errexit +set -eo pipefail + +# dirs +srcDir="/home/$USER/" +srcName="main.js" +targetDir="/home/$USER/" +targetName="c4k-website.js" + +echo "build" +shadow-cljs compile frontend + +echo "move and rename file" +cp $srcDir$srcName $targetDir$targetName + +echo "build" +(cd $targetDir; lein ring server) diff --git a/src/main/cljc/dda/c4k_website/ingress.cljc b/src/main/cljc/dda/c4k_website/ingress.cljc index 2790f11..1e039dc 100644 --- a/src/main/cljc/dda/c4k_website/ingress.cljc +++ b/src/main/cljc/dda/c4k_website/ingress.cljc @@ -24,6 +24,19 @@ (def certificate? (s/keys :req-un [::fqdns ::cert-name] :opt-un [::issuer])) +#?(:cljs + (defmethod yaml/load-resource :ingress [resource-name] + (case resource-name + "ingress/host-rule.yaml" (rc/inline "ingress/host-rule.yaml") + "ingress/certificate.yaml" (rc/inline "ingress/certificate.yaml") + "ingress/http-ingress.yaml" (rc/inline "ingress/http-ingress.yaml") + "ingress/https-ingress.yaml" (rc/inline "ingress/https-ingress.yaml") + (throw (js/Error. "Undefined Resource!"))))) + +#?(:cljs + (defmethod yaml/load-as-edn :ingress [resource-name] + (yaml/from-string (yaml/load-resource resource-name)))) + (defn-spec generate-host-rule pred/map-or-seq? [service-name ::service-name service-port ::service-port diff --git a/src/main/cljc/dda/c4k_website/website.cljc b/src/main/cljc/dda/c4k_website/website.cljc index 5cda6e9..7aa648d 100644 --- a/src/main/cljc/dda/c4k_website/website.cljc +++ b/src/main/cljc/dda/c4k_website/website.cljc @@ -20,7 +20,7 @@ (s/def ::unique-name string?) (s/def ::issuer pred/letsencrypt-issuer?) (s/def ::authtoken pred/bash-env-string?) -(s/def ::fqdns fqdn-list?) +(s/def ::fqdns (s/coll-of pred/fqdn-string?)) (s/def ::gitea-host pred/fqdn-string?) (s/def ::gitea-repo string?) (s/def ::branchname string?) @@ -79,10 +79,7 @@ #?(:cljs (defmethod yaml/load-resource :website [resource-name] - (case resource-name - "ingress/certificate.yaml" (rc/inline "ingress/certificate.yaml") - "ingress/http-ingress.yaml" (rc/inline "ingress/http-ingress.yaml") - "ingress/https-ingress.yaml" (rc/inline "ingress/https-ingress.yaml") + (case resource-name "website/nginx-configmap.yaml" (rc/inline "website/nginx-configmap.yaml") "website/nginx-deployment.yaml" (rc/inline "website/nginx-deployment.yaml") "website/nginx-service.yaml" (rc/inline "website/nginx-service.yaml") diff --git a/src/main/cljs/dda/c4k_website/browser.cljs b/src/main/cljs/dda/c4k_website/browser.cljs index b771271..4d0cfaf 100644 --- a/src/main/cljs/dda/c4k_website/browser.cljs +++ b/src/main/cljs/dda/c4k_website/browser.cljs @@ -3,7 +3,7 @@ [clojure.string :as st] [clojure.tools.reader.edn :as edn] [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])) @@ -31,17 +31,18 @@ (cm/concat-vec (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "") (br/generate-text-area - "websites" "A map containing fqdns and repo infos for each website:" - "[{:unique-name \"test.io \", - :fqdns [\"test.de \" \"www.test.de \"], - :gitea-host \"githost.de \", - :gitea-repo \"repo \", - :branchname \"main \"} + "websites" "A collection containing fqdns and repo infos for each website:" + "{:websites + [{:unique-name \"test.io\", + :fqdns [\"test.de\" \"www.test.de\"], + :gitea-host \"githost.de\", + :gitea-repo \"repo\", + :branchname \"main\"} {:unique-name \"example.io \", - :fqdns [\"example.org \" \"www.example.org \"], - :gitea-host \"githost.org \", - :gitea-repo \"repo \", - :branchname \"main \"}]" + :fqdns [\"example.org\" \"www.example.org\"], + :gitea-host \"githost.org\", + :gitea-repo \"repo\", + :branchname \"main\"}]}" "10"))) (generate-group "credentials" @@ -74,7 +75,7 @@ {:issuer issuer})))) (defn validate-all! [] - (br/validate! "websites" ::website/websites) + (br/validate! "websites" website/config? :deserializer edn/read-string) (br/validate! "issuer" ::website/issuer :optional true) (br/validate! "auth" website/auth? :deserializer edn/read-string) (br/set-form-validated!)) diff --git a/src/test/cljc/dda/c4k_website/ingress_test.cljc b/src/test/cljc/dda/c4k_website/ingress_test.cljc index 43c263c..5b2697e 100644 --- a/src/test/cljc/dda/c4k_website/ingress_test.cljc +++ b/src/test/cljc/dda/c4k_website/ingress_test.cljc @@ -3,10 +3,7 @@ #?(: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] - [dda.c4k-website.ingress :as cut] - [clojure.spec.alpha :as s])) + [dda.c4k-website.ingress :as cut])) (st/instrument `cut/generate-host-rule) (st/instrument `cut/generate-http-ingress)