Compare commits

...

2 commits

Author SHA1 Message Date
198713c229 add first try for image build 2024-03-06 13:58:20 +01:00
e9262382c4 using tasks 2024-03-06 11:52:10 +01:00
6 changed files with 49 additions and 22 deletions

5
.bashrc Normal file
View 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

5
bb.edn
View file

@ -1,2 +1,5 @@
{:deps {dda/dda-devops-build {:local/root "."}}}
{:deps {dda/dda-devops-build {:local/root "."}}
:tasks
{:requires ([dda.devops-build.image :as image])
image-build (image/dbuild {:name "myimage"})}}

View file

@ -1,6 +1,2 @@
#!/usr/bin/env bb
(require '[dda.devops-build.main :as build])
(when (= *file* (System/getProperty "babashka.file"))
(apply build/-main *command-line-args*))

View file

@ -0,0 +1,12 @@
(ns dda.devops-build.devops
(:require [clojure.spec.alpha :as s]))
(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]
:opt-un [::module ::stage ::project-root-path ::build-dir-name]))

View file

@ -0,0 +1,28 @@
(ns dda.devops-build.image
(:require [clojure.spec.alpha :as s]
[babashka.process :as p]
[babashka.tasks :as t]
[orchestra.core :refer [defn-spec]]
[dda.devops-build.devops :as d]))
(s/def ::options (s/* #{"-h"}))
(s/def ::cmd-args (s/cat :options ::options
:args any?))
(defn invalid-args-msg
[spec args]
(s/explain spec args)
(println (str "Bad commandline arguments\n")))
(defn-spec
dbuild any?
[devops ::d/devops]
(let [{:keys [name]} devops]
(t/shell "echo 'docker" "build" "-t" name "--file" "{path}/image/Dockerfile" "{path}/image")))
(defn drun [& cmd-args]
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
(if (= ::s/invalid parsed-args-cmd)
(invalid-args-msg ::cmd-args cmd-args)
(-> (p/process "docker run" "-it" "{name}" "/bin/bash")
(p/check)))))

View file

@ -1,17 +0,0 @@
(ns dda.devops-build.main)
(require '[clojure.spec.alpha :as s])
(s/def ::options (s/* #{"-h"}))
(s/def ::cmd-args (s/cat :options ::options
:args any?))
(defn invalid-args-msg
[spec args]
(s/explain spec args)
(println (str "Bad commandline arguments\n")))
(defn -main [& cmd-args]
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
(if (= ::s/invalid parsed-args-cmd)
(invalid-args-msg ::cmd-args cmd-args)
(println parsed-args-cmd))))