Compare commits
9 commits
main
...
clj-bb-rew
Author | SHA1 | Date | |
---|---|---|---|
9c9fd4ace6 | |||
00219a8e38 | |||
47d7e9050a | |||
7ea24fffb5 | |||
10bf635cdf | |||
0311d68371 | |||
198713c229 | |||
e9262382c4 | |||
52db785f8b |
17 changed files with 334 additions and 0 deletions
5
.bashrc
Normal file
5
.bashrc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
_bb_tasks() {
|
||||||
|
COMPREPLY=( $(compgen -W "$(bb tasks |tail -n +3 |cut -f1 -d ' ')" -- ${COMP_WORDS[COMP_CWORD]}) );
|
||||||
|
}
|
||||||
|
# autocomplete filenames as well
|
||||||
|
complete -f -F _bb_tasks bb
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -109,3 +109,5 @@ venv.bak/
|
||||||
|
|
||||||
.clj-kondo/
|
.clj-kondo/
|
||||||
.lsp/
|
.lsp/
|
||||||
|
.calva
|
||||||
|
.cpcache
|
||||||
|
|
12
bb.edn
Normal file
12
bb.edn
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{:deps {dda/dda-devops-build {:local/root "."}}
|
||||||
|
:tasks
|
||||||
|
{test
|
||||||
|
{:extra-paths ["src/test/clj"]
|
||||||
|
:extra-deps {io.github.cognitect-labs/test-runner
|
||||||
|
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
|
||||||
|
:task (exec 'cognitect.test-runner.api/test)
|
||||||
|
:exec-args {:dirs ["src/test/clj"]}
|
||||||
|
:org.babashka/cli {:coerce {:nses [:symbol]
|
||||||
|
:vars [:symbol]}}}
|
||||||
|
publish
|
||||||
|
{:task (clojure "-T:build deploy")}}}
|
8
deps.edn
Normal file
8
deps.edn
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{:paths ["src/main/clj"]
|
||||||
|
:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"}
|
||||||
|
orchestra/orchestra {:mvn/version "2021.01.01-1"}}
|
||||||
|
:aliases
|
||||||
|
{:build {:extra-paths ["src/tools/clj"]
|
||||||
|
:deps {io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"}
|
||||||
|
slipset/deps-deploy {:mvn/version "0.2.0"}}
|
||||||
|
:ns-default build}}}
|
5
doc/dev/clj_setup.md
Normal file
5
doc/dev/clj_setup.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
1. Install babashka
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
`bb test`
|
8
infrastructure/backup/bb.edn
Normal file
8
infrastructure/backup/bb.edn
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{:deps {dda/dda-devops-build {:local/root "../../."}}
|
||||||
|
:tasks
|
||||||
|
{:requires ([dda.devops-build.image :as image])
|
||||||
|
image-build (image/dbuild {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"})}}
|
||||||
|
|
19
src/main/clj/dda/devops_build/devops.clj
Normal file
19
src/main/clj/dda/devops_build/devops.clj
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
(ns dda.devops-build.devops
|
||||||
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[dda.devops-build.devops.domain :as domain]))
|
||||||
|
|
||||||
|
(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/keys :req-un [::name]
|
||||||
|
:opt-un [::module ::stage ::project-root-path ::build-dir-name]))
|
||||||
|
|
||||||
|
(def default {:name "dda-backup"
|
||||||
|
:project-root-path "."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:stage "dev"})
|
35
src/main/clj/dda/devops_build/devops/domain.clj
Normal file
35
src/main/clj/dda/devops_build/devops/domain.clj
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
(ns dda.devops-build.devops.domain
|
||||||
|
(:require
|
||||||
|
[clojure.string :as str]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[orchestra.core :refer [defn-spec]]))
|
||||||
|
|
||||||
|
(s/def ::name string?)
|
||||||
|
(s/def ::module string?)
|
||||||
|
(s/def ::stage string?)
|
||||||
|
(s/def ::project-root-path string?)
|
||||||
|
(s/def ::build-dir-name string?)
|
||||||
|
|
||||||
|
(s/def ::devops
|
||||||
|
(s/keys :req-un [::name ::stage ::project-root-path ::build-dir-name]
|
||||||
|
:opt-un [::module]))
|
||||||
|
|
||||||
|
(defn-spec build-path string?
|
||||||
|
[devops ::devops]
|
||||||
|
(let
|
||||||
|
[{:keys [project-root-path build-dir-name name module]} devops]
|
||||||
|
(str/join
|
||||||
|
"/"
|
||||||
|
(filter
|
||||||
|
some?
|
||||||
|
[project-root-path build-dir-name name module]))))
|
||||||
|
|
||||||
|
(defn-spec clean-build-dir-command seq?
|
||||||
|
[devops ::devops]
|
||||||
|
(let [{:keys [name]} devops]
|
||||||
|
["rm" "-rf" (build-path devops)]))
|
||||||
|
|
||||||
|
(defn-spec create-build-dir-command seq?
|
||||||
|
[devops ::devops]
|
||||||
|
(let [{:keys [name]} devops]
|
||||||
|
["mkdir" "-p" (build-path devops)]))
|
17
src/main/clj/dda/devops_build/image.clj
Normal file
17
src/main/clj/dda/devops_build/image.clj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
(ns dda.devops-build.image
|
||||||
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
|
[babashka.tasks :as t]
|
||||||
|
[dda.devops-build.devops :as d]
|
||||||
|
[dda.devops-build.devops.domain :as dd]
|
||||||
|
[dda.devops-build.image.domain :as domain]))
|
||||||
|
|
||||||
|
(def default
|
||||||
|
(merge d/default {}))
|
||||||
|
|
||||||
|
(defn-spec dbuild nil?
|
||||||
|
[devops ::d/devops]
|
||||||
|
(let [final (merge default devops)]
|
||||||
|
(apply t/shell (dd/clean-build-dir-command final))
|
||||||
|
(apply t/shell (dd/create-build-dir-command final))
|
||||||
|
(apply t/shell (domain/copy-image-command final))
|
||||||
|
(apply t/shell (domain/dbuild-command final))))
|
16
src/main/clj/dda/devops_build/image/domain.clj
Normal file
16
src/main/clj/dda/devops_build/image/domain.clj
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
(ns dda.devops-build.image.domain
|
||||||
|
(:require [clojure.spec.alpha :as s]
|
||||||
|
[orchestra.core :refer [defn-spec]]
|
||||||
|
[dda.devops-build.devops.domain :as d]))
|
||||||
|
|
||||||
|
(defn-spec copy-image-command seq?
|
||||||
|
[devops ::d/devops]
|
||||||
|
(let [{:keys [name]} devops]
|
||||||
|
["cp" "-r" "image" (d/build-path devops)]))
|
||||||
|
|
||||||
|
(defn-spec dbuild-command seq?
|
||||||
|
[devops ::d/devops]
|
||||||
|
(let [{:keys [name]} devops]
|
||||||
|
["docker" "build" "-t" name "--file"
|
||||||
|
(str (d/build-path devops) "/image/Dockerfile")
|
||||||
|
(str (d/build-path devops) "/image")]))
|
17
src/main/clj/dda/devops_build/terragrunt.clj
Normal file
17
src/main/clj/dda/devops_build/terragrunt.clj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
(ns dda.devops-build.image
|
||||||
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
|
[babashka.tasks :as t]
|
||||||
|
[dda.devops-build.devops :as d]
|
||||||
|
[dda.devops-build.devops.domain :as dd]
|
||||||
|
[dda.devops-build.terragrunt.domain :as dterra]))
|
||||||
|
|
||||||
|
(def default
|
||||||
|
(merge d/default {}))
|
||||||
|
|
||||||
|
(defn-spec plan nil?
|
||||||
|
[devops ::d/devops]
|
||||||
|
(let [final (merge default devops)]
|
||||||
|
(apply t/shell (dd/clean-build-dir-command final))
|
||||||
|
(apply t/shell (dd/create-build-dir-command final))
|
||||||
|
(apply t/shell (dterra/copy-terragrunt-command final))
|
||||||
|
(apply t/shell (dterra/plan-command final))))
|
40
src/test/clj/dda/devops_build/devops/domain_test.clj
Normal file
40
src/test/clj/dda/devops_build/devops/domain_test.clj
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
(ns dda.devops-build.devops.domain-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
[clojure.spec.test.alpha :as st]
|
||||||
|
[dda.devops-build.devops.domain :as cut]))
|
||||||
|
|
||||||
|
(st/instrument `cut/build-path)
|
||||||
|
(st/instrument `cut/create-build-dir-command)
|
||||||
|
|
||||||
|
(deftest should-calculate-build-path
|
||||||
|
(is (= "../../target/dda-backup"
|
||||||
|
(cut/build-path {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"})))
|
||||||
|
(is (= "../../target/dda/backup"
|
||||||
|
(cut/build-path {:name "dda"
|
||||||
|
:module "backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"}))))
|
||||||
|
|
||||||
|
(deftest should-calculate-clean-build-dir-command
|
||||||
|
(is (= ["rm" "-rf" "../../target/dda-backup"]
|
||||||
|
(cut/clean-build-dir-command {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"}))))
|
||||||
|
|
||||||
|
(deftest should-calculate-create-build-dir-command
|
||||||
|
(is (= ["mkdir" "-p" "../../target/dda-backup"]
|
||||||
|
(cut/create-build-dir-command {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"}))))
|
||||||
|
|
32
src/test/clj/dda/devops_build/image/domain_test.clj
Normal file
32
src/test/clj/dda/devops_build/image/domain_test.clj
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
(ns dda.devops-build.image.domain-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
[clojure.spec.test.alpha :as st]
|
||||||
|
[dda.devops-build.image.domain :as cut]))
|
||||||
|
|
||||||
|
(st/instrument `cut/copy-image-command)
|
||||||
|
(st/instrument `cut/dbuild-command)
|
||||||
|
|
||||||
|
|
||||||
|
(deftest should-calculate-copy-image-command
|
||||||
|
(is (= ["cp" "-r" "image" "../../target/dda-backup"]
|
||||||
|
(cut/copy-image-command {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"}))))
|
||||||
|
|
||||||
|
(deftest should-calculate-dbuild-command
|
||||||
|
(is (= ["docker"
|
||||||
|
"build"
|
||||||
|
"-t"
|
||||||
|
"dda-backup"
|
||||||
|
"--file"
|
||||||
|
"../../target/dda-backup/image/Dockerfile"
|
||||||
|
"../../target/dda-backup/image"]
|
||||||
|
(cut/dbuild-command {:name "dda-backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-dev"
|
||||||
|
:stage "dev"}))))
|
||||||
|
|
64
src/tools/clj/build.clj
Normal file
64
src/tools/clj/build.clj
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
(ns build
|
||||||
|
(:require [clojure.tools.build.api :as b]
|
||||||
|
[clojure.edn :as edn]))
|
||||||
|
|
||||||
|
(def project (-> (edn/read-string (slurp "deps.edn"))
|
||||||
|
:aliases :neil :project))
|
||||||
|
(def lib (or (:name project) 'my/lib1))
|
||||||
|
|
||||||
|
;; use neil project set version 1.2.0 to update the version in deps.edn
|
||||||
|
|
||||||
|
(def version (or (:version project)
|
||||||
|
"1.2.0"))
|
||||||
|
(def class-dir "target/classes")
|
||||||
|
(def basis (b/create-basis {:project "deps.edn"}))
|
||||||
|
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))
|
||||||
|
(def jar-file (format "target/%s-%s.jar" (name lib) version))
|
||||||
|
|
||||||
|
(defn clean [_]
|
||||||
|
(b/delete {:path "target"}))
|
||||||
|
|
||||||
|
(defn jar [_]
|
||||||
|
(b/write-pom {:class-dir class-dir
|
||||||
|
:lib lib
|
||||||
|
:version version
|
||||||
|
:basis basis
|
||||||
|
:src-dirs ["src"]
|
||||||
|
:pom-data
|
||||||
|
[[:licenses
|
||||||
|
[:license
|
||||||
|
[:name "MIT License"]
|
||||||
|
[:url "https://opensource.org/license/mit/"]]]]})
|
||||||
|
(b/copy-dir {:src-dirs ["src" "resources"]
|
||||||
|
:target-dir class-dir})
|
||||||
|
(b/jar {:class-dir class-dir
|
||||||
|
:jar-file jar-file}))
|
||||||
|
|
||||||
|
(defn install [_]
|
||||||
|
(jar {})
|
||||||
|
(b/install {:basis basis
|
||||||
|
:lib lib
|
||||||
|
:version version
|
||||||
|
:jar-file jar-file
|
||||||
|
:class-dir class-dir}))
|
||||||
|
|
||||||
|
(defn uber [_]
|
||||||
|
(clean nil)
|
||||||
|
(b/copy-dir {:src-dirs ["src" "resources"]
|
||||||
|
:target-dir class-dir})
|
||||||
|
(b/compile-clj {:basis basis
|
||||||
|
:src-dirs ["src"]
|
||||||
|
:class-dir class-dir})
|
||||||
|
(b/uber {:class-dir class-dir
|
||||||
|
:uber-file uber-file
|
||||||
|
:basis basis}))
|
||||||
|
|
||||||
|
(defn deploy [opts]
|
||||||
|
(clean opts)
|
||||||
|
(jar opts)
|
||||||
|
((requiring-resolve 'deps-deploy.deps-deploy/deploy)
|
||||||
|
(merge {:installer :remote
|
||||||
|
:artifact jar-file
|
||||||
|
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
|
||||||
|
opts))
|
||||||
|
opts)
|
1
src/tools/clj/deps.edn
Normal file
1
src/tools/clj/deps.edn
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{:deps {}}
|
15
src/tools/clj/test-runner.clj
Normal file
15
src/tools/clj/test-runner.clj
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(require '[clojure.test :as t]
|
||||||
|
'[babashka.classpath :as cp])
|
||||||
|
|
||||||
|
(cp/add-classpath "src:test")
|
||||||
|
|
||||||
|
(require 'your.test-a 'your.test-b)
|
||||||
|
|
||||||
|
(def test-results
|
||||||
|
(t/run-tests 'your.test-a 'your.test-b))
|
||||||
|
|
||||||
|
(let [{:keys [fail error]} test-results]
|
||||||
|
(when (pos? (+ fail error))
|
||||||
|
(System/exit 1)))
|
38
tests.edn
Normal file
38
tests.edn
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#kaocha/v1
|
||||||
|
{:kaocha/tests
|
||||||
|
[{:kaocha.testable/id :unit
|
||||||
|
:kaocha.testable/type :kaocha.type/clojure.test
|
||||||
|
:kaocha/ns-patterns ["-test$"],
|
||||||
|
:kaocha/source-paths ["src/test/clj" "src/test/cljc"],
|
||||||
|
:kaocha/test-paths ["src/test/clj" "src/test/cljc"],
|
||||||
|
:kaocha.filter/skip-meta [:kaocha/skip]}
|
||||||
|
|
||||||
|
{:kaocha.testable/id :generative-fdef-checks
|
||||||
|
:kaocha.testable/type :kaocha.type/spec.test.check
|
||||||
|
:kaocha/source-paths ["src/main/clj" "src/main/cljc"]
|
||||||
|
:kaocha.spec.test.check/checks [{:kaocha.spec.test.check/syms :all-fdefs
|
||||||
|
:clojure.spec.test.check/instrument? true
|
||||||
|
:clojure.spec.test.check/check-asserts? true
|
||||||
|
:clojure.spec.test.check/opts {:num-tests 10}}]}
|
||||||
|
]
|
||||||
|
|
||||||
|
:kaocha/reporter [kaocha.report/documentation]
|
||||||
|
|
||||||
|
:kaocha/color? #profile {:default true
|
||||||
|
:ci false}
|
||||||
|
|
||||||
|
;; Run tests of file changes, unless running in CI server
|
||||||
|
:kaocha/watch #profile {:default true :ci false}
|
||||||
|
|
||||||
|
:kaocha/fail-fast? true
|
||||||
|
|
||||||
|
:kaocha.plugin.randomize/randomize? false
|
||||||
|
|
||||||
|
:kaocha/plugins
|
||||||
|
[:kaocha.plugin/randomize
|
||||||
|
:kaocha.plugin/filter
|
||||||
|
:kaocha.plugin/capture-output
|
||||||
|
:kaocha.plugin.alpha/spec-test-check]
|
||||||
|
|
||||||
|
:kaocha.plugin.capture-output/capture-output? true
|
||||||
|
}
|
Loading…
Reference in a new issue