fix c4k
This commit is contained in:
parent
2932bcf5f8
commit
79ba8b75ff
7 changed files with 86 additions and 110 deletions
2
Makefile
2
Makefile
|
@ -62,7 +62,7 @@ install: build-jar
|
||||||
clojure -T:build install
|
clojure -T:build install
|
||||||
|
|
||||||
deploy: build-jar
|
deploy: build-jar
|
||||||
$(info --------- install library jar ---------)
|
$(info --------- deploy library jar ---------)
|
||||||
clojure -T:build deploy
|
clojure -T:build deploy
|
||||||
|
|
||||||
publish: build-jar
|
publish: build-jar
|
||||||
|
|
4
deps.edn
4
deps.edn
|
@ -5,9 +5,9 @@
|
||||||
["src" "resources"]
|
["src" "resources"]
|
||||||
|
|
||||||
:deps
|
:deps
|
||||||
{org.clojure/clojure {:mvn/version "1.11.4"}
|
{org.clojure/spec.alpha {:mvn/version "0.5.238"}
|
||||||
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"}
|
||||||
org.domaindrivenarchitecture/c4k-common-clj {:mvn/version "8.0.1-SNAPSHOT"}
|
org.domaindrivenarchitecture/c4k-common-clj {:mvn/version "8.0.1-SNAPSHOT"}
|
||||||
cheshire/cheshire {:mvn/version "5.13.0"}}
|
cheshire/cheshire {:mvn/version "5.13.0"}}
|
||||||
|
|
||||||
|
|
|
@ -1,83 +1,59 @@
|
||||||
(ns dda.build.c4k
|
(ns dda.build.c4k
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[clojure.spec.test.alpha :as st]
|
[clojure.spec.test.alpha :as st]
|
||||||
[cheshire.core :refer [parse-string generate-string]]
|
[cheshire.core :as cs]
|
||||||
[dda.build.devops :as d]
|
[dda.build.devops :as devops]
|
||||||
|
[dda.build.terragrunt :as tg]
|
||||||
|
[dda.build.config :as cfg]
|
||||||
[dda.build.c4k.domain :as domain]
|
[dda.build.c4k.domain :as domain]
|
||||||
[dda.build.terragrunt.domain :as tg-domain]
|
|
||||||
[dda.build.infrastructure :as i]))
|
[dda.build.infrastructure :as i]))
|
||||||
|
|
||||||
(st/instrument `clean-build-dir!)
|
(st/instrument `clean-build-dir!)
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
(merge d/default {:autoapply false
|
(merge devops/default
|
||||||
:c4k-output-filename "c4k-app.yaml"
|
tf/default
|
||||||
:c4k-config-filename "c4k-config.yaml"
|
{:c4k-output "c4k-app.yaml"
|
||||||
:c4k-auth-filename "c4k-auth.yaml"}))
|
:c4k-config-input "c4k-config.edn"
|
||||||
|
:c4k-auth-input "c4k-auth.edn"}))
|
||||||
|
|
||||||
|
(s/def ::c4k (s/merge
|
||||||
|
::devops/devops
|
||||||
|
::tg/tg
|
||||||
|
(s/keys :opt-un [::domain/c4k-output ::domain/c4k-config-input ::domain/c4k-auth-input])))
|
||||||
|
|
||||||
(defn-spec clean-build-dir! nil?
|
(defn-spec clean-build-dir! nil?
|
||||||
[devops ::d/devops]
|
[devops ::c4kg]
|
||||||
(let [config (merge default devops)]
|
(let [config (merge default 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 ::d/devops]
|
[devops ::c4kg]
|
||||||
(let [config (merge default devops)]
|
(let [config (merge default devops)]
|
||||||
(doseq [c (domain/c4k-uberjar-command config)]
|
(doseq [c (domain/c4k-uberjar-command config)]
|
||||||
(i/execute! c config))))
|
(i/execute! c config))))
|
||||||
|
|
||||||
(defn-spec run-c4k-executable! nil?
|
(defn-spec run-c4k-bin! nil?
|
||||||
[devops ::d/devops]
|
[devops ::c4kg]
|
||||||
(let [config (merge default devops)]
|
(let [config (merge default devops)]
|
||||||
(doseq [c (domain/c4k-graalvm-command config)]
|
(doseq [c (domain/c4k-graalvm-command config)]
|
||||||
(i/execute! c config))))
|
(i/execute! c config))))
|
||||||
|
|
||||||
; TODO: Generate functions assume that files have already been copied,
|
(defn-spec write-c4k-objects! nil?
|
||||||
; which will happen if this is run after terragrunt
|
[devops ::c4kg
|
||||||
; but it is not guaranteed
|
|
||||||
(defn-spec generate-jar! nil?
|
|
||||||
"Generates c4k app yaml using 'c4k-{module}-standalone.jar'
|
|
||||||
Stores the result in 'c4k-app.yaml'
|
|
||||||
|
|
||||||
Defaults: c4k-config.yaml c4k-auth.yaml c4k-app.yaml
|
|
||||||
can be changed by adding another value for ':c4k-config-filename', ':c4k-auth-filename', ':c4k-output-filename'
|
|
||||||
"
|
|
||||||
[devops ::d/devops]
|
|
||||||
(let [config (merge default devops)]
|
|
||||||
(run-c4k-jar! config)))
|
|
||||||
|
|
||||||
(defn-spec generate! nil?
|
|
||||||
"Generates c4k app yaml using 'c4k-{module}' (graalvm executable)
|
|
||||||
Stores the result in 'c4k-app.yaml'
|
|
||||||
|
|
||||||
Defaults: c4k-config.yaml c4k-auth.yaml c4k-app.yaml
|
|
||||||
can be changed by adding another value for ':c4k-config-filename', ':c4k-auth-filename', ':c4k-output-filename'
|
|
||||||
"
|
|
||||||
[devops ::d/devops]
|
|
||||||
(let [config (merge default devops)]
|
|
||||||
(run-c4k-executable! config)))
|
|
||||||
|
|
||||||
(defn-spec insert-tf-out! nil?
|
|
||||||
"Inserts relevant values from the tf output into the c4k config
|
|
||||||
|
|
||||||
Default: c4k-config.yaml
|
|
||||||
can be changed by adding another value for ':c4k-config-filename'
|
|
||||||
"
|
|
||||||
[devops ::d/devops
|
|
||||||
tf-out ::tg-domain/tf-out]
|
tf-out ::tg-domain/tf-out]
|
||||||
(let [config (merge default devops)
|
(let [config (merge default devops)
|
||||||
default-c4k-config (parse-string (slurp (domain/config-path config))
|
{:keys [module c4k-auth-input c4k-config-input c4k-output]} config]
|
||||||
(fn [k] (keyword (.toLowerCase k))))
|
(->> (cfg/read-config (domain/config-path config))
|
||||||
tf-out-c4k-config (domain/create-c4k-config config tf-out)]
|
(merge {:fqdn (:fqdn (:value (:out tf-out)))})
|
||||||
(->> default-c4k-config
|
(cs/generate-string)
|
||||||
(merge tf-out-c4k-config)
|
(spit (domain/config-path config)))
|
||||||
(generate-string)
|
(->> (cfg/read-config (domain/config-auth config))
|
||||||
(spit (domain/config-path config)))))
|
(cs/generate-string)
|
||||||
|
(spit (domain/config-auth config))
|
||||||
|
(run-c4k-jar! config)))
|
||||||
|
|
||||||
(st/instrument `clean-build-dir!)
|
(st/instrument `clean-build-dir!)
|
||||||
(st/instrument `run-c4k-jar!)
|
(st/instrument `run-c4k-jar!)
|
||||||
(st/instrument `run-c4k-executable!)
|
(st/instrument `run-c4k-bin!)
|
||||||
(st/instrument `generate-jar!)
|
(st/instrument `write-c4k-objects!)
|
||||||
(st/instrument `generate!)
|
|
||||||
(st/instrument `insert-tf-out!)
|
|
||||||
|
|
|
@ -1,32 +1,30 @@
|
||||||
(ns dda.build.c4k.domain
|
(ns dda.build.c4k.domain
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [clojure.spec.alpha :as s]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[dda.build.devops.domain :as d]
|
[dda.build.devops.domain :as d]))
|
||||||
[dda.build.terragrunt.domain :as td]))
|
|
||||||
|
|
||||||
(s/def ::c4k-output-filename string?)
|
(s/def ::c4k-output string?)
|
||||||
(s/def ::c4k-config-filename string?)
|
(s/def ::c4k-config-input string?)
|
||||||
(s/def ::c4k-auth-filename string?)
|
(s/def ::c4k-auth-input string?)
|
||||||
|
|
||||||
(s/def ::config
|
(s/def ::config
|
||||||
(s/keys :req-un [::d/name ::d/stage ::d/project-root-path ::d/build-dir-name ::d/debug
|
(s/merge ::d/devops
|
||||||
::d/dry-run ::c4k-output-filename ::c4k-config-filename ::c4k-auth-filename]
|
(s/keys :req-un [::c4k-output ::c4k-config-input ::c4k-auth-input])))
|
||||||
:opt-un [::d/module]))
|
|
||||||
|
|
||||||
(defn-spec config-path string?
|
(defn-spec config-path string?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
(let [{:keys [c4k-config-filename]} config]
|
(let [{:keys [c4k-config-input]} config]
|
||||||
(str (d/build-path config) "/" c4k-config-filename)))
|
(str (d/build-path config) "/" c4k-config-input)))
|
||||||
|
|
||||||
(defn-spec auth-path string?
|
(defn-spec auth-path string?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
(let [{:keys [c4k-auth-filename]} config]
|
(let [{:keys [c4k-auth-input]} config]
|
||||||
(str (d/build-path config) "/" c4k-auth-filename)))
|
(str (d/build-path config) "/" c4k-auth-input)))
|
||||||
|
|
||||||
(defn-spec output-path string?
|
(defn-spec output-path string?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
(let [{:keys [c4k-output-filename]} config]
|
(let [{:keys [c4k-output]} config]
|
||||||
(str (d/build-path config) "/" c4k-output-filename)))
|
(str (d/build-path config) "/" c4k-output)))
|
||||||
|
|
||||||
(defn-spec clean-build-dir-command seq?
|
(defn-spec clean-build-dir-command seq?
|
||||||
[config ::config]
|
[config ::config]
|
||||||
|
@ -43,11 +41,3 @@
|
||||||
(let [{:keys [module]} config
|
(let [{:keys [module]} config
|
||||||
executable-name (str "c4k-" module)]
|
executable-name (str "c4k-" module)]
|
||||||
[["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 create-c4k-config map?
|
|
||||||
[config ::config
|
|
||||||
tf-out ::td/tf-out]
|
|
||||||
(let [{:keys [stage]} config
|
|
||||||
issuer (if (= stage "prod") "prod" "staging")
|
|
||||||
fqdn (:fqdn (:value (:out tf-out)))]
|
|
||||||
{:issuer issuer :fqdn fqdn}))
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[clojure.spec.test.alpha :as st]
|
[clojure.spec.test.alpha :as st]
|
||||||
[cheshire.core :refer [parse-string generate-string]]
|
[cheshire.core :refer [parse-string generate-string]]
|
||||||
|
[aero.core :refer :as aero]
|
||||||
[dda.build.devops :as d]
|
[dda.build.devops :as d]
|
||||||
[dda.build.gopass.domain :as domain]
|
[dda.build.gopass.domain :as domain]
|
||||||
[dda.build.c4k.domain :as c4k-d]
|
[dda.build.c4k.domain :as c4k-d]
|
||||||
|
@ -45,6 +46,13 @@
|
||||||
(generate-string)
|
(generate-string)
|
||||||
(spit (c4k-d/auth-path config)))))
|
(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 `run-gopass-command!)
|
||||||
(st/instrument `resolve-gopass!)
|
(st/instrument `resolve-gopass!)
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
(is (= "../../target/dda/backup/config.yaml"
|
(is (= "../../target/dda/backup/config.yaml"
|
||||||
(cut/config-path {:name "dda"
|
(cut/config-path {:name "dda"
|
||||||
:module "backup"
|
:module "backup"
|
||||||
|
@ -33,9 +33,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
(deftest should-calculate-auth-path
|
(deftest should-calculate-auth-path
|
||||||
(is (= "../../target/dda-backup/auth.yaml"
|
(is (= "../../target/dda-backup/auth.yaml"
|
||||||
|
@ -46,9 +46,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
(is (= "../../target/dda/backup/auth.yaml"
|
(is (= "../../target/dda/backup/auth.yaml"
|
||||||
(cut/auth-path {:name "dda"
|
(cut/auth-path {:name "dda"
|
||||||
:module "backup"
|
:module "backup"
|
||||||
|
@ -58,9 +58,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
|
|
||||||
(deftest should-calculate-output-path
|
(deftest should-calculate-output-path
|
||||||
|
@ -72,9 +72,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"})))
|
:c4k-output "out.yaml"})))
|
||||||
(is (= "../../target/dda/backup/out.yaml"
|
(is (= "../../target/dda/backup/out.yaml"
|
||||||
(cut/output-path {:name "dda"
|
(cut/output-path {:name "dda"
|
||||||
:module "backup"
|
:module "backup"
|
||||||
|
@ -84,9 +84,9 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
(deftest should-calculate-clean-build-dir-command
|
(deftest should-calculate-clean-build-dir-command
|
||||||
(is (= ["rm" "-rf" "../../target/dda-backup"]
|
(is (= ["rm" "-rf" "../../target/dda-backup"]
|
||||||
|
@ -97,33 +97,35 @@
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
(deftest should-calculate-c4k-uberjar-command
|
(deftest should-calculate-c4k-uberjar-command
|
||||||
(is (= ["bash" "-c" "c4k-dda-backup-standalone.jar ../../target/dda-backup/config.yaml ../../target/dda-backup/auth.yaml > ../../target/dda-backup/out.yaml"]
|
(is (= [["bash" "-c" "c4k-backup-standalone.jar ../../target/dda-backup/backup/config.yaml ../../target/dda-backup/backup/auth.yaml > ../../target/dda-backup/backup/out.yaml"]]
|
||||||
(cut/c4k-uberjar-command {:name "dda-backup"
|
(cut/c4k-uberjar-command {:name "dda-backup"
|
||||||
|
:module "backup"
|
||||||
:project-root-path "../.."
|
:project-root-path "../.."
|
||||||
:build-dir-name "target"
|
:build-dir-name "target"
|
||||||
:version "4.11.8-dev"
|
:version "4.11.8-dev"
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
(deftest should-calculate-c4k-graalvm-command
|
(deftest should-calculate-c4k-graalvm-command
|
||||||
(is (= ["bash" "-c" "c4k-dda-backup ../../target/dda-backup/config.yaml ../../target/dda-backup/auth.yaml > ../../target/dda-backup/out.yaml"]
|
(is (= [["bash" "-c" "c4k-backup ../../target/dda-backup/backup/config.yaml ../../target/dda-backup/backup/auth.yaml > ../../target/dda-backup/backup/out.yaml"]]
|
||||||
(cut/c4k-graalvm-command {:name "dda-backup"
|
(cut/c4k-graalvm-command {:name "dda-backup"
|
||||||
|
:module "backup"
|
||||||
:project-root-path "../.."
|
:project-root-path "../.."
|
||||||
:build-dir-name "target"
|
:build-dir-name "target"
|
||||||
:version "4.11.8-dev"
|
:version "4.11.8-dev"
|
||||||
:stage "dev"
|
:stage "dev"
|
||||||
:debug false
|
:debug false
|
||||||
:dry-run false
|
:dry-run false
|
||||||
:c4k-config-filename "config.yaml"
|
:c4k-config-input "config.yaml"
|
||||||
:c4k-auth-filename "auth.yaml"
|
:c4k-auth-input "auth.yaml"
|
||||||
:c4k-output-filename "out.yaml"}))))
|
:c4k-output "out.yaml"}))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue