c4k now works
This commit is contained in:
parent
79ba8b75ff
commit
1ab16b8529
10 changed files with 74 additions and 136 deletions
3
deps.edn
3
deps.edn
|
@ -5,7 +5,8 @@
|
||||||
["src" "resources"]
|
["src" "resources"]
|
||||||
|
|
||||||
:deps
|
:deps
|
||||||
{org.clojure/spec.alpha {:mvn/version "0.5.238"}
|
{org.clojure/clojure {:mvn/version "1.12.0"}
|
||||||
|
org.clojure/spec.alpha {:mvn/version "0.5.238"}
|
||||||
orchestra/orchestra {:mvn/version "2021.01.01-1"}
|
orchestra/orchestra {:mvn/version "2021.01.01-1"}
|
||||||
aero/aero {:mvn/version "1.1.6"}
|
aero/aero {:mvn/version "1.1.6"}
|
||||||
org.domaindrivenarchitecture/c4k-common-clj {:mvn/version "8.0.1-SNAPSHOT"}
|
org.domaindrivenarchitecture/c4k-common-clj {:mvn/version "8.0.1-SNAPSHOT"}
|
||||||
|
|
|
@ -1,56 +1,59 @@
|
||||||
(ns dda.build.c4k
|
(ns dda.build.c4k
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
(:require
|
||||||
[clojure.spec.test.alpha :as st]
|
[clojure.spec.alpha :as s]
|
||||||
[cheshire.core :as cs]
|
[clojure.spec.test.alpha :as st]
|
||||||
[dda.build.devops :as devops]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[dda.build.terragrunt :as tg]
|
[dda.build.devops :as devops]
|
||||||
[dda.build.config :as cfg]
|
[dda.build.terragrunt :as tg]
|
||||||
[dda.build.c4k.domain :as domain]
|
[dda.build.config :as cfg]
|
||||||
[dda.build.infrastructure :as i]))
|
[dda.build.c4k.domain :as domain]
|
||||||
|
[dda.build.infrastructure :as i]))
|
||||||
(st/instrument `clean-build-dir!)
|
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
(merge devops/default
|
(merge devops/default
|
||||||
tf/default
|
|
||||||
{:c4k-output "c4k-app.yaml"
|
{:c4k-output "c4k-app.yaml"
|
||||||
:c4k-config-input "c4k-config.edn"
|
:c4k-config-input "c4k-config.edn"
|
||||||
:c4k-auth-input "c4k-auth.edn"}))
|
:c4k-auth-input "c4k-auth.edn"}))
|
||||||
|
|
||||||
(s/def ::c4k (s/merge
|
(s/def ::c4k (s/merge
|
||||||
::devops/devops
|
::devops/devops
|
||||||
::tg/tg
|
(s/keys :opt-un [::domain/c4k-output ::domain/c4k-config-input ::domain/c4k-auth-input ::domain/c4k-app-name])))
|
||||||
(s/keys :opt-un [::domain/c4k-output ::domain/c4k-config-input ::domain/c4k-auth-input])))
|
|
||||||
|
(defn- default-cfg
|
||||||
|
[input]
|
||||||
|
(merge default
|
||||||
|
(when (and (not (contains? input :c4k-app-name))
|
||||||
|
(contains? input :module))
|
||||||
|
{:c4k-app-name (:module input)})
|
||||||
|
input))
|
||||||
|
|
||||||
(defn-spec clean-build-dir! nil?
|
(defn-spec clean-build-dir! nil?
|
||||||
[devops ::c4kg]
|
[devops ::c4k]
|
||||||
(let [config (merge default devops)]
|
(let [config (default-cfg devops)]
|
||||||
(i/execute! (domain/clean-build-dir-command config) config)))
|
(i/execute! (domain/clean-build-dir-command config) config)))
|
||||||
|
|
||||||
(defn-spec run-c4k-jar! nil?
|
(defn-spec run-c4k-jar! nil?
|
||||||
[devops ::c4kg]
|
[devops ::c4k]
|
||||||
(let [config (merge default devops)]
|
(let [config (default-cfg devops)]
|
||||||
(doseq [c (domain/c4k-uberjar-command config)]
|
(i/execute! (domain/c4k-uberjar-command config) config)))
|
||||||
(i/execute! c config))))
|
|
||||||
|
|
||||||
(defn-spec run-c4k-bin! nil?
|
(defn-spec run-c4k-bin! nil?
|
||||||
[devops ::c4kg]
|
[devops ::c4k]
|
||||||
(let [config (merge default devops)]
|
(let [config (default-cfg devops)]
|
||||||
(doseq [c (domain/c4k-graalvm-command config)]
|
(doseq [c (domain/c4k-graalvm-command config)]
|
||||||
(i/execute! c config))))
|
(i/execute! c config))))
|
||||||
|
|
||||||
(defn-spec write-c4k-objects! nil?
|
(defn-spec write-c4k-objects! nil?
|
||||||
[devops ::c4kg
|
[devops ::c4k
|
||||||
tf-out ::tg-domain/tf-out]
|
tf-out ::tg/tf-out]
|
||||||
(let [config (merge default devops)
|
(let [config (default-cfg devops)]
|
||||||
{:keys [module c4k-auth-input c4k-config-input c4k-output]} config]
|
|
||||||
(->> (cfg/read-config (domain/config-path config))
|
(->> (cfg/read-config (domain/config-path config))
|
||||||
(merge {:fqdn (:fqdn (:value (:out tf-out)))})
|
(merge {:fqdn (:fqdn (:value (:out tf-out)))})
|
||||||
(cs/generate-string)
|
(pr-str)
|
||||||
(spit (domain/config-path config)))
|
(spit (domain/config-path config)))
|
||||||
(->> (cfg/read-config (domain/config-auth config))
|
(->> (cfg/read-config (domain/auth-path config))
|
||||||
(cs/generate-string)
|
(pr-str)
|
||||||
(spit (domain/config-auth config))
|
(spit (domain/auth-path config)))
|
||||||
(run-c4k-jar! config)))
|
(run-c4k-jar! config)))
|
||||||
|
|
||||||
(st/instrument `clean-build-dir!)
|
(st/instrument `clean-build-dir!)
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
[orchestra.core :refer [defn-spec]]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[dda.build.devops.domain :as d]))
|
[dda.build.devops.domain :as d]))
|
||||||
|
|
||||||
|
(s/def ::c4k-app-name string?)
|
||||||
(s/def ::c4k-output string?)
|
(s/def ::c4k-output string?)
|
||||||
(s/def ::c4k-config-input string?)
|
(s/def ::c4k-config-input string?)
|
||||||
(s/def ::c4k-auth-input string?)
|
(s/def ::c4k-auth-input string?)
|
||||||
|
|
||||||
(s/def ::config
|
(s/def ::config
|
||||||
(s/merge ::d/devops
|
(s/merge ::d/devops
|
||||||
(s/keys :req-un [::c4k-output ::c4k-config-input ::c4k-auth-input])))
|
(s/keys :req-un [::c4k-output ::c4k-config-input ::c4k-auth-input ::c4k-app-name])))
|
||||||
|
|
||||||
(defn-spec config-path string?
|
(defn-spec config-path string?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
|
@ -32,12 +33,12 @@
|
||||||
|
|
||||||
(defn-spec c4k-uberjar-command seq?
|
(defn-spec c4k-uberjar-command seq?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
(let [{:keys [module]} config
|
(let [{:keys [c4k-app-name]} config
|
||||||
executable-name (str "c4k-" module "-standalone.jar")]
|
executable-name (str "c4k-" c4k-app-name "-standalone.jar")]
|
||||||
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
||||||
|
|
||||||
(defn-spec c4k-graalvm-command seq?
|
(defn-spec c4k-graalvm-command seq?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
(let [{:keys [module]} config
|
(let [{:keys [c4k-app-name]} config
|
||||||
executable-name (str "c4k-" module)]
|
executable-name (str "c4k-" c4k-app-name)]
|
||||||
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
(ns dda.build.config
|
(ns dda.build.config
|
||||||
"
|
"{:test huhu :long-name #env LOGNAME :gopass-pw #gopass [sopra/test.de] :gopass-field-url #gopass [sopra/test.de url]}"
|
||||||
{:test huhu
|
|
||||||
:long-name #env LOGNAME
|
|
||||||
:gopass-pw #gopass [sopra/test.de]
|
|
||||||
:gopass-field-url #gopass [sopra/test.de url]}
|
|
||||||
"
|
|
||||||
(:require [aero.core :as aero]
|
(:require [aero.core :as aero]
|
||||||
[dda.build.infrastructure :as i]))
|
[dda.build.infrastructure :as i]))
|
||||||
|
|
||||||
|
@ -14,4 +9,9 @@
|
||||||
|
|
||||||
(defn read-config
|
(defn read-config
|
||||||
[file]
|
[file]
|
||||||
(aero/read-config file))
|
(try
|
||||||
|
(aero/read-config file)
|
||||||
|
(catch Exception e
|
||||||
|
(do (println (str "Warn: " e))
|
||||||
|
{}))
|
||||||
|
))
|
||||||
|
|
|
@ -1,20 +1,12 @@
|
||||||
(ns dda.build.devops
|
(ns dda.build.devops
|
||||||
(:require
|
(:require [clojure.spec.alpha :as s]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[clojure.spec.test.alpha :as st]
|
[dda.build.devops.domain :as domain]
|
||||||
[clojure.spec.alpha :as s]
|
[dda.build.infrastructure :as i]))
|
||||||
[dda.build.devops.domain :as domain]
|
|
||||||
[dda.build.infrastructure :as i]))
|
|
||||||
|
|
||||||
(s/def ::name ::domain/name)
|
|
||||||
(s/def ::module ::domain/module)
|
|
||||||
(s/def ::stage ::domain/stage)
|
|
||||||
(s/def ::project-root-path ::domain/project-root-path)
|
|
||||||
(s/def ::build-dir-name ::domain/build-dir-name)
|
|
||||||
|
|
||||||
(s/def ::devops
|
(s/def ::devops
|
||||||
(s/keys :req-un [::name]
|
(s/keys :req-un [::domain/name]
|
||||||
:opt-un [::module ::stage ::project-root-path ::build-dir-name ::debug ::dry-run]))
|
:opt-un [::domain/module ::domain/stage ::domain/project-root-path ::domain/build-dir-name ::domain/debug ::domain/dry-run]))
|
||||||
|
|
||||||
(def default {:name "dda-backup"
|
(def default {:name "dda-backup"
|
||||||
:project-root-path "."
|
:project-root-path "."
|
||||||
|
@ -42,7 +34,3 @@
|
||||||
[devops ::devops]
|
[devops ::devops]
|
||||||
(let [final (merge default devops)]
|
(let [final (merge default devops)]
|
||||||
(i/execute! (domain/create-build-dir-command final) final)))
|
(i/execute! (domain/create-build-dir-command final) final)))
|
||||||
|
|
||||||
(st/instrument `clean-build-dir!)
|
|
||||||
(st/instrument `create-build-dir!)
|
|
||||||
(st/instrument `env-or-file)#
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns dda.build.devops.domain
|
(ns dda.build.devops.domain
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as str]
|
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.string :as str]
|
||||||
[orchestra.core :refer [defn-spec]]))
|
[orchestra.core :refer [defn-spec]]))
|
||||||
|
|
||||||
(s/def ::name string?)
|
(s/def ::name string?)
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
(ns dda.build.gopass
|
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
|
||||||
[clojure.spec.test.alpha :as st]
|
|
||||||
[cheshire.core :refer [parse-string generate-string]]
|
|
||||||
[aero.core :refer :as aero]
|
|
||||||
[dda.build.devops :as d]
|
|
||||||
[dda.build.gopass.domain :as domain]
|
|
||||||
[dda.build.c4k.domain :as c4k-d]
|
|
||||||
[dda.build.infrastructure :as i]))
|
|
||||||
|
|
||||||
(def default
|
|
||||||
(merge d/default {:c4k-auth-filename "c4k-auth.yaml"}))
|
|
||||||
|
|
||||||
(defn-spec run-gopass-command! string?
|
|
||||||
[devops ::d/devops
|
|
||||||
entry ::domain/gopass-entry]
|
|
||||||
(let [config (merge default devops)
|
|
||||||
c (domain/gopass-show-command entry)]
|
|
||||||
(i/execute-output! c config)))
|
|
||||||
|
|
||||||
(defn-spec resolve-gopass! ::domain/resolved-config
|
|
||||||
"Resolves gopass values inside a map of key names and entries
|
|
||||||
|
|
||||||
entries may either contain only a path
|
|
||||||
{:path \"test/path\"}
|
|
||||||
or a path and a field
|
|
||||||
{:path \"test/path\" :field \"field\"}
|
|
||||||
"
|
|
||||||
[devops ::d/devops
|
|
||||||
config ::domain/config]
|
|
||||||
(apply merge (for [[k v] config] {(name k) (run-gopass-command! devops v)})))
|
|
||||||
|
|
||||||
(defn-spec insert-gopass! nil?
|
|
||||||
"Inserts values from the resolved auth config into the c4k auth
|
|
||||||
|
|
||||||
Default: c4k-auth.yaml
|
|
||||||
can be changed by adding another value for ':c4k-auth-filename'
|
|
||||||
"
|
|
||||||
[devops ::d/devops
|
|
||||||
resolved-config ::domain/resolved-config]
|
|
||||||
(let [config (merge default devops)
|
|
||||||
default-c4k-auth (parse-string (slurp (c4k-d/auth-path config))
|
|
||||||
(fn [k] (keyword (.toLowerCase k))))]
|
|
||||||
(->> default-c4k-auth
|
|
||||||
(merge resolved-config)
|
|
||||||
(generate-string)
|
|
||||||
(spit (c4k-d/auth-path config)))))
|
|
||||||
|
|
||||||
(defmethod aero/reader 'gopass
|
|
||||||
[{:keys [profile] :as opts} tag value]
|
|
||||||
(i/execute-output! (into ["gopass" "show" "-y" "-o"] value) {}))
|
|
||||||
|
|
||||||
(defn read-config []
|
|
||||||
(aero/read-config "config.edn"))
|
|
||||||
|
|
||||||
|
|
||||||
(st/instrument `run-gopass-command!)
|
|
||||||
(st/instrument `resolve-gopass!)
|
|
||||||
(st/instrument `insert-gopass!)
|
|
|
@ -1,12 +1,12 @@
|
||||||
(ns dda.build.provs
|
(ns dda.build.provs
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[clojure.spec.test.alpha :as st]
|
||||||
[clojure.spec.test.alpha :as st]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[cheshire.core :refer [generate-string]]
|
[cheshire.core :refer [generate-string]]
|
||||||
[dda.build.c4k :as c4k]
|
[dda.build.c4k :as c4k]
|
||||||
[dda.build.terragrunt :as tg]
|
[dda.build.terragrunt :as tg]
|
||||||
[dda.build.provs.domain :as domain]
|
[dda.build.provs.domain :as domain]
|
||||||
[dda.build.infrastructure :as i]))
|
[dda.build.infrastructure :as i]))
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
(merge c4k/default
|
(merge c4k/default
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
:k3s-provision-user "root"
|
:k3s-provision-user "root"
|
||||||
:echo false}))
|
:echo false}))
|
||||||
(s/def ::provs (s/merge ::c4k/c4k
|
(s/def ::provs (s/merge ::c4k/c4k
|
||||||
(s/keys
|
(s/keys
|
||||||
:req-un [::domain/email ::domain/fqdn ::domain/ipv4 ::domain/ipv6]
|
:req-un [::domain/email ::domain/fqdn ::domain/ipv4 ::domain/ipv6]
|
||||||
:opt-un [::domain/echo ::domain/k3s-output-filename ::domain/k3s-provision-user])))
|
:opt-un [::domain/echo ::domain/k3s-output-filename ::domain/k3s-provision-user])))
|
||||||
|
|
||||||
|
@ -26,12 +26,6 @@
|
||||||
(i/execute! c config))))
|
(i/execute! c config))))
|
||||||
|
|
||||||
(defn-spec write-k3s-config! nil?
|
(defn-spec write-k3s-config! nil?
|
||||||
"Create a server config for provs using tf-out and write it to a file
|
|
||||||
|
|
||||||
Requires ':email' to be set, otherwise certs will not work
|
|
||||||
Default: out_k3sServerConfig.yaml
|
|
||||||
can be changed by adding another value for ':k3s-output-filename'
|
|
||||||
"
|
|
||||||
[devops ::provs
|
[devops ::provs
|
||||||
tf-out ::tg/tf-out]
|
tf-out ::tg/tf-out]
|
||||||
(let [config (merge default devops)
|
(let [config (merge default devops)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
@ -46,6 +48,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
|
@ -58,6 +61,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
@ -72,6 +76,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
|
@ -84,6 +89,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
@ -97,6 +103,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
@ -111,6 +118,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
@ -125,6 +133,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-input "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
|
:c4k-app-name "backup"
|
||||||
:k3s-output-filename "k3s-out.yaml"
|
:k3s-output-filename "k3s-out.yaml"
|
||||||
:k3s-provision-user "root"
|
:k3s-provision-user "root"
|
||||||
:c4k-config-input "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
|
|
Loading…
Add table
Reference in a new issue