added tests
This commit is contained in:
parent
2f78c5d8ff
commit
5908a1b8d8
4 changed files with 209 additions and 69 deletions
|
@ -1,69 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>c4k-keycloak</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" />
|
|
||||||
<link href="https://domaindrivenarchitecture.org/css/custom.css" rel="stylesheet" type="text/css" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="container jumbotron">
|
|
||||||
<form class="needs-validation" id="form">
|
|
||||||
<label for="fqdn" class="form-label">Your fqdn:</label>
|
|
||||||
<input class="form-control" type="text" name="fqdn" id="fqdn" value="jira-neu.prod.meissa-gmbh.de">
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="fqdn-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<label for="jira-data-volume-path" class="form-label">(Optional) Your jira-data-volume-path:</label>
|
|
||||||
<input class="form-control" type="text" name="jira-data-volume-path" id="jira-data-volume-path" value="/var/jira">
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="jira-data-volume-path-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<label for="postgres-data-volume-path" class="form-label">(Optional) Your postgres-data-volume-path:</label>
|
|
||||||
<input class="form-control" type="text" name="postgres-data-volume-path" id="postgres-data-volume-path" value="/var/postgres">
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="postgres-data-volume-path-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<label for="restic-repository" class="form-label">(Optional) Your restic-repository:</label>
|
|
||||||
<input class="form-control" type="text" name="restic-repository" id="restic-repository" value="restic-repository">
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="restic-repository-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
<label for="issuer" class="form-label">(Optional) Your issuer prod/staging:</label>
|
|
||||||
<input class="form-control" type="text" name="issuer" id="issuer" value="">
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="issuer-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<br><br>
|
|
||||||
<label for="auth" class="form-label">Your auth.edn:</label>
|
|
||||||
<textarea name="auth" id="auth" class="form-control" rows="5">
|
|
||||||
{:postgres-db-user "jira"
|
|
||||||
:postgres-db-password "jira-db-password"
|
|
||||||
:aws-access-key-id "aws-id"
|
|
||||||
:aws-secret-access-key "aws-secret"
|
|
||||||
:restic-password "restic-password"}
|
|
||||||
</textarea>
|
|
||||||
<div class="invalid-feedback">
|
|
||||||
<pre id="auth-validation"></pre>
|
|
||||||
</div>
|
|
||||||
<br><br>
|
|
||||||
<button type="button" id="generate-button" class="btn btn-primary">
|
|
||||||
Generate c4k yaml
|
|
||||||
</button>
|
|
||||||
</form><br><br>
|
|
||||||
<div id="c4k-keycloak-output">
|
|
||||||
<label for="output" class="form-label">Your c4k deployment.yaml:</label>
|
|
||||||
<textarea name="output" id="output" class="form-control" rows="25">
|
|
||||||
</textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<script src="js/main.js"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
93
src/test/cljc/dda/c4k_nextcloud/backup_test.cljc
Normal file
93
src/test/cljc/dda/c4k_nextcloud/backup_test.cljc
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
(ns dda.c4k-nextcloud.backup-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-nextcloud.backup :as cut]))
|
||||||
|
|
||||||
|
|
||||||
|
(deftest should-generate-secret
|
||||||
|
(is (= {:apiVersion "v1"
|
||||||
|
:kind "Secret"
|
||||||
|
:metadata {:name "backup-secret"}
|
||||||
|
:type "Opaque"
|
||||||
|
:data
|
||||||
|
{:aws-access-key-id "YXdzLWlk", :aws-secret-access-key "YXdzLXNlY3JldA==", :restic-password "cmVzdGljLXB3"}}
|
||||||
|
(cut/generate-secret {:aws-access-key-id "aws-id" :aws-secret-access-key "aws-secret" :restic-password "restic-pw"}))))
|
||||||
|
|
||||||
|
(deftest should-generate-config
|
||||||
|
(is (= {:apiVersion "v1"
|
||||||
|
:kind "ConfigMap"
|
||||||
|
:metadata {:name "backup-config"
|
||||||
|
:labels {:app.kubernetes.io/name "backup"
|
||||||
|
:app.kubernetes.io/part-of "cloud"}}
|
||||||
|
:data
|
||||||
|
{:restic-repository "s3:restic-repository"}}
|
||||||
|
(cut/generate-config {:restic-repository "s3:restic-repository"}))))
|
||||||
|
|
||||||
|
(deftest should-generate-cron
|
||||||
|
(is (= {:apiVersion "batch/v1beta1"
|
||||||
|
:kind "CronJob"
|
||||||
|
:metadata {:name "nextcloud-backup"
|
||||||
|
:labels {:app.kubernetes.part-of "cloud"}}
|
||||||
|
:spec {:schedule "10 23 * * *"
|
||||||
|
:successfulJobsHistoryLimit 1
|
||||||
|
:failedJobsHistoryLimit 1
|
||||||
|
:jobTemplate
|
||||||
|
{:spec
|
||||||
|
{:template
|
||||||
|
{:spec
|
||||||
|
{:containers
|
||||||
|
[{:name "backup-app"
|
||||||
|
:image "domaindrivenarchitecture/c4k-nextcloud-backup"
|
||||||
|
:imagePullPolicy "IfNotPresent"
|
||||||
|
:command ["/entrypoint.sh"]
|
||||||
|
:env
|
||||||
|
[{:name "POSTGRES_USER"
|
||||||
|
:valueFrom
|
||||||
|
{:secretKeyRef
|
||||||
|
{:name "postgres-secret"
|
||||||
|
:key "postgres-user"}}}
|
||||||
|
{:name "POSTGRES_PASSWORD"
|
||||||
|
:valueFrom
|
||||||
|
{:secretKeyRef
|
||||||
|
{:name "postgres-secret"
|
||||||
|
:key "postgres-password"}}}
|
||||||
|
{:name "POSTGRES_DB"
|
||||||
|
:valueFrom
|
||||||
|
{:configMapKeyRef
|
||||||
|
{:name "postgres-config"
|
||||||
|
:key "postgres-db"}}}
|
||||||
|
{:name "POSTGRES_HOST"
|
||||||
|
:value "postgresql-service:5432"}
|
||||||
|
{:name "POSTGRES_SERVICE"
|
||||||
|
:value "postgresql-service"}
|
||||||
|
{:name "POSTGRES_PORT"
|
||||||
|
:value "5432"}
|
||||||
|
{:name "AWS_DEFAULT_REGION"
|
||||||
|
:value "eu-central-1"}
|
||||||
|
{:name "AWS_ACCESS_KEY_ID_FILE"
|
||||||
|
:value "/var/run/secrets/backup-secrets/aws-access-key-id"}
|
||||||
|
{:name "AWS_SECRET_ACCESS_KEY_FILE"
|
||||||
|
:value "/var/run/secrets/backup-secrets/aws-secret-access-key"}
|
||||||
|
{:name "RESTIC_REPOSITORY"
|
||||||
|
:valueFrom
|
||||||
|
{:configMapKeyRef
|
||||||
|
{:name "backup-config"
|
||||||
|
:key "restic-repository"}}}
|
||||||
|
{:name "RESTIC_PASSWORD_FILE"
|
||||||
|
:value "/var/run/secrets/backup-secrets/restic-password"}]
|
||||||
|
:volumeMounts
|
||||||
|
[{:name "nextcloud-data-volume"
|
||||||
|
:mountPath "/var/backups"}
|
||||||
|
{:name "backup-secret-volume"
|
||||||
|
:mountPath "/var/run/secrets/backup-secrets"
|
||||||
|
:readOnly true}]}]
|
||||||
|
:volumes
|
||||||
|
[{:name "nextcloud-data-volume"
|
||||||
|
:persistentVolumeClaim
|
||||||
|
{:claimName "nextcloud-pvc"}}
|
||||||
|
{:name "backup-secret-volume"
|
||||||
|
:secret
|
||||||
|
{:secretName "backup-secret"}}]
|
||||||
|
:restartPolicy "OnFailure"}}}}}}
|
||||||
|
(cut/generate-cron))))
|
35
src/test/cljc/dda/c4k_nextcloud/core_test.cljc
Normal file
35
src/test/cljc/dda/c4k_nextcloud/core_test.cljc
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
(ns dda.c4k-nextcloud.core-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-nextcloud.core :as cut]))
|
||||||
|
|
||||||
|
(deftest should-k8s-objects
|
||||||
|
(is (= 16
|
||||||
|
(count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de"
|
||||||
|
:postgres-db-user "nextcloud"
|
||||||
|
:postgres-db-password "nextcloud-db-password"
|
||||||
|
:issuer :prod
|
||||||
|
:nextcloud-data-volume-path "/var/nextcloud"
|
||||||
|
:postgres-data-volume-path "/var/postgres"
|
||||||
|
:aws-access-key-id "aws-id"
|
||||||
|
:aws-secret-access-key "aws-secret"
|
||||||
|
:restic-password "restic-pw"
|
||||||
|
:restic-repository "restic-repository"}))))
|
||||||
|
(is (= 14
|
||||||
|
(count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de"
|
||||||
|
:postgres-db-user "nextcloud"
|
||||||
|
:postgres-db-password "nextcloud-db-password"
|
||||||
|
:issuer :prod
|
||||||
|
:aws-access-key-id "aws-id"
|
||||||
|
:aws-secret-access-key "aws-secret"
|
||||||
|
:restic-password "restic-pw"
|
||||||
|
:restic-repository "restic-repository"}))))
|
||||||
|
(is (= 11
|
||||||
|
(count (cut/k8s-objects {:fqdn "nextcloud-neu.prod.meissa-gmbh.de"
|
||||||
|
:postgres-db-user "nextcloud"
|
||||||
|
:postgres-db-password "nextcloud-db-password"
|
||||||
|
:issuer :prod
|
||||||
|
:aws-access-key-id "aws-id"
|
||||||
|
:aws-secret-access-key "aws-secret"
|
||||||
|
:restic-password "restic-pw"})))))
|
81
src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc
Normal file
81
src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
(ns dda.c4k-nextcloud.nextcloud-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-nextcloud.nextcloud :as cut]))
|
||||||
|
|
||||||
|
(deftest should-generate-certificate
|
||||||
|
(is (= {:apiVersion "cert-manager.io/v1alpha2"
|
||||||
|
:kind "Certificate"
|
||||||
|
:metadata {:name "cloud-cert", :namespace "default"}
|
||||||
|
:spec
|
||||||
|
{:secretName "cloud-secret"
|
||||||
|
:commonName "xx"
|
||||||
|
:dnsNames ["xx"]
|
||||||
|
:issuerRef
|
||||||
|
{:name "letsencrypt-prod-issuer", :kind "ClusterIssuer"}}}
|
||||||
|
(cut/generate-certificate {:fqdn "xx" :issuer :prod}))))
|
||||||
|
|
||||||
|
(deftest should-generate-ingress
|
||||||
|
(is (= {:apiVersion "extensions/v1beta1"
|
||||||
|
:kind "Ingress"
|
||||||
|
:metadata
|
||||||
|
{:name "ingress-cloud"
|
||||||
|
:annotations
|
||||||
|
{:cert-manager.io/cluster-issuer
|
||||||
|
"letsencrypt-staging-issuer"
|
||||||
|
:nginx.ingress.kubernetes.io/proxy-body-size "256m"
|
||||||
|
:nginx.ingress.kubernetes.io/ssl-redirect "true"
|
||||||
|
:nginx.ingress.kubernetes.io/rewrite-target "/"
|
||||||
|
:nginx.ingress.kubernetes.io/proxy-connect-timeout "300"
|
||||||
|
:nginx.ingress.kubernetes.io/proxy-send-timeout "300"
|
||||||
|
:nginx.ingress.kubernetes.io/proxy-read-timeout "300"}
|
||||||
|
:namespace "default"}
|
||||||
|
:spec
|
||||||
|
{:tls [{:hosts ["xx"], :secretName "nextcloud-secret"}]
|
||||||
|
:rules
|
||||||
|
[{:host "xx"
|
||||||
|
:http
|
||||||
|
{:paths
|
||||||
|
[{:path "/"
|
||||||
|
:backend
|
||||||
|
{:serviceName "nextcloud-service", :servicePort 80}}]}}]}}
|
||||||
|
(cut/generate-ingress {:fqdn "xx"}))))
|
||||||
|
|
||||||
|
(deftest should-generate-persistent-volume
|
||||||
|
(is (= {:kind "PersistentVolume"
|
||||||
|
:apiVersion "v1"
|
||||||
|
:metadata {:name "cloud-pv-volume", :labels {:type "local" :app "cloud"}}
|
||||||
|
:spec
|
||||||
|
{:storageClassName "manual"
|
||||||
|
:accessModes ["ReadWriteOnce"]
|
||||||
|
:capacity {:storage "200Gi"}
|
||||||
|
:hostPath {:path "xx"}}}
|
||||||
|
(cut/generate-persistent-volume {:nextcloud-data-volume-path "xx"}))))
|
||||||
|
|
||||||
|
(deftest should-generate-deployment
|
||||||
|
(is (= {:containers
|
||||||
|
[{:image "domaindrivenarchitecture/meissa-cloud-app"
|
||||||
|
:name "cloud-app"
|
||||||
|
:imagePullPolicy "IfNotPresent"
|
||||||
|
:ports [{:containerPort 80}]
|
||||||
|
:env
|
||||||
|
[{:name "DB_USERNAME_FILE"
|
||||||
|
:value
|
||||||
|
"/var/run/secrets/postgres-secret/postgres-user"}
|
||||||
|
{:name "DB_PASSWORD_FILE"
|
||||||
|
:value
|
||||||
|
"/var/run/secrets/postgres-secret/postgres-password"}
|
||||||
|
{:name "FQDN", :value "xx"}]
|
||||||
|
:command ["/app/entrypoint.sh"]
|
||||||
|
:volumeMounts
|
||||||
|
[{:mountPath "/var/nextcloud", :name "cloud-data-volume"}
|
||||||
|
{:name "postgres-secret-volume"
|
||||||
|
:mountPath "/var/run/secrets/postgres-secret"
|
||||||
|
:readOnly true}]}]
|
||||||
|
:volumes
|
||||||
|
[{:name "cloud-data-volume"
|
||||||
|
:persistentVolumeClaim {:claimName "cloud-pvc"}}
|
||||||
|
{:name "postgres-secret-volume"
|
||||||
|
:secret {:secretName "postgres-secret"}}]}
|
||||||
|
(get-in (cut/generate-deployment {:fqdn "xx"}) [:spec :template :spec]))))
|
Loading…
Reference in a new issue