|
196 | 196 | (spec/def ::container-definition (spec/keys :opt-un [::host-dir ::entrypoint ::command ::user ::pat]
|
197 | 197 | :req-un [::image]))
|
198 | 198 |
|
199 |
| -(defn run-function [{:keys [timeout] :or {timeout 600000} :as m}] |
| 199 | +(defn- -pull [m] |
200 | 200 | (pull (merge m
|
201 | 201 | {:serveraddress "https://index.docker.io/v1/"}
|
202 | 202 | (let [jwt (creds/credential-helper->jwt)]
|
203 | 203 | (when (and (:user m)
|
204 | 204 | (or (:pat m) jwt))
|
205 | 205 | {:creds {:username (:user m)
|
206 |
| - :password (or (:pat m) jwt)}})))) |
| 206 | + :password (or (:pat m) jwt)}}))))) |
| 207 | + |
| 208 | +(defn run-function [{:keys [timeout] :or {timeout 600000} :as m}] |
| 209 | + (-pull m) |
207 | 210 | (let [x (create m)
|
208 | 211 | finished-channel (async/promise-chan)]
|
209 | 212 | (start x)
|
|
214 | 217 | :done :timeout
|
215 | 218 | :kill-container (kill-container x)}))
|
216 | 219 | ;; watch the container
|
217 |
| - (async/go |
| 220 | + (async/go |
218 | 221 | (wait x)
|
219 | 222 | (async/>! finished-channel {:done :exited}))
|
220 | 223 |
|
|
224 | 227 | info (inspect x)]
|
225 | 228 | (delete x)
|
226 | 229 | (merge
|
227 |
| - finish-reason |
228 |
| - {:pty-output s |
229 |
| - :exit-code (-> info :State :ExitCode) |
230 |
| - :info info})))) |
| 230 | + finish-reason |
| 231 | + {:pty-output s |
| 232 | + :exit-code (-> info :State :ExitCode) |
| 233 | + :info info})))) |
231 | 234 |
|
232 | 235 | (def extract-facts run-function)
|
233 | 236 |
|
|
252 | 255 | (defn docker-stream-format->stdout [bytes]
|
253 | 256 | ;; use xxd to look at the bytes
|
254 | 257 | #_(try
|
255 |
| - (with-open [w (java.io.BufferedOutputStream. |
256 |
| - (java.io.FileOutputStream. "hey.txt"))] |
257 |
| - (.write w bytes)) |
258 |
| - |
259 |
| - (catch Throwable t |
260 |
| - (println t))) |
| 258 | + (with-open [w (java.io.BufferedOutputStream. |
| 259 | + (java.io.FileOutputStream. "hey.txt"))] |
| 260 | + (.write w bytes)) |
| 261 | + |
| 262 | + (catch Throwable t |
| 263 | + (println t))) |
261 | 264 | (String. (Arrays/copyOfRange bytes 8 (count bytes))))
|
262 | 265 |
|
263 | 266 | (defn function-call-with-stdin [m]
|
| 267 | + (-pull m) |
264 | 268 | (let [x (merge
|
265 | 269 | m
|
266 | 270 | (create (assoc m
|
|
276 | 280 | (.close (:socket x))
|
277 | 281 | (wait x)
|
278 | 282 | ;; body is raw PTY output
|
279 |
| - (let [s (docker-stream-format->stdout |
280 |
| - (:body |
281 |
| - (attach-container-stdout-logs x)) ) |
| 283 | + (let [s (docker-stream-format->stdout |
| 284 | + (:body |
| 285 | + (attach-container-stdout-logs x))) |
282 | 286 | info (inspect x)]
|
283 | 287 | (delete x)
|
284 | 288 | {:pty-output s
|
|
295 | 299 | :user "jimclark106")) keyword))
|
296 | 300 | (docker/delete-image {:image "vonwig/go-linguist:latest"})
|
297 | 301 | (pprint
|
298 |
| - (extract-facts {:image "vonwig/go-linguist:latest" |
299 |
| - :timeout 100 |
300 |
| - :command ["-json"] |
301 |
| - :host-dir "/Users/slim/docker/labs-make-runbook" |
302 |
| - :user "jimclark106"})) |
| 302 | + (extract-facts {:image "vonwig/go-linguist:latest" |
| 303 | + :timeout 100 |
| 304 | + :command ["-json"] |
| 305 | + :host-dir "/Users/slim/docker/labs-make-runbook" |
| 306 | + :user "jimclark106"})) |
303 | 307 | (pprint
|
304 | 308 | (json/parse-string
|
305 | 309 | (extract-facts
|
|
0 commit comments