first results for dbuild
This commit is contained in:
parent
198713c229
commit
0311d68371
9 changed files with 151 additions and 31 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -109,3 +109,5 @@ venv.bak/
|
||||||
|
|
||||||
.clj-kondo/
|
.clj-kondo/
|
||||||
.lsp/
|
.lsp/
|
||||||
|
.calva
|
||||||
|
.cpcache
|
||||||
|
|
6
deps.edn
6
deps.edn
|
@ -1,3 +1,7 @@
|
||||||
{:paths ["src/main/clj"]
|
{:paths ["src/main/clj"]
|
||||||
:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"}
|
:deps {org.clojure/spec.alpha {:mvn/version "0.4.233"}
|
||||||
orchestra {:mvn/version "2021.01.01-1"}}}
|
orchestra {:mvn/version "2021.01.01-1"}}
|
||||||
|
:aliases
|
||||||
|
{:test/env
|
||||||
|
{:extra-paths ["src/test/clj"]
|
||||||
|
:extra-deps {}}}}
|
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"})}}
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
(ns dda.devops-build.devops
|
(ns dda.devops-build.devops
|
||||||
(:require [clojure.spec.alpha :as s]))
|
(:require
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
|
[dda.devops-build.devops.domain :as domain]))
|
||||||
|
|
||||||
(s/def ::name string?)
|
(s/def ::name ::domain/name)
|
||||||
(s/def ::module string?)
|
(s/def ::module ::domain/module)
|
||||||
(s/def ::stage string?)
|
(s/def ::stage ::domain/stage)
|
||||||
(s/def ::project-root-path string?)
|
(s/def ::project-root-path ::domain/project-root-path)
|
||||||
(s/def ::build-dir-name string?)
|
(s/def ::build-dir-name ::domain/build-dir-name)
|
||||||
|
|
||||||
(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]))
|
||||||
|
|
||||||
|
(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)]))
|
|
@ -1,28 +1,18 @@
|
||||||
(ns dda.devops-build.image
|
(ns dda.devops-build.image
|
||||||
(:require [clojure.spec.alpha :as s]
|
(:require [orchestra.core :refer [defn-spec]]
|
||||||
[babashka.process :as p]
|
|
||||||
[babashka.tasks :as t]
|
[babashka.tasks :as t]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[clojure.string :as str]
|
||||||
[dda.devops-build.devops :as d]))
|
[dda.devops-build.devops :as d]
|
||||||
|
[dda.devops-build.devops.domain :as dd]
|
||||||
|
[dda.devops-build.image.domain :as domain]))
|
||||||
|
|
||||||
(s/def ::options (s/* #{"-h"}))
|
(def default
|
||||||
(s/def ::cmd-args (s/cat :options ::options
|
(merge d/default {}))
|
||||||
:args any?))
|
|
||||||
|
|
||||||
(defn invalid-args-msg
|
(defn-spec dbuild nil?
|
||||||
[spec args]
|
|
||||||
(s/explain spec args)
|
|
||||||
(println (str "Bad commandline arguments\n")))
|
|
||||||
|
|
||||||
(defn-spec
|
|
||||||
dbuild any?
|
|
||||||
[devops ::d/devops]
|
[devops ::d/devops]
|
||||||
(let [{:keys [name]} devops]
|
(let [final (merge default devops)]
|
||||||
(t/shell "echo 'docker" "build" "-t" name "--file" "{path}/image/Dockerfile" "{path}/image")))
|
(apply t/shell (dd/clean-build-dir-command final))
|
||||||
|
(apply t/shell (dd/create-build-dir-command final))
|
||||||
(defn drun [& cmd-args]
|
(apply t/shell (domain/copy-image-command final))
|
||||||
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
|
(apply t/shell (domain/dbuild-command final))))
|
||||||
(if (= ::s/invalid parsed-args-cmd)
|
|
||||||
(invalid-args-msg ::cmd-args cmd-args)
|
|
||||||
(-> (p/process "docker run" "-it" "{name}" "/bin/bash")
|
|
||||||
(p/check)))))
|
|
||||||
|
|
17
src/main/clj/dda/devops_build/image/domain.clj
Normal file
17
src/main/clj/dda/devops_build/image/domain.clj
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
(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")]))
|
32
src/test/clj/dda/devops_build/devops/domain_test.clj
Normal file
32
src/test/clj/dda/devops_build/devops/domain_test.clj
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
(ns dda.devops-build.devops.domain-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
[dda.devops-build.devops.domain :as cut]))
|
||||||
|
|
||||||
|
(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"})))
|
||||||
|
(is (= "../../target/dda/backup"
|
||||||
|
(cut/build-path {:name "dda"
|
||||||
|
:module "backup"
|
||||||
|
:project-root-path "../.."
|
||||||
|
:build-dir-name "target"
|
||||||
|
:version "4.11.8-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"}))))
|
||||||
|
|
||||||
|
(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"}))))
|
||||||
|
|
25
src/test/clj/dda/devops_build/image/domain_test.clj
Normal file
25
src/test/clj/dda/devops_build/image/domain_test.clj
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
(ns dda.devops-build.image.domain-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
|
[dda.devops-build.image.domain :as cut]))
|
||||||
|
|
||||||
|
(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"}))))
|
||||||
|
|
||||||
|
(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"}))))
|
||||||
|
|
Loading…
Reference in a new issue