| 
8 | 8 |    [clojure.string :as string]  | 
9 | 9 |    [creds]  | 
10 | 10 |    jsonrpc  | 
 | 11 | +   [jsonrpc.logger :as logger]  | 
11 | 12 |    logging  | 
12 | 13 |    schema)  | 
13 | 14 |   (:import  | 
 | 
35 | 36 |   (curl/post  | 
36 | 37 |    (format "http://localhost/images/create?fromImage=%s" image)  | 
37 | 38 |    (merge  | 
38 |  | -     {:raw-args ["--unix-socket" (let [f (fs/file "/var/run/docker.raw.sock")]   | 
39 |  | -                                   (if (.exists f)    | 
40 |  | -                                     "/var/run/docker.raw.sock"  | 
41 |  | -                                     "/var/run/docker.sock"))]  | 
 | 39 | +    {:raw-args ["--unix-socket" (let [f (fs/file "/var/run/docker.raw.sock")]  | 
 | 40 | +                                  (if (.exists f)  | 
 | 41 | +                                    "/var/run/docker.raw.sock"  | 
 | 42 | +                                    "/var/run/docker.sock"))]  | 
42 | 43 |      :throw false}  | 
43 | 44 |     (when (or creds identity-token)  | 
44 | 45 |       {:headers {"X-Registry-Auth"  | 
 | 
129 | 130 |                    :WorkingDir (or workdir "/project")}  | 
130 | 131 |                   (when entrypoint {:Entrypoint entrypoint})  | 
131 | 132 |                   (when command {:Cmd command})))  | 
132 |  | -        ascii-payload (String. (.getBytes payload "ASCII")) ]  | 
 | 133 | +        ascii-payload (String. (.getBytes payload "ASCII"))]  | 
133 | 134 |     (curl/post  | 
134 | 135 |      "http://localhost/containers/create"  | 
135 | 136 |      {:raw-args ["--unix-socket" "/var/run/docker.sock"]  | 
 | 
386 | 387 |   (try  | 
387 | 388 |     (String. ^bytes (Arrays/copyOfRange ^bytes bytes 8 (count bytes)))  | 
388 | 389 |     (catch Throwable t  | 
389 |  | -      (println t)  | 
 | 390 | +      (logger/error "not a docker stream: " t)  | 
390 | 391 |       "")))  | 
391 | 392 | 
 
  | 
392 |  | -(defn function-call-with-stdin   | 
 | 393 | +(defn function-call-with-stdin  | 
393 | 394 |   "creates and starts container, then writes to stdin process  | 
394 | 395 |      returns container map with Id, and socket - socket is open socket to stdin"  | 
395 | 396 |   [m]  | 
 | 
442 | 443 |   "run container with stdin read from a file"  | 
443 | 444 |   [m]  | 
444 | 445 |   (let [x (docker/function-call-with-stdin  | 
445 |  | -            (assoc m :content (or (-> m :stdin :content)  (slurp (-> m :stdin :file)))))]  | 
 | 446 | +           (assoc m :content (or (-> m :stdin :content) (slurp (-> m :stdin :file)))))]  | 
446 | 447 |     (async/<!! (async/thread  | 
447 | 448 |                  (Thread/sleep 10)  | 
448 | 449 |                  (docker/finish-call x)))))  | 
 | 
452 | 453 |      returns ::container-response"  | 
453 | 454 |   [m]  | 
454 | 455 |   ;; (schema/validate :schema/container-definition)  | 
455 |  | -  (cond   | 
 | 456 | +  (cond  | 
456 | 457 |     (-> m :stdin)  | 
457 | 458 |     (run-with-stdin-content m)  | 
458 | 459 |     (true? (:background m))  | 
459 | 460 |     (run-background-function m)  | 
460 | 461 |     :else  | 
461 | 462 |     (run-function m)))  | 
462 | 463 | 
 
  | 
 | 464 | +(comment  | 
 | 465 | +  (run-container  | 
 | 466 | +   {:image "vonwig/websocat:latest",  | 
 | 467 | +    :stdin  | 
 | 468 | +    {:content  | 
 | 469 | +     "{\"id\":1,\"method\":\"Page.navigate\",\"params\":{\"url\":\"https://www.docker.com\"}}"},  | 
 | 470 | +    :command  | 
 | 471 | +    ["-n1"  | 
 | 472 | +     "--jsonrpc"  | 
 | 473 | +     "--jsonrpc-omit-jsonrpc"  | 
 | 474 | +     "http://host.docker.internal:9222/devtools/page/EF1106D0B121836079CE1582C85F6E9A"],  | 
 | 475 | +    :jsonrpc true,  | 
 | 476 | +    :host-dir "/Users/slim/docker/labs-ai-tools-for-devs",  | 
 | 477 | +    :debug true,  | 
 | 478 | +    :stream true,  | 
 | 479 | +    :jwt "xxxxxxx",  | 
 | 480 | +    :save-thread-volume true,  | 
 | 481 | +    :register [],  | 
 | 482 | +    :thread-id "thread",  | 
 | 483 | +    :user "jimclark106",  | 
 | 484 | +    :platform "darwin"}))  | 
 | 485 | + | 
463 | 486 | (defn get-login-info-from-desktop-backend  | 
464 | 487 |   "returns token or nil if not logged in or backend.sock is not available"  | 
465 | 488 |   []  | 
 | 
0 commit comments