add first try for image build

This commit is contained in:
Michael Jerger 2024-03-06 13:58:20 +01:00
parent e9262382c4
commit 198713c229
5 changed files with 47 additions and 19 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

4
bb.edn
View file

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

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 build [& 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))))