Compare commits
3 commits
1b91da0e3d
...
e0b5eb0ee3
Author | SHA1 | Date | |
---|---|---|---|
e0b5eb0ee3 | |||
ae5ccc60f1 | |||
0cbd256547 |
11 changed files with 110 additions and 23 deletions
2
deps.edn
2
deps.edn
|
@ -1,5 +1,5 @@
|
||||||
{:project {:name org.domaindrivenarchitecture/build
|
{:project {:name org.domaindrivenarchitecture/build
|
||||||
:version "0.1.0"}
|
:version "0.1.1-SNAPSHOT"}
|
||||||
|
|
||||||
:paths
|
:paths
|
||||||
["src" "resources"]
|
["src" "resources"]
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
(ns dda.build.devops
|
(ns dda.build.devops
|
||||||
(:require
|
(:require
|
||||||
|
[orchestra.core :refer [defn-spec]]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[dda.build.devops.domain :as domain]))
|
[dda.build.devops.domain :as domain]
|
||||||
|
[dda.build.infrastructure :as i]))
|
||||||
|
|
||||||
(s/def ::name ::domain/name)
|
(s/def ::name ::domain/name)
|
||||||
(s/def ::module ::domain/module)
|
(s/def ::module ::domain/module)
|
||||||
|
@ -11,9 +13,21 @@
|
||||||
|
|
||||||
(s/def ::devops
|
(s/def ::devops
|
||||||
(s/keys :req-un [::name]
|
(s/keys :req-un [::name]
|
||||||
:opt-un [::module ::stage ::project-root-path ::build-dir-name]))
|
:opt-un [::module ::stage ::project-root-path ::build-dir-name ::debug ::dry-run]))
|
||||||
|
|
||||||
(def default {:name "dda-backup"
|
(def default {:name "dda-backup"
|
||||||
:project-root-path "."
|
:project-root-path "."
|
||||||
:build-dir-name "target"
|
:build-dir-name "target"
|
||||||
:stage "dev"})
|
:stage "dev"
|
||||||
|
:debug false
|
||||||
|
:dry-run false})
|
||||||
|
|
||||||
|
(defn-spec clean-build-dir nil?
|
||||||
|
[devops ::devops]
|
||||||
|
(let [final (merge default devops)]
|
||||||
|
(i/execute (domain/clean-build-dir-command final) final)))
|
||||||
|
|
||||||
|
(defn-spec create-build-dir nil?
|
||||||
|
[devops ::devops]
|
||||||
|
(let [final (merge default devops)]
|
||||||
|
(i/execute (domain/create-build-dir-command final) final)))
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
(s/def ::stage string?)
|
(s/def ::stage string?)
|
||||||
(s/def ::project-root-path string?)
|
(s/def ::project-root-path string?)
|
||||||
(s/def ::build-dir-name string?)
|
(s/def ::build-dir-name string?)
|
||||||
|
(s/def ::debug boolean?)
|
||||||
|
(s/def ::dry-run boolean?)
|
||||||
|
|
||||||
(s/def ::devops
|
(s/def ::devops
|
||||||
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name]
|
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run]
|
||||||
:opt-un [::module]))
|
:opt-un [::module]))
|
||||||
|
|
||||||
(defn-spec build-path string?
|
(defn-spec build-path string?
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[babashka.tasks :as t]
|
[babashka.tasks :as t]
|
||||||
[dda.build.devops :as d]
|
[dda.build.devops :as d]
|
||||||
[dda.build.devops.domain :as dd]
|
|
||||||
[dda.build.image.domain :as domain]))
|
[dda.build.image.domain :as domain]))
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
|
@ -11,7 +10,7 @@
|
||||||
(defn-spec dbuild nil?
|
(defn-spec dbuild nil?
|
||||||
[devops ::d/devops]
|
[devops ::d/devops]
|
||||||
(let [final (merge default devops)]
|
(let [final (merge default devops)]
|
||||||
(apply t/shell (dd/clean-build-dir-command final))
|
(d/create-build-dir final)
|
||||||
(apply t/shell (dd/create-build-dir-command final))
|
(d/create-build-dir final)
|
||||||
(apply t/shell (domain/copy-image-command final))
|
(apply t/shell (domain/copy-image-command final))
|
||||||
(apply t/shell (domain/dbuild-command final))))
|
(apply t/shell (domain/dbuild-command final))))
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
(ns dda.build.image.domain
|
(ns dda.build.image.domain
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[orchestra.core :refer [defn-spec]]
|
|
||||||
[dda.build.devops.domain :as d]))
|
[dda.build.devops.domain :as d]))
|
||||||
|
|
||||||
(defn-spec copy-image-command seq?
|
(defn-spec copy-image-command seq?
|
||||||
|
|
13
src/dda/build/infrastructure.clj
Normal file
13
src/dda/build/infrastructure.clj
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
(ns dda.build.infrastructure
|
||||||
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
|
[babashka.tasks :as t]
|
||||||
|
[dda.build.devops.domain :as d]))
|
||||||
|
|
||||||
|
(defn-spec execute nil?
|
||||||
|
[command string?
|
||||||
|
devops ::d/devops]
|
||||||
|
(let [{:keys [dry-run debug]} devops]
|
||||||
|
(when debug
|
||||||
|
(println command))
|
||||||
|
(when-not dry-run
|
||||||
|
(apply t/shell command))))
|
|
@ -1,9 +1,8 @@
|
||||||
(ns dda.build.terragrunt
|
(ns dda.build.terragrunt
|
||||||
(:require [orchestra.core :refer [defn-spec]]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[babashka.tasks :as t]
|
|
||||||
[dda.build.devops :as d]
|
[dda.build.devops :as d]
|
||||||
[dda.build.devops.domain :as dd]
|
[dda.build.terragrunt.domain :as domain]
|
||||||
[dda.build.terragrunt.domain :as dterra]))
|
[dda.build.infrastructure :as i]))
|
||||||
|
|
||||||
(def default
|
(def default
|
||||||
(merge d/default {}))
|
(merge d/default {}))
|
||||||
|
@ -11,7 +10,7 @@
|
||||||
(defn-spec plan nil?
|
(defn-spec plan nil?
|
||||||
[devops ::d/devops]
|
[devops ::d/devops]
|
||||||
(let [final (merge default devops)]
|
(let [final (merge default devops)]
|
||||||
(apply t/shell (dd/clean-build-dir-command final))
|
(i/execute (domain/clean-build-dir-command final) final)
|
||||||
(apply t/shell (dd/create-build-dir-command final))
|
(d/create-build-dir final)
|
||||||
(apply t/shell (dterra/copy-terragrunt-command final))
|
(i/execute (domain/copy-terragrunt-command final) final)
|
||||||
(apply t/shell (dterra/plan-command final))))
|
))
|
||||||
|
|
17
src/dda/build/terragrunt/domain.clj
Normal file
17
src/dda/build/terragrunt/domain.clj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
(ns dda.build.terragrunt.domain
|
||||||
|
(:require [clojure.spec.alpha :as s]
|
||||||
|
[orchestra.core :refer [defn-spec]]
|
||||||
|
[dda.build.devops.domain :as d]))
|
||||||
|
|
||||||
|
(s/def ::devops
|
||||||
|
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name ::debug ::dry-run ::module]
|
||||||
|
:opt-un []))
|
||||||
|
|
||||||
|
(defn-spec clean-build-dir-command seq?
|
||||||
|
[devops ::devops]
|
||||||
|
["rm" "-rf" (d/build-path (dissoc devops :module))])
|
||||||
|
|
||||||
|
(defn-spec copy-terragrunt-command seq?
|
||||||
|
[devops ::devops]
|
||||||
|
(let [{:keys [module]} devops]
|
||||||
|
["cp" "." (d/build-path devops) "&&" "cp" module (d/build-path devops)]))
|
|
@ -13,14 +13,18 @@
|
||||||
: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
|
||||||
|
:dry-run false})))
|
||||||
(is (= "../../target/dda/backup"
|
(is (= "../../target/dda/backup"
|
||||||
(cut/build-path {:name "dda"
|
(cut/build-path {:name "dda"
|
||||||
:module "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
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
(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"]
|
||||||
|
@ -28,7 +32,9 @@
|
||||||
: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
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
(deftest should-calculate-create-build-dir-command
|
(deftest should-calculate-create-build-dir-command
|
||||||
(is (= ["mkdir" "-p" "../../target/dda-backup"]
|
(is (= ["mkdir" "-p" "../../target/dda-backup"]
|
||||||
|
@ -36,5 +42,7 @@
|
||||||
: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
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
: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
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
(deftest should-calculate-dbuild-command
|
(deftest should-calculate-dbuild-command
|
||||||
(is (= ["docker"
|
(is (= ["docker"
|
||||||
|
@ -28,5 +30,7 @@
|
||||||
: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
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
|
|
32
test/dda/build/terragrunt/domain_test.clj
Normal file
32
test/dda/build/terragrunt/domain_test.clj
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
(ns dda.build.terragrunt.domain-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
[clojure.spec.test.alpha :as st]
|
||||||
|
[dda.build.terragrunt.domain :as cut]))
|
||||||
|
|
||||||
|
(st/instrument `cut/clean-build-dir-command)
|
||||||
|
(st/instrument `cut/copy-terragrunt-command)
|
||||||
|
|
||||||
|
(deftest should-calculate-clean-build-dir-command
|
||||||
|
(is (= ["rm" "-rf" "../../target/test"]
|
||||||
|
(cut/clean-build-dir-command {:name "test"
|
||||||
|
:module "statistics"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"
|
||||||
|
:debug false
|
||||||
|
:dry-run false}))))
|
||||||
|
|
||||||
|
(deftest should-calculate-copy-terragrunt-command
|
||||||
|
(is (= ["cp" "." "../../target/test/statistics" "&&"
|
||||||
|
"cp" "statistics" "../../target/test/statistics"]
|
||||||
|
(cut/copy-terragrunt-command {:name "test"
|
||||||
|
:module "statistics"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"
|
||||||
|
:debug false
|
||||||
|
:dry-run false}))))
|
||||||
|
|
Loading…
Reference in a new issue