From bf49370b7436e4fc145e1986b6f74b857ae9a31d Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 9 Jul 2021 17:17:41 +0200 Subject: [PATCH] introduce cljs resource loading --- project.clj | 2 +- shadow-cljs.edn | 11 ++++++ src/main/cljc/dda/c4k_jira/backup.cljc | 9 +++++ src/main/cljc/dda/c4k_jira/core.cljc | 2 +- src/main/cljc/dda/c4k_jira/jira.cljc | 12 +++++++ src/main/cljc/dda/c4k_jira/postgres.cljc | 35 ------------------- src/main/cljs/dda/c4k_jira/yaml.cljs | 19 ---------- src/test/cljc/dda/c4k_jira/postgres_test.cljc | 26 -------------- 8 files changed, 34 insertions(+), 82 deletions(-) create mode 100644 shadow-cljs.edn delete mode 100644 src/main/cljc/dda/c4k_jira/postgres.cljc delete mode 100644 src/main/cljs/dda/c4k_jira/yaml.cljs delete mode 100644 src/test/cljc/dda/c4k_jira/postgres_test.cljc diff --git a/project.clj b/project.clj index 875951e..3f60d16 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.10.3"] [org.clojure/tools.reader "1.3.4"] - [org.domaindrivenarchitecture/c4k-common-clj "0.1.0-SNAPSHOT"]] + [org.domaindrivenarchitecture/c4k-common-clj "0.2.0-SNAPSHOT"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/shadow-cljs.edn b/shadow-cljs.edn new file mode 100644 index 0000000..1c732dc --- /dev/null +++ b/shadow-cljs.edn @@ -0,0 +1,11 @@ +{:source-paths ["src/main/cljc" + "src/main/cljs" + "src/main/resources" + "src/test/cljc" + "src/test/cljs" + "src/test/resources"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "0.2.0-SNAPSHOT"]] + :builds {:test {:target :node-test + :output-to "target/node-tests.js" + :autorun true + :repl-pprint true}}} diff --git a/src/main/cljc/dda/c4k_jira/backup.cljc b/src/main/cljc/dda/c4k_jira/backup.cljc index ee09ef1..ffc7fa8 100644 --- a/src/main/cljc/dda/c4k_jira/backup.cljc +++ b/src/main/cljc/dda/c4k_jira/backup.cljc @@ -1,6 +1,7 @@ (ns dda.c4k-jira.backup (:require [clojure.spec.alpha :as s] + #?(:cljs [shadow.resource :as rc]) [dda.c4k-common.yaml :as yaml] [dda.c4k-common.base64 :as b64] [dda.c4k-common.common :as cm])) @@ -10,6 +11,14 @@ (s/def ::restic-password cm/bash-env-string?) (s/def ::restic-repository cm/bash-env-string?) +#?(:cljs + (defmethod yaml/load-resource :backup [resource-name] + (case resource-name + "backup/config.yaml" (rc/inline "backup/config.yaml") + "backup/cron.yaml" (rc/inline "backup/cron.yaml") + "backup/secret.yaml" (rc/inline "backup/secret.yaml") + (throw (js/Error. "Undefined Resource!"))))) + (defn generate-config [my-conf] (let [{:keys [restic-repository]} my-conf] (-> diff --git a/src/main/cljc/dda/c4k_jira/core.cljc b/src/main/cljc/dda/c4k_jira/core.cljc index 9e7a393..da818ed 100644 --- a/src/main/cljc/dda/c4k_jira/core.cljc +++ b/src/main/cljc/dda/c4k_jira/core.cljc @@ -5,8 +5,8 @@ #?(:clj [orchestra.core :refer [defn-spec]] :cljs [orchestra.core :refer-macros [defn-spec]]) [dda.c4k-common.yaml :as yaml] + [dda.c4k-common.postgres :as postgres] [dda.c4k-jira.jira :as jira] - [dda.c4k-jira.postgres :as postgres] [dda.c4k-jira.backup :as backup])) (def config-defaults {:issuer :staging}) diff --git a/src/main/cljc/dda/c4k_jira/jira.cljc b/src/main/cljc/dda/c4k_jira/jira.cljc index ea2bd2d..733321e 100644 --- a/src/main/cljc/dda/c4k_jira/jira.cljc +++ b/src/main/cljc/dda/c4k_jira/jira.cljc @@ -1,6 +1,7 @@ (ns dda.c4k-jira.jira (:require [clojure.spec.alpha :as s] + #?(:cljs [shadow.resource :as rc]) [dda.c4k-common.yaml :as yaml] [dda.c4k-common.common :as cm])) @@ -8,6 +9,17 @@ (s/def ::issuer cm/letsencrypt-issuer?) (s/def ::jira-data-volume-path string?) +#?(:cljs + (defmethod yaml/load-resource :jira [resource-name] + (case resource-name + "jira/certificate.yaml" (rc/inline "jira/certificate.yaml") + "jira/ingress.yaml" (rc/inline "jira/ingress.yaml") + "jira/persistent-volume.yaml" (rc/inline "jira/persistent-volume.yaml") + "jira/pod.yaml" (rc/inline "jira/pod.yaml") + "jira/pvc.yaml" (rc/inline "jira/pvc.yaml") + "jira/service.yaml" (rc/inline "jira/service.yaml") + (throw (js/Error. "Undefined Resource!"))))) + (defn generate-certificate [config] (let [{:keys [fqdn issuer]} config letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")] diff --git a/src/main/cljc/dda/c4k_jira/postgres.cljc b/src/main/cljc/dda/c4k_jira/postgres.cljc deleted file mode 100644 index b9230e7..0000000 --- a/src/main/cljc/dda/c4k_jira/postgres.cljc +++ /dev/null @@ -1,35 +0,0 @@ -(ns dda.c4k-jira.postgres - (:require - [clojure.spec.alpha :as s] - [dda.c4k-common.yaml :as yaml] - [dda.c4k-common.base64 :as b64] - [dda.c4k-common.common :as cm])) - -(s/def ::postgres-db-user cm/bash-env-string?) -(s/def ::postgres-db-password cm/bash-env-string?) -(s/def ::postgres-data-volume-path string?) - -(defn generate-config [] - (yaml/from-string (yaml/load-resource "postgres/config.yaml"))) - -(defn generate-deployment [] - (yaml/from-string (yaml/load-resource "postgres/deployment.yaml"))) - -(defn generate-persistent-volume [config] - (let [{:keys [postgres-data-volume-path]} config] - (-> - (yaml/from-string (yaml/load-resource "postgres/persistent-volume.yaml")) - (assoc-in [:spec :hostPath :path] postgres-data-volume-path)))) - -(defn generate-pvc [] - (yaml/from-string (yaml/load-resource "postgres/pvc.yaml"))) - -(defn generate-secret [my-auth] - (let [{:keys [postgres-db-user postgres-db-password]} my-auth] - (-> - (yaml/from-string (yaml/load-resource "postgres/secret.yaml")) - (cm/replace-key-value :postgres-user (b64/encode postgres-db-user)) - (cm/replace-key-value :postgres-password (b64/encode postgres-db-password))))) - -(defn generate-service [] - (yaml/from-string (yaml/load-resource "postgres/service.yaml"))) diff --git a/src/main/cljs/dda/c4k_jira/yaml.cljs b/src/main/cljs/dda/c4k_jira/yaml.cljs deleted file mode 100644 index 2d495f9..0000000 --- a/src/main/cljs/dda/c4k_jira/yaml.cljs +++ /dev/null @@ -1,19 +0,0 @@ -(ns dda.c4k-jira.yaml - (:require - ["js-yaml" :as yaml] - [shadow.resource :as rc])) - -(def postgres-config (rc/inline "postgres/config.yaml")) - -(def postgres-secret (rc/inline "postgres/secret.yaml")) - -(def postgres-deployment (rc/inline "postgres/deployment.yaml")) - -(def postgres-service (rc/inline "postgres/service.yaml")) - -(defn load-resource [resource-name] - (case resource-name - "postgres/config.yaml" postgres-config - "postgres/secret.yaml" postgres-secret - "postgres/deployment.yaml" postgres-deployment - "postgres/service.yaml" postgres-service)) \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_jira/postgres_test.cljc b/src/test/cljc/dda/c4k_jira/postgres_test.cljc deleted file mode 100644 index 58f639d..0000000 --- a/src/test/cljc/dda/c4k_jira/postgres_test.cljc +++ /dev/null @@ -1,26 +0,0 @@ -(ns dda.c4k-jira.postgres-test - (:require - #?(:clj [clojure.test :refer [deftest is are testing run-tests]] - :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) - [dda.c4k-jira.postgres :as cut])) - -(deftest should-generate-persistent-volume - (is (= {:kind "PersistentVolume" - :apiVersion "v1" - :metadata - {:name "postgres-pv-volume", :labels {:type "local"}} - :spec - {:storageClassName "manual" - :accessModes ["ReadWriteOnce"] - :capacity {:storage "10Gi"} - :hostPath {:path "xx"}}} - (cut/generate-persistent-volume {:postgres-data-volume-path "xx"})))) - -(deftest should-generate-secret - (is (= {:apiVersion "v1" - :kind "Secret" - :metadata {:name "postgres-secret"} - :type "Opaque" - :data - {:postgres-user "eHgtdXM=", :postgres-password "eHgtcHc="}} - (cut/generate-secret {:postgres-db-user "xx-us" :postgres-db-password "xx-pw"}))))