|
61 | 61 |
|
62 | 62 | (defn backend-login-info [_]
|
63 | 63 | (curl/get
|
64 |
| - "http://localhost/registry/info" |
65 |
| - {:raw-args ["--unix-socket" (get-backend-socket)] |
66 |
| - :throw false})) |
| 64 | + "http://localhost/registry/info" |
| 65 | + {:raw-args ["--unix-socket" (get-backend-socket)] |
| 66 | + :throw false})) |
67 | 67 |
|
68 | 68 | (defn backend-get-token [_]
|
69 | 69 | (curl/get
|
|
228 | 228 | (spec/def ::container-definition (spec/keys :opt-un [::host-dir ::entrypoint ::command ::user ::jwt]
|
229 | 229 | :req-un [::image]))
|
230 | 230 |
|
| 231 | +(spec/def ::pty-output string?) |
| 232 | +(spec/def ::exit-code integer?) |
| 233 | +(spec/def ::info any?) |
| 234 | +(spec/def ::done #{:timeout :exited}) |
| 235 | +(spec/def ::timeout integer?) |
| 236 | +(spec/def ::kill-container any?) |
| 237 | + |
| 238 | +(spec/def ::container-response (spec/keys :req-un [::pty-output ::exit-code ::info ::done] |
| 239 | + :opt-un [::timeout ::kill-container])) |
| 240 | + |
231 | 241 | (defn- -pull [m]
|
232 | 242 | (pull (merge m
|
233 | 243 | {:serveraddress "https://index.docker.io/v1/"}
|
|
236 | 246 | {:creds {:username (:user m)
|
237 | 247 | :password (or (:jwt m) (:pat m))}}))))
|
238 | 248 |
|
239 |
| -(defn run-function [{:keys [timeout] :or {timeout 600000} :as m}] |
| 249 | +(defn run-function |
| 250 | + "run container function with no stdin" |
| 251 | + [{:keys [timeout] :or {timeout 600000} :as m}] |
240 | 252 | (-pull m)
|
241 | 253 | (let [x (create m)
|
242 | 254 | finished-channel (async/promise-chan)]
|
|
340 | 352 | {:pty-output s
|
341 | 353 | :exit-code (-> info :State :ExitCode)
|
342 | 354 | :info info}))
|
343 |
| - (catch Throwable t |
| 355 | + (catch Throwable _ |
344 | 356 | (delete x)
|
345 | 357 | {}))))
|
346 | 358 |
|
| 359 | +(defn run-with-stdin-content |
| 360 | + "run container with stdin read from a file" |
| 361 | + [m] |
| 362 | + (let [x (docker/function-call-with-stdin |
| 363 | + (assoc m :content (slurp (-> m :stdin :file))))] |
| 364 | + (async/<!! (async/thread |
| 365 | + (Thread/sleep 10) |
| 366 | + (docker/finish-call x))))) |
| 367 | + |
| 368 | +(defn run-container |
| 369 | + " params ::container-definition |
| 370 | + returns ::container-response" |
| 371 | + [m] |
| 372 | + (if (-> m :stdin :file) |
| 373 | + (run-with-stdin-content m) |
| 374 | + (run-function m))) |
| 375 | + |
347 | 376 | (defn get-login-info-from-desktop-backend
|
348 | 377 | "returns token or nil if not logged in or backend.sock is not available"
|
349 | 378 | []
|
350 | 379 | (try
|
351 | 380 | (when (is-logged-in? {})
|
352 |
| - (merge |
353 |
| - {:is-logged-in? true} |
354 |
| - (try |
355 |
| - (get-login-info {}) |
356 |
| - (catch Throwable ex |
357 |
| - (logging/warn "Unable to extract login info: {{ex}}" {:ex ex}))))) |
| 381 | + (merge |
| 382 | + {:is-logged-in? true} |
| 383 | + (try |
| 384 | + (get-login-info {}) |
| 385 | + (catch Throwable ex |
| 386 | + (logging/warn "Unable to extract login info: {{ex}}" {:ex ex}))))) |
358 | 387 | (catch Throwable _)))
|
359 | 388 |
|
360 | 389 | (comment
|
|
0 commit comments