c4k-nextcloud/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc

60 lines
2.4 KiB
Text
Raw Normal View History

2021-08-10 08:43:04 +00:00
(ns dda.c4k-nextcloud.nextcloud
2021-08-06 15:36:59 +00:00
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]))
(s/def ::fqdn cm/fqdn-string?)
(s/def ::issuer cm/letsencrypt-issuer?)
2021-08-10 08:43:04 +00:00
(s/def ::restic-repository string?)
(s/def ::nextcloud-data-volume-path string?)
2021-08-06 15:36:59 +00:00
#?(:cljs
2021-08-10 08:43:04 +00:00
(defmethod yaml/load-resource :nextcloud [resource-name]
2021-08-06 15:36:59 +00:00
(case resource-name
2021-08-10 08:43:04 +00:00
"nextcloud/certificate.yaml" (rc/inline "nextcloud/certificate.yaml")
"nextcloud/deployment.yaml" (rc/inline "nextcloud/deployment.yaml")
"nextcloud/ingress.yaml" (rc/inline "nextcloud/ingress.yaml")
"nextcloud/persistent-volume.yaml" (rc/inline "nextcloud/persistent-volume.yaml")
"nextcloud/pvc.yaml" (rc/inline "nextcloud/pvc.yaml")
"nextcloud/service.yaml" (rc/inline "nextcloud/service.yaml")
2021-08-06 15:36:59 +00:00
(throw (js/Error. "Undefined Resource!")))))
(defn generate-certificate [config]
(let [{:keys [fqdn issuer]} config
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
(->
2021-08-10 08:43:04 +00:00
(yaml/from-string (yaml/load-resource "nextcloud/certificate.yaml"))
2021-08-06 15:36:59 +00:00
(assoc-in [:spec :commonName] fqdn)
(assoc-in [:spec :dnsNames] [fqdn])
(assoc-in [:spec :issuerRef :name] letsencrypt-issuer))))
(defn generate-deployment [config]
(let [{:keys [fqdn]} config]
2021-08-10 08:43:04 +00:00
(-> (yaml/from-string (yaml/load-resource "nextcloud/deployment.yaml"))
2021-08-10 12:34:17 +00:00
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
2021-08-06 15:36:59 +00:00
(defn generate-ingress [config]
(let [{:keys [fqdn issuer]
:or {issuer :staging}} config
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
(->
2021-08-10 08:43:04 +00:00
(yaml/from-string (yaml/load-resource "nextcloud/ingress.yaml"))
2021-08-06 15:36:59 +00:00
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-persistent-volume [config]
2021-08-10 12:34:17 +00:00
(let [{:keys [nextcloud-data-volume-path storage-size]} config]
2021-08-06 15:36:59 +00:00
(->
2021-08-10 08:43:04 +00:00
(yaml/from-string (yaml/load-resource "nextcloud/persistent-volume.yaml"))
2021-08-10 12:34:17 +00:00
(assoc-in [:spec :hostPath :path] nextcloud-data-volume-path)
2021-08-10 12:41:03 +00:00
;(assoc-in [:spec :capacity :storage] (str storage-size "Gi"))
)))
2021-08-06 15:36:59 +00:00
(defn generate-pvc []
2021-08-10 08:43:04 +00:00
(yaml/from-string (yaml/load-resource "nextcloud/pvc.yaml")))
2021-08-06 15:36:59 +00:00
(defn generate-service []
2021-08-10 08:43:04 +00:00
(yaml/from-string (yaml/load-resource "nextcloud/service.yaml")))