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"]
|
||||
|
||||
: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"}
|
||||
aero/aero {:mvn/version "1.1.6"}
|
||||
org.domaindrivenarchitecture/c4k-common-clj {:mvn/version "8.0.1-SNAPSHOT"}
|
||||
|
|
|
@ -1,56 +1,59 @@
|
|||
(ns dda.build.c4k
|
||||
(:require [orchestra.core :refer [defn-spec]]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[cheshire.core :as cs]
|
||||
[dda.build.devops :as devops]
|
||||
[dda.build.terragrunt :as tg]
|
||||
[dda.build.config :as cfg]
|
||||
[dda.build.c4k.domain :as domain]
|
||||
[dda.build.infrastructure :as i]))
|
||||
|
||||
(st/instrument `clean-build-dir!)
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[dda.build.devops :as devops]
|
||||
[dda.build.terragrunt :as tg]
|
||||
[dda.build.config :as cfg]
|
||||
[dda.build.c4k.domain :as domain]
|
||||
[dda.build.infrastructure :as i]))
|
||||
|
||||
(def default
|
||||
(merge devops/default
|
||||
tf/default
|
||||
{:c4k-output "c4k-app.yaml"
|
||||
:c4k-config-input "c4k-config.edn"
|
||||
:c4k-auth-input "c4k-auth.edn"}))
|
||||
|
||||
(s/def ::c4k (s/merge
|
||||
(s/def ::c4k (s/merge
|
||||
::devops/devops
|
||||
::tg/tg
|
||||
(s/keys :opt-un [::domain/c4k-output ::domain/c4k-config-input ::domain/c4k-auth-input])))
|
||||
(s/keys :opt-un [::domain/c4k-output ::domain/c4k-config-input ::domain/c4k-auth-input ::domain/c4k-app-name])))
|
||||
|
||||
(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?
|
||||
[devops ::c4kg]
|
||||
(let [config (merge default devops)]
|
||||
[devops ::c4k]
|
||||
(let [config (default-cfg devops)]
|
||||
(i/execute! (domain/clean-build-dir-command config) config)))
|
||||
|
||||
(defn-spec run-c4k-jar! nil?
|
||||
[devops ::c4kg]
|
||||
(let [config (merge default devops)]
|
||||
(doseq [c (domain/c4k-uberjar-command config)]
|
||||
(i/execute! c config))))
|
||||
[devops ::c4k]
|
||||
(let [config (default-cfg devops)]
|
||||
(i/execute! (domain/c4k-uberjar-command config) config)))
|
||||
|
||||
(defn-spec run-c4k-bin! nil?
|
||||
[devops ::c4kg]
|
||||
(let [config (merge default devops)]
|
||||
[devops ::c4k]
|
||||
(let [config (default-cfg devops)]
|
||||
(doseq [c (domain/c4k-graalvm-command config)]
|
||||
(i/execute! c config))))
|
||||
|
||||
(defn-spec write-c4k-objects! nil?
|
||||
[devops ::c4kg
|
||||
tf-out ::tg-domain/tf-out]
|
||||
(let [config (merge default devops)
|
||||
{:keys [module c4k-auth-input c4k-config-input c4k-output]} config]
|
||||
[devops ::c4k
|
||||
tf-out ::tg/tf-out]
|
||||
(let [config (default-cfg devops)]
|
||||
(->> (cfg/read-config (domain/config-path config))
|
||||
(merge {:fqdn (:fqdn (:value (:out tf-out)))})
|
||||
(cs/generate-string)
|
||||
(pr-str)
|
||||
(spit (domain/config-path config)))
|
||||
(->> (cfg/read-config (domain/config-auth config))
|
||||
(cs/generate-string)
|
||||
(spit (domain/config-auth config))
|
||||
(->> (cfg/read-config (domain/auth-path config))
|
||||
(pr-str)
|
||||
(spit (domain/auth-path config)))
|
||||
(run-c4k-jar! config)))
|
||||
|
||||
(st/instrument `clean-build-dir!)
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
[orchestra.core :refer [defn-spec]]
|
||||
[dda.build.devops.domain :as d]))
|
||||
|
||||
(s/def ::c4k-app-name string?)
|
||||
(s/def ::c4k-output string?)
|
||||
(s/def ::c4k-config-input string?)
|
||||
(s/def ::c4k-auth-input string?)
|
||||
|
||||
(s/def ::config
|
||||
(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?
|
||||
[config ::config]
|
||||
|
@ -32,12 +33,12 @@
|
|||
|
||||
(defn-spec c4k-uberjar-command seq?
|
||||
[config ::config]
|
||||
(let [{:keys [module]} config
|
||||
executable-name (str "c4k-" module "-standalone.jar")]
|
||||
(let [{:keys [c4k-app-name]} config
|
||||
executable-name (str "c4k-" c4k-app-name "-standalone.jar")]
|
||||
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
||||
|
||||
(defn-spec c4k-graalvm-command seq?
|
||||
[config ::config]
|
||||
(let [{:keys [module]} config
|
||||
executable-name (str "c4k-" module)]
|
||||
(let [{:keys [c4k-app-name]} config
|
||||
executable-name (str "c4k-" c4k-app-name)]
|
||||
[["bash" "-c" (str executable-name " " (config-path config) " " (auth-path config) " > " (output-path config))]]))
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
(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]
|
||||
[dda.build.infrastructure :as i]))
|
||||
|
||||
|
@ -14,4 +9,9 @@
|
|||
|
||||
(defn read-config
|
||||
[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
|
||||
(:require
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[clojure.spec.alpha :as s]
|
||||
[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)
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[dda.build.devops.domain :as domain]
|
||||
[dda.build.infrastructure :as i]))
|
||||
|
||||
(s/def ::devops
|
||||
(s/keys :req-un [::name]
|
||||
:opt-un [::module ::stage ::project-root-path ::build-dir-name ::debug ::dry-run]))
|
||||
(s/keys :req-un [::domain/name]
|
||||
:opt-un [::domain/module ::domain/stage ::domain/project-root-path ::domain/build-dir-name ::domain/debug ::domain/dry-run]))
|
||||
|
||||
(def default {:name "dda-backup"
|
||||
:project-root-path "."
|
||||
|
@ -42,7 +34,3 @@
|
|||
[devops ::devops]
|
||||
(let [final (merge default devops)]
|
||||
(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
|
||||
(:require
|
||||
[clojure.string :as str]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[orchestra.core :refer [defn-spec]]))
|
||||
|
||||
(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
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[cheshire.core :refer [generate-string]]
|
||||
[dda.build.c4k :as c4k]
|
||||
[dda.build.terragrunt :as tg]
|
||||
[dda.build.provs.domain :as domain]
|
||||
[dda.build.infrastructure :as i]))
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.spec.test.alpha :as st]
|
||||
[orchestra.core :refer [defn-spec]]
|
||||
[cheshire.core :refer [generate-string]]
|
||||
[dda.build.c4k :as c4k]
|
||||
[dda.build.terragrunt :as tg]
|
||||
[dda.build.provs.domain :as domain]
|
||||
[dda.build.infrastructure :as i]))
|
||||
|
||||
(def default
|
||||
(merge c4k/default
|
||||
|
@ -14,7 +14,7 @@
|
|||
:k3s-provision-user "root"
|
||||
:echo false}))
|
||||
(s/def ::provs (s/merge ::c4k/c4k
|
||||
(s/keys
|
||||
(s/keys
|
||||
:req-un [::domain/email ::domain/fqdn ::domain/ipv4 ::domain/ipv6]
|
||||
:opt-un [::domain/echo ::domain/k3s-output-filename ::domain/k3s-provision-user])))
|
||||
|
||||
|
@ -26,12 +26,6 @@
|
|||
(i/execute! c config))))
|
||||
|
||||
(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
|
||||
tf-out ::tg/tf-out]
|
||||
(let [config (merge default devops)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"})))
|
||||
|
@ -33,6 +34,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
@ -46,6 +48,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"})))
|
||||
|
@ -58,6 +61,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
@ -72,6 +76,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"})))
|
||||
|
@ -84,6 +89,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
@ -97,6 +103,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
@ -111,6 +118,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
@ -125,6 +133,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:c4k-config-input "config.yaml"
|
||||
:c4k-auth-input "auth.yaml"
|
||||
:c4k-output "out.yaml"}))))
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
:stage "dev"
|
||||
:debug false
|
||||
:dry-run false
|
||||
:c4k-app-name "backup"
|
||||
:k3s-output-filename "k3s-out.yaml"
|
||||
:k3s-provision-user "root"
|
||||
:c4k-config-input "config.yaml"
|
||||
|
|
Loading…
Add table
Reference in a new issue