introduce cljs resource loading
This commit is contained in:
parent
ff9ffd9c2e
commit
bf49370b74
8 changed files with 34 additions and 82 deletions
|
@ -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.10.3"]
|
:dependencies [[org.clojure/clojure "1.10.3"]
|
||||||
[org.clojure/tools.reader "1.3.4"]
|
[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/"
|
:target-path "target/%s/"
|
||||||
:source-paths ["src/main/cljc"
|
:source-paths ["src/main/cljc"
|
||||||
"src/main/clj"]
|
"src/main/clj"]
|
||||||
|
|
11
shadow-cljs.edn
Normal file
11
shadow-cljs.edn
Normal file
|
@ -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}}}
|
|
@ -1,6 +1,7 @@
|
||||||
(ns dda.c4k-jira.backup
|
(ns dda.c4k-jira.backup
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
#?(:cljs [shadow.resource :as rc])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.base64 :as b64]
|
[dda.c4k-common.base64 :as b64]
|
||||||
[dda.c4k-common.common :as cm]))
|
[dda.c4k-common.common :as cm]))
|
||||||
|
@ -10,6 +11,14 @@
|
||||||
(s/def ::restic-password cm/bash-env-string?)
|
(s/def ::restic-password cm/bash-env-string?)
|
||||||
(s/def ::restic-repository 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]
|
(defn generate-config [my-conf]
|
||||||
(let [{:keys [restic-repository]} my-conf]
|
(let [{:keys [restic-repository]} my-conf]
|
||||||
(->
|
(->
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
|
[dda.c4k-common.postgres :as postgres]
|
||||||
[dda.c4k-jira.jira :as jira]
|
[dda.c4k-jira.jira :as jira]
|
||||||
[dda.c4k-jira.postgres :as postgres]
|
|
||||||
[dda.c4k-jira.backup :as backup]))
|
[dda.c4k-jira.backup :as backup]))
|
||||||
|
|
||||||
(def config-defaults {:issuer :staging})
|
(def config-defaults {:issuer :staging})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns dda.c4k-jira.jira
|
(ns dda.c4k-jira.jira
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
#?(:cljs [shadow.resource :as rc])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.common :as cm]))
|
[dda.c4k-common.common :as cm]))
|
||||||
|
|
||||||
|
@ -8,6 +9,17 @@
|
||||||
(s/def ::issuer cm/letsencrypt-issuer?)
|
(s/def ::issuer cm/letsencrypt-issuer?)
|
||||||
(s/def ::jira-data-volume-path string?)
|
(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]
|
(defn generate-certificate [config]
|
||||||
(let [{:keys [fqdn issuer]} config
|
(let [{:keys [fqdn issuer]} config
|
||||||
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
|
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
|
||||||
|
|
|
@ -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")))
|
|
|
@ -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))
|
|
|
@ -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"}))))
|
|
Reference in a new issue