Skip to content

Commit

Permalink
refactored docker module
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 18, 2023
1 parent 9d29dd4 commit ef2aa10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public DocSection section() {
utils.addItem(diBuilder.getDocItem("docker/container-remove-by-name", false));
utils.addItem(diBuilder.getDocItem("docker/container-status-by-name", false));
utils.addItem(diBuilder.getDocItem("docker/container-exec-by-name", false));
utils.addItem(diBuilder.getDocItem("docker/container-log", false));
utils.addItem(diBuilder.getDocItem("docker/container-has-log-msg", false));
utils.addItem(diBuilder.getDocItem("docker/container-logs", false));
utils.addItem(diBuilder.getDocItem("docker/container-purge-by-name", false));
utils.addItem(diBuilder.getDocItem("docker/container-image-info-by-name", false));

Expand Down
85 changes: 22 additions & 63 deletions src/main/resources/com/github/jlangch/venice/docker.venice
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@
"docker/container-remove-by-name"
"docker/container-status-by-name"
"docker/container-exec-by-name"
"docker/container-log"
"docker/container-has-log-msg"
"docker/container-logs"
"docker/container-purge-by-name"
"docker/container-image-info-by-name" )
:spec { :options { :detach [:optional #{true, false}]
Expand Down Expand Up @@ -1031,8 +1030,7 @@
;; - docker/container-remove-by-name
;; - docker/container-status-by-name
;; - docker/container-exec-by-name
;; - docker/container-log
;; - docker/container-has-log-msg
;; - docker/container-logs
;; - docker/container-purge-by-name
;; - docker/container-image-info-by-name
;; -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1171,7 +1169,7 @@
"docker/container-stop-by-name"
"docker/container-remove-by-name"
"docker/container-status-by-name"
"docker/container-log" ) }
"docker/container-logs" ) }

container-start-by-name [name]

Expand Down Expand Up @@ -1205,7 +1203,7 @@
"docker/container-stop-by-name"
"docker/container-remove-by-name"
"docker/container-status-by-name"
"docker/container-log" ) }
"docker/container-logs" ) }

container-stop-by-name

Expand Down Expand Up @@ -1341,7 +1339,7 @@
"docker/run"
"docker/container-running-with-name?"
"docker/container-exec-by-name"
"docker/container-log" ) }
"docker/container-logs" ) }

container-exec-by-name [name]

Expand All @@ -1355,74 +1353,35 @@

(defn
^{ :arglists '(
"(docker/container-log name)"
"(docker/container-log name since)")
"(docker/container-logs name & options)")
:doc """
Returns the container logs.
"""
:examples '(
"""
(docker/container-log "myapp"9
""",
"""
(docker/container-log "myapp" "2m")
""" )
:see-also '(
"docker/run"
"docker/container-running-with-name?"
"docker/container-has-log-msg" ) }

container-log

([name]
(container-log name nil))

([name since]
(let [container (first (container-find-by-name name))
id (get container "ID")
status (get container "State")]
(assert (= status "running")
"There is no container running with the name \"~{name}\"!")
(if (nil? since) (docker/logs id) (docker/logs id :since since)))))


(defn
^{ :arglists '(
"(docker/container-has-log-msg name msg)"
"(docker/container-has-log-msg name msg tail)")
:doc """
Returns true if the container logs has message that matches the
regex 'msg' and is newer than the optional 'since' timestamp.
Options:

'tail': the number of lines to show from the end of the logs
| :tail n | Number of lines to show from the end of the logs |
| :since ts | Show logs since timestamp or relative (e.g. "42m" for 42 minutes) |
| :until ts | Show logs until timestamp or relative (e.g. "42m" for 42 minutes) |
| :follow {true, false} | Follow log output |
| :details {true, false} | Show extra details provided to logs |
"""
:examples '(
"""
(docker/container-has-log-msg "myapp"
#".*is ready for business. Have fun.*"
10)
(docker/container-logs "myapp")
""",
"""
(docker/container-logs "myapp" :since "2m")
""" )
:see-also '(
"docker/run"
"docker/container-running-with-name?"
"docker/container-log" ) }

container-has-log-msg
"docker/logs"
"docker/container-running-with-name?" ) }

([name msg]
(container-has-log-msg name msg nil))
container-logs [name & options]

([name msg tail]
(let [container (first (container-find-by-name name))
id (get container "ID")
status (get container "State")]
(assert (= status "running")
"There is no container running with the name \"~{name}\"!")
(->> (if (nil? tail) (docker/logs id) (docker/logs id :tail tail))
(str/split-lines)
(filter #(match? % msg))
(count)
(pos?)))))
(let [container (first (container-find-by-name name))
id (get container "ID")]
(apply docker/logs id options)))



Expand Down

0 comments on commit ef2aa10

Please sign in to comment.