Skip to content

Commit

Permalink
added docker volume functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 1, 2023
1 parent 86d160f commit a614654
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public DocSection section() {
all.addSection(docker);
docker.addItem(diBuilder.getDocItem("docker/version", false));
docker.addItem(diBuilder.getDocItem("docker/cmd", false));
docker.addItem(diBuilder.getDocItem("docker/volume-list", false));
docker.addItem(diBuilder.getDocItem("docker/debug", false));

final DocSection images = new DocSection("Images", id());
Expand All @@ -71,6 +70,13 @@ public DocSection section() {
containers.addItem(diBuilder.getDocItem("docker/unpause", false));
containers.addItem(diBuilder.getDocItem("docker/wait", false));

final DocSection volume = new DocSection("Volumes", id());
all.addSection(volume);
volume.addItem(diBuilder.getDocItem("docker/volume-list", false));
volume.addItem(diBuilder.getDocItem("docker/volume-create", false));
volume.addItem(diBuilder.getDocItem("docker/volume-rm", false));
volume.addItem(diBuilder.getDocItem("docker/volume-exist?", false));

final DocSection utils = new DocSection("Utils", id());
all.addSection(utils);
utils.addItem(diBuilder.getDocItem("docker/container-find-by-name", false));
Expand Down
75 changes: 74 additions & 1 deletion src/main/resources/com/github/jlangch/venice/docker.venice
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,15 @@
(:out (apply docker/cmd cmdargs*))))



;; -----------------------------------------------------------------------------
;; Volume functions
;; - docker/volume-list
;; - docker/volume-create
;; - docker/volume-rm
;; - docker/volume-exists?
;; -----------------------------------------------------------------------------

(defn
^{ :arglists '("(docker/volume-list & options)")
:doc """
Expand All @@ -728,10 +737,13 @@
(docker/volume-list)
""" )
:see-also '(
"docker/volume-create"
"docker/volume-rm"
"docker/volume-exists?"
"docker/images"
"docker/run" ) }

volume-list []
volume-list [& options]

(let [opts (apply hash-map options)
quiet (:quiet opts false)
Expand All @@ -744,6 +756,67 @@
(parse-output-list format))))


(defn
^{ :arglists '("(docker/volume-create name)")
:doc """
Create a volume.
"""
:examples '(
"""
(docker/volume-create "hello")
""" )
:see-also '(
"docker/volume-list"
"docker/volume-rm"
"docker/volume-exists?" ) }

volume-create [name]

(->> (apply docker/cmd ["volume" "create" name])
(:out)))


(defn
^{ :arglists '("(docker/volume-rm name)")
:doc """
Remove a volume.
"""
:examples '(
"""
(docker/volume-remove "hello")
""" )
:see-also '(
"docker/volume-list"
"docker/volume-create"
"docker/volume-exists?" ) }

volume-rm [name]

(->> (apply docker/cmd ["volume" "rm" name])
(:out)))


(defn
^{ :arglists '("(docker/volume-exists? name)")
:doc """
Returns true if the volume with the specified name exists.
"""
:examples '(
"""
(docker/volume-exists? "hello")
""" )
:see-also '(
"docker/volume-list" ) }

volume-exists? [name]

(->> (docker/volume-list ":format" ":json")
(filter #(if (== name (get % name))))
(count)
(pos?)))




;; -----------------------------------------------------------------------------
;; Generic docker command
Expand Down

0 comments on commit a614654

Please sign in to comment.