Skip to content

Commit

Permalink
first function transitioned to clj-docker 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKramer committed Feb 23, 2020
1 parent 4069224 commit d944ebc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[com.layerware/hugsql "0.5.1"]
[metosin/compojure-api "2.0.0-alpha30"]
[prismatic/schema "1.1.12"]
[lispyclouds/clj-docker-client "0.3.2"]
[lispyclouds/clj-docker-client "0.4.0"]
[mount "0.1.16"]
[environ "1.1.0"]
[com.impossibl.pgjdbc-ng/pgjdbc-ng "0.8.3"]
Expand Down
14 changes: 12 additions & 2 deletions src/bob/execution/internals.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"Checks if an image is present locally.
Returns the name or the error if any."
[name]
(let [result (f/try* (filter #(= (:RepoTags %) [name])
(docker/image-ls states/docker-conn)))]
(let [images (docker/client {:category :images
:conn states/docker-conn})
result (f/try* (filter #(= (:RepoTags %) [name])
(docker/invoke images {:op :ImageList})))]
(if (or (f/failed? result) (zero? (count result)))
(f/fail "Failed to find %s" name)
name)))
Expand Down Expand Up @@ -112,6 +114,14 @@
err)))

(comment
(def images (docker/client {:category :images
:conn states/docker-conn}))
(clojure.pprint/pprint images)
(filter #(= (:RepoTags %) ["nginx:latest"]) (docker/invoke images {:op :ImageList}))
(filter #(= (:RepoTags %) ["img"]) [{:RepoTags ["img"]}])



(build "busybox:musl"
{:needs_resource "source"
:cmd "ls"}
Expand Down
4 changes: 1 addition & 3 deletions src/bob/states.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
:start (repl/migrate migration-config))

(m/defstate docker-conn
:start (docker/connect)
:stop (do (log/info "Closing docker connection")
(docker/disconnect docker-conn)))
:start (docker/connect {:uri "unix:///var/run/docker.sock"}))

(comment
(m/start)
Expand Down
6 changes: 4 additions & 2 deletions test/bob/execution/internals_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

(deftest docker-image-presence
(testing "image present"
(with-redefs-fn {#'docker/image-ls (constantly [{:RepoTags ["img"]}])}
(with-redefs-fn {#'docker/client (constantly nil)
#'docker/invoke (constantly [{:RepoTags ["img"]}])}
#(is (= "img" (has-image "img")))))

(testing "image absent"
(with-redefs-fn {#'docker/image-ls (constantly [])}
(with-redefs-fn {#'docker/client (constantly nil)
#'docker/invoke (constantly [{:RepoTags ["foo"]}])}
#(let [result (has-image "img")]
(is (and (f/failed? result)
(= "Failed to find img"
Expand Down

0 comments on commit d944ebc

Please sign in to comment.