Merge branch 'main' of gitlab.com:domaindrivenarchitecture/c4k-website
This commit is contained in:
commit
04c60aa9bc
12 changed files with 18 additions and 308 deletions
|
@ -2,7 +2,7 @@
|
|||
"name": "c4k-website",
|
||||
"description": "Generate c4k yaml for a website deployment.",
|
||||
"author": "meissa GmbH",
|
||||
"version": "0.2.1-SNAPSHOT",
|
||||
"version": "1.0.1-SNAPSHOT",
|
||||
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-website#readme",
|
||||
"repository": "https://www.npmjs.com/package/c4k-website",
|
||||
"license": "APACHE2",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
(defproject org.domaindrivenarchitecture/c4k-website "0.2.1-SNAPSHOT"
|
||||
(defproject org.domaindrivenarchitecture/c4k-website "1.0.1-SNAPSHOT"
|
||||
:description "website c4k-installation package"
|
||||
:url "https://domaindrivenarchitecture.org"
|
||||
:license {:name "Apache License, Version 2.0"
|
||||
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
||||
:dependencies [[org.clojure/clojure "1.10.3"]
|
||||
[org.clojure/tools.reader "1.3.6"]
|
||||
[org.domaindrivenarchitecture/c4k-common-clj "3.0.2"]
|
||||
[org.domaindrivenarchitecture/c4k-common-clj "3.1.1"]
|
||||
[hickory "0.7.1"]]
|
||||
:target-path "target/%s/"
|
||||
:source-paths ["src/main/cljc"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"src/test/cljc"
|
||||
"src/test/cljs"
|
||||
"src/test/resources"]
|
||||
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "3.0.2"]
|
||||
:dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "3.1.1"]
|
||||
[hickory "0.7.1"]]
|
||||
:builds {:frontend {:target :browser
|
||||
:modules {:main {:init-fn dda.c4k-website.browser/init}}
|
||||
|
|
|
@ -45,8 +45,7 @@
|
|||
(website/generate-nginx-configmap (flatten-and-reduce-config config))
|
||||
(website/generate-nginx-service (flatten-and-reduce-config config))
|
||||
(website/generate-website-content-volume (flatten-and-reduce-config config))
|
||||
(website/generate-website-http-ingress (flatten-and-reduce-config config))
|
||||
(website/generate-website-https-ingress (flatten-and-reduce-config config))
|
||||
(website/generate-website-ingress (flatten-and-reduce-config config))
|
||||
(website/generate-website-certificate (flatten-and-reduce-config config))
|
||||
(website/generate-website-build-cron (flatten-and-reduce-config config))
|
||||
(website/generate-website-initial-build-job (flatten-and-reduce-config config))
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
(ns dda.c4k-website.ingress-cert
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
#?(:cljs [shadow.resource :as rc])
|
||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||
#?(:clj [clojure.edn :as edn]
|
||||
:cljs [cljs.reader :as edn])
|
||||
[dda.c4k-common.yaml :as yaml]
|
||||
[dda.c4k-common.common :as cm]
|
||||
[dda.c4k-common.predicate :as pred]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(s/def ::issuer pred/letsencrypt-issuer?)
|
||||
(s/def ::service-name string?)
|
||||
(s/def ::app-name string?)
|
||||
(s/def ::ingress-name string?)
|
||||
(s/def ::cert-name string?)
|
||||
(s/def ::service-port pos-int?)
|
||||
(s/def ::fqdns (s/coll-of pred/fqdn-string?))
|
||||
|
||||
(def ingress? (s/keys :req-un [::fqdns ::app-name ::ingress-name ::service-name ::service-port]
|
||||
:opt-un [::issuer ::cert-name]))
|
||||
|
||||
(def certificate? (s/keys :req-un [::fqdns ::app-name ::cert-name]
|
||||
:opt-un [::issuer]))
|
||||
|
||||
#?(:cljs
|
||||
(defmethod yaml/load-resource :ingress [resource-name]
|
||||
(case resource-name
|
||||
"ingress/host-rule.yaml" (rc/inline "ingress/host-rule.yaml")
|
||||
"ingress/certificate.yaml" (rc/inline "ingress/certificate.yaml")
|
||||
"ingress/http-ingress.yaml" (rc/inline "ingress/http-ingress.yaml")
|
||||
"ingress/https-ingress.yaml" (rc/inline "ingress/https-ingress.yaml")
|
||||
(throw (js/Error. "Undefined Resource!")))))
|
||||
|
||||
(defn-spec generate-host-rule pred/map-or-seq?
|
||||
[service-name ::service-name
|
||||
service-port ::service-port
|
||||
fqdn pred/fqdn-string?]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/host-rule.yaml")
|
||||
(cm/replace-all-matching-values-by-new-value "FQDN" fqdn)
|
||||
(cm/replace-all-matching-values-by-new-value "SERVICE_PORT" service-port)
|
||||
(cm/replace-all-matching-values-by-new-value "SERVICE_NAME" service-name)))
|
||||
|
||||
(defn-spec generate-http-ingress pred/map-or-seq?
|
||||
[config ingress?]
|
||||
(let [{:keys [ingress-name service-name service-port fqdns app-name]} config]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/http-ingress.yaml")
|
||||
(assoc-in [:metadata :name] ingress-name)
|
||||
(assoc-in [:metadata :labels :app.kubernetes.part-of] app-name)
|
||||
(assoc-in [:spec :rules] (mapv (partial generate-host-rule service-name service-port) fqdns)))))
|
||||
|
||||
(defn-spec generate-https-ingress pred/map-or-seq?
|
||||
[config ingress?]
|
||||
(let [{:keys [ingress-name cert-name service-name service-port fqdns app-name]} config]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/https-ingress.yaml")
|
||||
(assoc-in [:metadata :name] ingress-name)
|
||||
(assoc-in [:metadata :labels :app.kubernetes.part-of] app-name)
|
||||
(assoc-in [:spec :tls 0 :secretName] cert-name)
|
||||
(assoc-in [:spec :tls 0 :hosts] fqdns)
|
||||
(assoc-in [:spec :rules] (mapv (partial generate-host-rule service-name service-port) fqdns)))))
|
||||
|
||||
(defn-spec generate-certificate pred/map-or-seq?
|
||||
[config certificate?]
|
||||
(let [{:keys [cert-name issuer fqdns app-name]
|
||||
:or {issuer "staging"}} config
|
||||
letsencrypt-issuer (name issuer)]
|
||||
(->
|
||||
(yaml/load-as-edn "ingress/certificate.yaml")
|
||||
(assoc-in [:metadata :name] cert-name)
|
||||
(assoc-in [:metadata :labels :app.kubernetes.part-of] app-name)
|
||||
(assoc-in [:spec :secretName] cert-name)
|
||||
(assoc-in [:spec :dnsNames] fqdns)
|
||||
(assoc-in [:spec :issuerRef :name] letsencrypt-issuer))))
|
||||
|
|
@ -10,9 +10,8 @@
|
|||
[dda.c4k-common.common :as cm]
|
||||
[dda.c4k-common.base64 :as b64]
|
||||
[dda.c4k-common.predicate :as pred]
|
||||
[dda.c4k-website.ingress-cert :as ing]
|
||||
[clojure.string :as str]
|
||||
[clojure.string :as st]))
|
||||
[dda.c4k-common.ingress-cert :as ing]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn fqdn-list?
|
||||
[input]
|
||||
|
@ -49,13 +48,13 @@
|
|||
[sha256sum-output string?]
|
||||
(if (nil? sha256sum-output)
|
||||
nil
|
||||
(first (st/split sha256sum-output #"\ +"))))
|
||||
(first (str/split sha256sum-output #"\ +"))))
|
||||
|
||||
(defn-spec get-file-name-from-sha256sum-output string?
|
||||
[sha256sum-output string?]
|
||||
(if (nil? sha256sum-output)
|
||||
nil
|
||||
(second (st/split (st/trim sha256sum-output) #"\ +"))))
|
||||
(second (str/split (str/trim sha256sum-output) #"\ +"))))
|
||||
|
||||
(defn-spec replace-dots-by-minus string?
|
||||
[fqdn pred/fqdn-string?]
|
||||
|
@ -73,13 +72,9 @@
|
|||
[unique-name pred/fqdn-string?]
|
||||
(str (replace-dots-by-minus unique-name) "-cert"))
|
||||
|
||||
(defn-spec generate-http-ingress-name string?
|
||||
(defn-spec generate-ingress-name string?
|
||||
[unique-name pred/fqdn-string?]
|
||||
(str (replace-dots-by-minus unique-name) "-http-ingress"))
|
||||
|
||||
(defn-spec generate-https-ingress-name string?
|
||||
[unique-name pred/fqdn-string?]
|
||||
(str (replace-dots-by-minus unique-name) "-https-ingress"))
|
||||
(str (replace-dots-by-minus unique-name) "-ingress"))
|
||||
|
||||
; https://your.gitea.host/api/v1/repos/<owner>/<repo>/archive/main.zip
|
||||
(defn-spec make-gitrepourl string?
|
||||
|
@ -111,22 +106,12 @@
|
|||
"website/website-content-volume.yaml" (rc/inline "website/website-content-volume.yaml")
|
||||
(throw (js/Error. "Undefined Resource!")))))
|
||||
|
||||
(defn-spec generate-website-http-ingress pred/map-or-seq?
|
||||
(defn-spec generate-website-ingress pred/map-or-seq?
|
||||
[config flattened-and-reduced-config?]
|
||||
(let [{:keys [unique-name fqdns]} config]
|
||||
(ing/generate-http-ingress {:fqdns fqdns
|
||||
(ing/generate-ingress {:fqdns fqdns
|
||||
:app-name (generate-app-name unique-name)
|
||||
:ingress-name (generate-http-ingress-name unique-name)
|
||||
:service-name (generate-service-name unique-name)
|
||||
:service-port 80})))
|
||||
|
||||
(defn-spec generate-website-https-ingress pred/map-or-seq?
|
||||
[config flattened-and-reduced-config?]
|
||||
(let [{:keys [unique-name fqdns]} config]
|
||||
(ing/generate-https-ingress {:fqdns fqdns
|
||||
:cert-name (generate-cert-name unique-name)
|
||||
:app-name (generate-app-name unique-name)
|
||||
:ingress-name (generate-https-ingress-name unique-name)
|
||||
:ingress-name (generate-ingress-name unique-name)
|
||||
:service-name (generate-service-name unique-name)
|
||||
:service-port 80})))
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
apiVersion: cert-manager.io/v1
|
||||
kind: Certificate
|
||||
metadata:
|
||||
name: c4k-common-cert
|
||||
labels:
|
||||
app.kubernetes.part-of: c4k-common-app
|
||||
namespace: default
|
||||
spec:
|
||||
secretName: c4k-common-cert
|
||||
duration: 2160h # 90d
|
||||
renewBefore: 360h # 15d
|
||||
dnsNames:
|
||||
- FQDN
|
||||
issuerRef:
|
||||
name: staging
|
||||
kind: ClusterIssuer
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
host: FQDN
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: SERVICE_NAME
|
||||
port:
|
||||
number: SERVICE_PORT
|
|
@ -1,22 +0,0 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: c4k-common-http-ingress
|
||||
namespace: default
|
||||
labels:
|
||||
app.kubernetes.part-of: c4k-common-app
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: web
|
||||
traefik.ingress.kubernetes.io/router.middlewares: default-redirect-https@kubernetescrd
|
||||
spec:
|
||||
rules:
|
||||
- host: FQDN
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: SERVICE_NAME
|
||||
port:
|
||||
number: 80
|
|
@ -1,26 +0,0 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: c4k-common-https-ingress
|
||||
namespace: default
|
||||
labels:
|
||||
app.kubernetes.part-of: c4k-common-app
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- FQDN
|
||||
secretName: c4k-common-cert
|
||||
rules:
|
||||
- host: FQDN
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
backend:
|
||||
service:
|
||||
name: SERVICE_NAME
|
||||
port:
|
||||
number: 80
|
|
@ -1,119 +0,0 @@
|
|||
(ns dda.c4k-website.ingress-cert-test
|
||||
(:require
|
||||
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
||||
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[dda.c4k-website.ingress-cert :as cut]))
|
||||
|
||||
(st/instrument `cut/generate-host-rule)
|
||||
(st/instrument `cut/generate-http-ingress)
|
||||
(st/instrument `cut/generate-https-ingress)
|
||||
(st/instrument `cut/generate-certificate)
|
||||
|
||||
(deftest should-generate-rule
|
||||
(is (= {:host "test.com",
|
||||
:http
|
||||
{:paths
|
||||
[{:pathType "Prefix",
|
||||
:path "/",
|
||||
:backend
|
||||
{:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||
(cut/generate-host-rule "myservice" 3000 "test.com"))))
|
||||
|
||||
|
||||
(deftest should-generate-http-ingress
|
||||
(is (= {:apiVersion "networking.k8s.io/v1",
|
||||
:kind "Ingress",
|
||||
:metadata
|
||||
{:name "test-io-http-ingress",
|
||||
:namespace "default",
|
||||
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
||||
:annotations
|
||||
#:traefik.ingress.kubernetes.io{:router.entrypoints "web",
|
||||
:router.middlewares "default-redirect-https@kubernetescrd"}}}
|
||||
(dissoc (cut/generate-http-ingress
|
||||
{:issuer "prod"
|
||||
:app-name "c4k-common-app"
|
||||
:service-name "myservice"
|
||||
:service-port 3000
|
||||
:ingress-name "test-io-http-ingress"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :spec)))
|
||||
(is (= {:rules
|
||||
[{:host "test.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||
{:host "www.test.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||
{:host "test-it.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}
|
||||
{:host "www.test-it.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "myservice", :port {:number 3000}}}}]}}]}
|
||||
(:spec (cut/generate-http-ingress
|
||||
{:issuer "prod"
|
||||
:service-name "myservice"
|
||||
:app-name "c4k-common-app"
|
||||
:service-port 3000
|
||||
:ingress-name "test-io-http-ingress"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
|
||||
|
||||
(deftest should-generate-https-ingress
|
||||
(is (= {:apiVersion "networking.k8s.io/v1",
|
||||
:kind "Ingress",
|
||||
:metadata
|
||||
{:name "test-io-https-ingress",
|
||||
:namespace "default",
|
||||
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
||||
:annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "websecure", :router.tls "true"}}}
|
||||
(dissoc (cut/generate-https-ingress
|
||||
{:issuer "prod"
|
||||
:service-name "test-io-service"
|
||||
:app-name "c4k-common-app"
|
||||
:service-port 80
|
||||
:ingress-name "test-io-https-ingress"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :spec)))
|
||||
(is (= {:tls
|
||||
[{:hosts
|
||||
["test.de" "www.test.de" "test-it.de" "www.test-it.de"],
|
||||
:secretName "test-io-cert"}]
|
||||
:rules
|
||||
[{:host "test.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
||||
{:host "www.test.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
||||
{:host "test-it.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
||||
{:host "www.test-it.de",
|
||||
:http
|
||||
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}
|
||||
(:spec (cut/generate-https-ingress {:issuer "prod"
|
||||
:app-name "c4k-common-app"
|
||||
:service-name "test-io-service"
|
||||
:service-port 80
|
||||
:ingress-name "test-io-https-ingress"
|
||||
:cert-name "test-io-cert"
|
||||
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
|
||||
|
||||
(deftest should-generate-certificate
|
||||
(is (= {:apiVersion "cert-manager.io/v1",
|
||||
:kind "Certificate",
|
||||
:metadata {
|
||||
:name "test-io-cert",
|
||||
:namespace "default",
|
||||
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
||||
},
|
||||
:spec
|
||||
{:secretName "test-io-cert",
|
||||
:duration "2160h",
|
||||
:renewBefore "360h",
|
||||
:dnsNames ["test.de" "test.org" "www.test.de" "www.test.org"],
|
||||
:issuerRef {:name "prod", :kind "ClusterIssuer"}}}
|
||||
(cut/generate-certificate {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
|
||||
:app-name "c4k-common-app"
|
||||
:cert-name "test-io-cert"
|
||||
:issuer "prod"}))))
|
|
@ -8,12 +8,11 @@
|
|||
[dda.c4k-website.website :as cut]
|
||||
[clojure.spec.alpha :as s]))
|
||||
|
||||
(st/instrument `cut/generate-http-ingress)
|
||||
(st/instrument `cut/generate-https-ingress)
|
||||
(st/instrument `cut/generate-nginx-configmap)
|
||||
(st/instrument `cut/generate-nginx-deployment)
|
||||
(st/instrument `cut/generate-nginx-service)
|
||||
(st/instrument `cut/generate-website-content-volume)
|
||||
(st/instrument `cut/generate-website-ingress)
|
||||
(st/instrument `cut/generate-website-certificate)
|
||||
(st/instrument `cut/generate-website-build-cron)
|
||||
(st/instrument `cut/generate-website-build-deployment)
|
||||
|
|
Loading…
Reference in a new issue