refactoring matomo -> shynet

This commit is contained in:
see 2022-01-27 15:57:11 +01:00
parent 3b6570e6fb
commit f601c479c1
16 changed files with 63 additions and 63 deletions

View file

@ -1,4 +1,4 @@
# c4k-matomo # c4k-shynet
@ -15,14 +15,14 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
``` ```
cd existing_repo cd existing_repo
git remote add origin https://gitlab.com/domaindrivenarchitecture/c4k-matomo.git git remote add origin https://gitlab.com/domaindrivenarchitecture/c4k-shynet.git
git branch -M main git branch -M main
git push -uf origin main git push -uf origin main
``` ```
## Integrate with your tools ## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/-/experiment/new_project_readme_content:e2a9c69713642ba95e355c012bccb082?https://gitlab.com/domaindrivenarchitecture/c4k-matomo/-/settings/integrations) - [ ] [Set up project integrations](https://gitlab.com/-/experiment/new_project_readme_content:e2a9c69713642ba95e355c012bccb082?https://gitlab.com/domaindrivenarchitecture/c4k-shynet/-/settings/integrations)
## Collaborate with your team ## Collaborate with your team

View file

@ -1,18 +1,18 @@
{ {
"name": "c4k-matomo", "name": "c4k-shynet",
"description": "Generate c4k yaml for a matomo deployment.", "description": "Generate c4k yaml for a shynet deployment.",
"author": "meissa GmbH", "author": "meissa GmbH",
"version": "1.0.4-SNAPSHOT", "version": "1.0.4-SNAPSHOT",
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-matomo#readme", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-shynet#readme",
"repository": "https://www.npmjs.com/package/c4k-matomo", "repository": "https://www.npmjs.com/package/c4k-shynet",
"license": "APACHE2", "license": "APACHE2",
"main": "c4k-matomo.js", "main": "c4k-shynet.js",
"bin": { "bin": {
"c4k-matomo": "./c4k-matomo.js" "c4k-shynet": "./c4k-shynet.js"
}, },
"keywords": [ "keywords": [
"cljs", "cljs",
"matomo", "shynet",
"k8s", "k8s",
"c4k", "c4k",
"deployment", "deployment",
@ -20,7 +20,7 @@
"convention4kubernetes" "convention4kubernetes"
], ],
"bugs": { "bugs": {
"url": "https://gitlab.com/domaindrivenarchitecture/c4k-matomo/issues" "url": "https://gitlab.com/domaindrivenarchitecture/c4k-shynet/issues"
}, },
"dependencies": { "dependencies": {
"js-base64": "^3.6.1", "js-base64": "^3.6.1",

View file

@ -1,5 +1,5 @@
(defproject org.domaindrivenarchitecture/c4k-matomo "1.0.0-SNAPSHOT" (defproject org.domaindrivenarchitecture/c4k-shynet "1.0.0-SNAPSHOT"
:description "matomo c4k-installation package" :description "shynet c4k-installation package"
:url "https://domaindrivenarchitecture.org" :url "https://domaindrivenarchitecture.org"
:license {:name "Apache License, Version 2.0" :license {:name "Apache License, Version 2.0"
:url "https://www.apache.org/licenses/LICENSE-2.0.html"} :url "https://www.apache.org/licenses/LICENSE-2.0.html"}
@ -20,8 +20,8 @@
:dependencies [[dda/data-test "0.1.1"]]} :dependencies [[dda/data-test "0.1.1"]]}
:dev {:plugins [[lein-shell "0.5.0"]]} :dev {:plugins [[lein-shell "0.5.0"]]}
:uberjar {:aot :all :uberjar {:aot :all
:main dda.c4k-matomo.uberjar :main dda.c4k-shynet.uberjar
:uberjar-name "c4k-matomo-standalone.jar" :uberjar-name "c4k-shynet-standalone.jar"
:dependencies [[org.clojure/tools.cli "1.0.206"] :dependencies [[org.clojure/tools.cli "1.0.206"]
[ch.qos.logback/logback-classic "1.3.0-alpha4" [ch.qos.logback/logback-classic "1.3.0-alpha4"
:exclusions [com.sun.mail/javax.mail]] :exclusions [com.sun.mail/javax.mail]]
@ -36,7 +36,7 @@
"native-image" "native-image"
"--report-unsupported-elements-at-runtime" "--report-unsupported-elements-at-runtime"
"--initialize-at-build-time" "--initialize-at-build-time"
"-jar" "target/uberjar/c4k-matomo-standalone.jar" "-jar" "target/uberjar/c4k-shynet-standalone.jar"
"-H:ResourceConfigurationFiles=graalvm-resource-config.json" "-H:ResourceConfigurationFiles=graalvm-resource-config.json"
"-H:Log=registerResource" "-H:Log=registerResource"
"-H:Name=target/graalvm/${:name}"]}) "-H:Name=target/graalvm/${:name}"]})

View file

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>c4k-matomo</title> <title>c4k-shynet</title>
<link href="https://domaindrivenarchitecture.org/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="https://domaindrivenarchitecture.org/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://domaindrivenarchitecture.org/css/fonts/fontawesome/fontawesome.css" rel="stylesheet" <link href="https://domaindrivenarchitecture.org/css/fonts/fontawesome/fontawesome.css" rel="stylesheet"
type="text/css" /> type="text/css" />

View file

@ -7,7 +7,7 @@
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "0.4.3"] :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "0.4.3"]
[hickory "0.7.1"]] [hickory "0.7.1"]]
:builds {:frontend {:target :browser :builds {:frontend {:target :browser
:modules {:main {:init-fn dda.c4k-matomo.browser/init}} :modules {:main {:init-fn dda.c4k-shynet.browser/init}}
:release {} :release {}
:compiler-options {:optimizations :advanced}} :compiler-options {:optimizations :advanced}}
:test {:target :node-test :test {:target :node-test

View file

@ -1,16 +1,16 @@
(ns dda.c4k-matomo.uberjar (ns dda.c4k-shynet.uberjar
(:gen-class) (:gen-class)
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string :as cs] [clojure.string :as cs]
[clojure.tools.reader.edn :as edn] [clojure.tools.reader.edn :as edn]
[expound.alpha :as expound] [expound.alpha :as expound]
[dda.c4k-matomo.core :as core])) [dda.c4k-shynet.core :as core]))
(def usage (def usage
"usage: "usage:
c4k-matomo {your configuraton file} {your authorization file}") c4k-shynet {your configuraton file} {your authorization file}")
(s/def ::options (s/* #{"-h"})) (s/def ::options (s/* #{"-h"}))
(s/def ::filename (s/and string? (s/def ::filename (s/and string?

View file

@ -1,4 +1,4 @@
(ns dda.c4k-matomo.core (ns dda.c4k-shynet.core
(:require (:require
[clojure.string :as cs] [clojure.string :as cs]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
@ -6,12 +6,12 @@
: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-common.postgres :as postgres]
[dda.c4k-matomo.matomo :as matomo])) [dda.c4k-shynet.shynet :as shynet]))
(def config-defaults {:issuer :staging}) (def config-defaults {:issuer :staging})
(def config? (s/keys :req-un [::matomo/fqdn] (def config? (s/keys :req-un [::shynet/fqdn]
:opt-un [::matomo/issuer ::postgres/postgres-data-volume-path])) :opt-un [::shynet/issuer ::postgres/postgres-data-volume-path]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password])) ;TODO add auth (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password])) ;TODO add auth
@ -26,13 +26,13 @@
[(yaml/to-string (postgres/generate-pvc)) [(yaml/to-string (postgres/generate-pvc))
(yaml/to-string (postgres/generate-deployment :postgres-image "postgres:14")) (yaml/to-string (postgres/generate-deployment :postgres-image "postgres:14"))
(yaml/to-string (postgres/generate-service))] (yaml/to-string (postgres/generate-service))]
[(yaml/to-string (matomo/generate-webserver-deployment)) [(yaml/to-string (shynet/generate-webserver-deployment))
(yaml/to-string (matomo/generate-celeryworker-deployment)) (yaml/to-string (shynet/generate-celeryworker-deployment))
(yaml/to-string (matomo/generate-ingress config)) (yaml/to-string (shynet/generate-ingress config))
(yaml/to-string (matomo/generate-certificate config)) (yaml/to-string (shynet/generate-certificate config))
(yaml/to-string (matomo/generate-service-redis)) (yaml/to-string (shynet/generate-service-redis))
(yaml/to-string (matomo/generate-service-webserver)) (yaml/to-string (shynet/generate-service-webserver))
(yaml/to-string (matomo/generate-statefulset))]))) (yaml/to-string (shynet/generate-statefulset))])))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config config?

View file

@ -1,4 +1,4 @@
(ns dda.c4k-matomo.matomo (ns dda.c4k-shynet.shynet
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc]) #?(:cljs [shadow.resource :as rc])
@ -10,34 +10,34 @@
(s/def ::issuer pred/letsencrypt-issuer?) (s/def ::issuer pred/letsencrypt-issuer?)
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :matomo [resource-name] (defmethod yaml/load-resource :shynet [resource-name]
(case resource-name (case resource-name
"matomo/certificate.yaml" (rc/inline "matomo/certificate.yaml") "shynet/certificate.yaml" (rc/inline "shynet/certificate.yaml")
"matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml") "shynet/deployments.yaml" (rc/inline "shynet/deployments.yaml")
"matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml") "shynet/ingress.yaml" (rc/inline "shynet/ingress.yaml")
"matomo/service-redis.yaml" (rc/inline "matomo/service-redis.yaml") "shynet/service-redis.yaml" (rc/inline "shynet/service-redis.yaml")
"matomo/service-webserver.yaml" (rc/inline "matomo/service-webserver.yaml") "shynet/service-webserver.yaml" (rc/inline "shynet/service-webserver.yaml")
"matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml") "shynet/statefulset.yaml" (rc/inline "shynet/statefulset.yaml")
(throw (js/Error. "Undefined Resource!"))))) (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")]
(-> (->
(yaml/from-string (yaml/load-resource "matomo/certificate.yaml")) (yaml/from-string (yaml/load-resource "shynet/certificate.yaml"))
(assoc-in [:spec :commonName] fqdn) (assoc-in [:spec :commonName] fqdn)
(assoc-in [:spec :dnsNames] [fqdn]) (assoc-in [:spec :dnsNames] [fqdn])
(assoc-in [:spec :issuerRef :name] letsencrypt-issuer)))) (assoc-in [:spec :issuerRef :name] letsencrypt-issuer))))
(defn generate-webserver-deployment [] (defn generate-webserver-deployment []
(let [shynet-application "shynet-webserver"] (let [shynet-application "shynet-webserver"]
(-> (yaml/from-string (yaml/load-resource "matomo/deployments.yaml")) (-> (yaml/from-string (yaml/load-resource "shynet/deployments.yaml"))
(cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application) (cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application)
(update-in [:spec :template :spec :containers 0] dissoc :command)))) (update-in [:spec :template :spec :containers 0] dissoc :command))))
(defn generate-celeryworker-deployment [] (defn generate-celeryworker-deployment []
(let [shynet-application "shynet-celeryworker"] (let [shynet-application "shynet-celeryworker"]
(-> (yaml/from-string (yaml/load-resource "matomo/deployments.yaml")) (-> (yaml/from-string (yaml/load-resource "shynet/deployments.yaml"))
(cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application)))) (cm/replace-all-matching-values-by-new-value "shynet-application" shynet-application))))
(defn generate-ingress [config] (defn generate-ingress [config]
@ -45,15 +45,15 @@
:or {issuer :staging}} config :or {issuer :staging}} config
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")] letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
(-> (->
(yaml/from-string (yaml/load-resource "matomo/ingress.yaml")) (yaml/from-string (yaml/load-resource "shynet/ingress.yaml"))
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-statefulset [] (defn generate-statefulset []
(yaml/from-string (yaml/load-resource "matomo/statefulset.yaml"))) (yaml/from-string (yaml/load-resource "shynet/statefulset.yaml")))
(defn generate-service-redis [] (defn generate-service-redis []
(yaml/from-string (yaml/load-resource "matomo/service-redis.yaml"))) (yaml/from-string (yaml/load-resource "shynet/service-redis.yaml")))
(defn generate-service-webserver [] (defn generate-service-webserver []
(yaml/from-string (yaml/load-resource "matomo/service-webserver.yaml"))) (yaml/from-string (yaml/load-resource "shynet/service-webserver.yaml")))

View file

@ -1,22 +1,22 @@
(ns dda.c4k-matomo.browser (ns dda.c4k-shynet.browser
(:require (:require
[clojure.tools.reader.edn :as edn] [clojure.tools.reader.edn :as edn]
[dda.c4k-matomo.core :as core] [dda.c4k-shynet.core :as core]
[dda.c4k-matomo.matomo :as matomo] [dda.c4k-shynet.shynet :as shynet]
[dda.c4k-common.browser :as br] [dda.c4k-common.browser :as br]
[dda.c4k-common.postgres :as pgc])) [dda.c4k-common.postgres :as pgc]))
(defn generate-content (defn generate-content
[] []
(into [] (concat [(assoc (br/generate-needs-validation) :content (into [] (concat [(assoc (br/generate-needs-validation) :content
(into [] (concat (br/generate-input-field "fqdn" "Your fqdn:" "matomo-neu.prod.meissa-gmbh.de") (into [] (concat (br/generate-input-field "fqdn" "Your fqdn:" "shynet-neu.prod.meissa-gmbh.de")
(br/generate-input-field "matomo-data-volume-path" "(Optional) Your matomo-data-volume-path:" "/var/matomo") (br/generate-input-field "shynet-data-volume-path" "(Optional) Your shynet-data-volume-path:" "/var/shynet")
(br/generate-input-field "postgres-data-volume-path" "(Optional) Your postgres-data-volume-path:" "/var/postgres") (br/generate-input-field "postgres-data-volume-path" "(Optional) Your postgres-data-volume-path:" "/var/postgres")
(br/generate-input-field "restic-repository" "(Optional) Your restic-repository:" "restic-repository") (br/generate-input-field "restic-repository" "(Optional) Your restic-repository:" "restic-repository")
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "") (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
[(br/generate-br)] [(br/generate-br)]
(br/generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \"matomo\" (br/generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \"shynet\"
:postgres-db-password \"matomo-db-password\" :postgres-db-password \"shynet-db-password\"
:aws-access-key-id \"aws-id\" :aws-access-key-id \"aws-id\"
:aws-secret-access-key \"aws-secret\" :aws-secret-access-key \"aws-secret\"
:restic-password \"restic-password\"}" :restic-password \"restic-password\"}"
@ -33,14 +33,14 @@
(generate-content)}) (generate-content)})
(defn config-from-document [] (defn config-from-document []
(let [matomo-data-volume-path (br/get-content-from-element "matomo-data-volume-path" :optional true) (let [shynet-data-volume-path (br/get-content-from-element "shynet-data-volume-path" :optional true)
postgres-data-volume-path (br/get-content-from-element "postgres-data-volume-path" :optional true) postgres-data-volume-path (br/get-content-from-element "postgres-data-volume-path" :optional true)
restic-repository (br/get-content-from-element "restic-repository" :optional true) restic-repository (br/get-content-from-element "restic-repository" :optional true)
issuer (br/get-content-from-element "issuer" :optional true :deserializer keyword)] issuer (br/get-content-from-element "issuer" :optional true :deserializer keyword)]
(merge (merge
{:fqdn (br/get-content-from-element "fqdn")} {:fqdn (br/get-content-from-element "fqdn")}
(when (some? matomo-data-volume-path) (when (some? shynet-data-volume-path)
{:matomo-data-volume-path matomo-data-volume-path}) {:shynet-data-volume-path shynet-data-volume-path})
(when (some? postgres-data-volume-path) (when (some? postgres-data-volume-path)
{:postgres-data-volume-path postgres-data-volume-path}) {:postgres-data-volume-path postgres-data-volume-path})
(when (some? restic-repository) (when (some? restic-repository)
@ -50,10 +50,10 @@
))) )))
(defn validate-all! [] (defn validate-all! []
(br/validate! "fqdn" ::matomo/fqdn) (br/validate! "fqdn" ::shynet/fqdn)
(br/validate! "matomo-data-volume-path" ::matomo/matomo-data-volume-path :optional true) (br/validate! "shynet-data-volume-path" ::shynet/shynet-data-volume-path :optional true)
(br/validate! "postgres-data-volume-path" ::pgc/postgres-data-volume-path :optional true) (br/validate! "postgres-data-volume-path" ::pgc/postgres-data-volume-path :optional true)
(br/validate! "issuer" ::matomo/issuer :optional true :deserializer keyword) (br/validate! "issuer" ::shynet/issuer :optional true :deserializer keyword)
(br/validate! "auth" core/auth? :deserializer edn/read-string) (br/validate! "auth" core/auth? :deserializer edn/read-string)
(br/set-validated!)) (br/set-validated!))
@ -73,7 +73,7 @@
(br/get-content-from-element "auth" :deserializer edn/read-string)) (br/get-content-from-element "auth" :deserializer edn/read-string))
(br/set-output!))))) (br/set-output!)))))
(add-validate-listener "fqdn") (add-validate-listener "fqdn")
(add-validate-listener "matomo-data-volume-path") (add-validate-listener "shynet-data-volume-path")
(add-validate-listener "postgres-data-volume-path") (add-validate-listener "postgres-data-volume-path")
(add-validate-listener "restic-repository") (add-validate-listener "restic-repository")
(add-validate-listener "issuer") (add-validate-listener "issuer")

View file

@ -1,8 +1,8 @@
(ns dda.c4k-matomo.matomo-test (ns dda.c4k-shynet.shynet-test
(:require (:require
#?(: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]])
[dda.c4k-matomo.matomo :as cut])) [dda.c4k-shynet.shynet :as cut]))
(deftest should-generate-webserver-deployment (deftest should-generate-webserver-deployment