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
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 push -uf origin main
```
## 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

View file

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

View file

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

View file

@ -3,7 +3,7 @@
<head>
<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/fonts/fontawesome/fontawesome.css" rel="stylesheet"
type="text/css" />

View file

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

View file

@ -1,16 +1,16 @@
(ns dda.c4k-matomo.uberjar
(ns dda.c4k-shynet.uberjar
(:gen-class)
(:require
[clojure.spec.alpha :as s]
[clojure.string :as cs]
[clojure.tools.reader.edn :as edn]
[expound.alpha :as expound]
[dda.c4k-matomo.core :as core]))
[dda.c4k-shynet.core :as core]))
(def 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 ::filename (s/and string?

View file

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

View file

@ -1,4 +1,4 @@
(ns dda.c4k-matomo.matomo
(ns dda.c4k-shynet.shynet
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
@ -10,34 +10,34 @@
(s/def ::issuer pred/letsencrypt-issuer?)
#?(:cljs
(defmethod yaml/load-resource :matomo [resource-name]
(defmethod yaml/load-resource :shynet [resource-name]
(case resource-name
"matomo/certificate.yaml" (rc/inline "matomo/certificate.yaml")
"matomo/deployments.yaml" (rc/inline "matomo/deployments.yaml")
"matomo/ingress.yaml" (rc/inline "matomo/ingress.yaml")
"matomo/service-redis.yaml" (rc/inline "matomo/service-redis.yaml")
"matomo/service-webserver.yaml" (rc/inline "matomo/service-webserver.yaml")
"matomo/statefulset.yaml" (rc/inline "matomo/statefulset.yaml")
"shynet/certificate.yaml" (rc/inline "shynet/certificate.yaml")
"shynet/deployments.yaml" (rc/inline "shynet/deployments.yaml")
"shynet/ingress.yaml" (rc/inline "shynet/ingress.yaml")
"shynet/service-redis.yaml" (rc/inline "shynet/service-redis.yaml")
"shynet/service-webserver.yaml" (rc/inline "shynet/service-webserver.yaml")
"shynet/statefulset.yaml" (rc/inline "shynet/statefulset.yaml")
(throw (js/Error. "Undefined Resource!")))))
(defn generate-certificate [config]
(let [{:keys [fqdn issuer]} config
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 :dnsNames] [fqdn])
(assoc-in [:spec :issuerRef :name] letsencrypt-issuer))))
(defn generate-webserver-deployment []
(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)
(update-in [:spec :template :spec :containers 0] dissoc :command))))
(defn generate-celeryworker-deployment []
(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))))
(defn generate-ingress [config]
@ -45,15 +45,15 @@
:or {issuer :staging}} config
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)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(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 []
(yaml/from-string (yaml/load-resource "matomo/service-redis.yaml")))
(yaml/from-string (yaml/load-resource "shynet/service-redis.yaml")))
(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
[clojure.tools.reader.edn :as edn]
[dda.c4k-matomo.core :as core]
[dda.c4k-matomo.matomo :as matomo]
[dda.c4k-shynet.core :as core]
[dda.c4k-shynet.shynet :as shynet]
[dda.c4k-common.browser :as br]
[dda.c4k-common.postgres :as pgc]))
(defn generate-content
[]
(into [] (concat [(assoc (br/generate-needs-validation) :content
(into [] (concat (br/generate-input-field "fqdn" "Your fqdn:" "matomo-neu.prod.meissa-gmbh.de")
(br/generate-input-field "matomo-data-volume-path" "(Optional) Your matomo-data-volume-path:" "/var/matomo")
(into [] (concat (br/generate-input-field "fqdn" "Your fqdn:" "shynet-neu.prod.meissa-gmbh.de")
(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 "restic-repository" "(Optional) Your restic-repository:" "restic-repository")
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "")
[(br/generate-br)]
(br/generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \"matomo\"
:postgres-db-password \"matomo-db-password\"
(br/generate-text-area "auth" "Your auth.edn:" "{:postgres-db-user \"shynet\"
:postgres-db-password \"shynet-db-password\"
:aws-access-key-id \"aws-id\"
:aws-secret-access-key \"aws-secret\"
:restic-password \"restic-password\"}"
@ -33,14 +33,14 @@
(generate-content)})
(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)
restic-repository (br/get-content-from-element "restic-repository" :optional true)
issuer (br/get-content-from-element "issuer" :optional true :deserializer keyword)]
(merge
{:fqdn (br/get-content-from-element "fqdn")}
(when (some? matomo-data-volume-path)
{:matomo-data-volume-path matomo-data-volume-path})
(when (some? shynet-data-volume-path)
{:shynet-data-volume-path shynet-data-volume-path})
(when (some? postgres-data-volume-path)
{:postgres-data-volume-path postgres-data-volume-path})
(when (some? restic-repository)
@ -50,10 +50,10 @@
)))
(defn validate-all! []
(br/validate! "fqdn" ::matomo/fqdn)
(br/validate! "matomo-data-volume-path" ::matomo/matomo-data-volume-path :optional true)
(br/validate! "fqdn" ::shynet/fqdn)
(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! "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/set-validated!))
@ -73,7 +73,7 @@
(br/get-content-from-element "auth" :deserializer edn/read-string))
(br/set-output!)))))
(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 "restic-repository")
(add-validate-listener "issuer")

View file

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