|
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 |
14 | | - [java.net UnixDomainSocketAddress] |
| 15 | + [java.net URLEncoder UnixDomainSocketAddress] |
15 | 16 | [java.nio ByteBuffer] |
16 | 17 | [java.nio.channels SocketChannel] |
17 | 18 | [java.util Arrays Base64])) |
|
109 | 110 | {:StdinOnce true |
110 | 111 | :OpenStdin true} |
111 | 112 | (defn create-container [{:keys [image entrypoint workdir command host-dir env thread-id opts mounts volumes] :or {opts {:Tty true}}}] |
112 | | - #_(jsonrpc/notify :message {:content (str m)}) |
113 | 113 | (let [payload (json/generate-string |
114 | 114 | (merge |
115 | 115 | {:Image image} |
|
126 | 126 | (or volumes mounts))} |
127 | 127 | :WorkingDir (or workdir "/project")} |
128 | 128 | (when entrypoint {:Entrypoint entrypoint}) |
129 | | - (when command {:Cmd command})))] |
| 129 | + (when command {:Cmd command}))) |
| 130 | + ascii-payload (String. (.getBytes payload "ASCII")) ] |
130 | 131 | (curl/post |
131 | 132 | "http://localhost/containers/create" |
132 | 133 | {:raw-args ["--unix-socket" "/var/run/docker.sock"] |
133 | 134 | :throw false |
134 | | - :body payload |
| 135 | + :body ascii-payload |
135 | 136 | :headers {"Content-Type" "application/json" |
136 | | - "Content-Length" (count payload)}}))) |
| 137 | + "Content-Length" (count ascii-payload)}}))) |
137 | 138 |
|
138 | 139 | (defn create-volume [{:keys [Name]}] |
139 | 140 | (curl/post "http://localhost/volumes/create" |
|
308 | 309 | :AttachStdin false}} |
309 | 310 | println))) |
310 | 311 |
|
| 312 | +(defn run-background-function |
| 313 | + "run container function with no stdin, and no streaming output" |
| 314 | + [m] |
| 315 | + (when (not (has-image? (:image m))) |
| 316 | + (-pull m)) |
| 317 | + (let [x (create m)] |
| 318 | + (start x) |
| 319 | + ;; TODO schedule shutdown hook |
| 320 | + {:done :running})) |
| 321 | + |
311 | 322 | (defn run-function |
312 | 323 | "run container function with no stdin, and no streaming output" |
313 | 324 | [{:keys [timeout] :or {timeout 600000} :as m}] |
|
439 | 450 | returns ::container-response" |
440 | 451 | [m] |
441 | 452 | ;; (schema/validate :schema/container-definition) |
442 | | - (if (-> m :stdin :file) |
| 453 | + (cond |
| 454 | + (-> m :stdin :file) |
443 | 455 | (run-with-stdin-content m) |
| 456 | + (true? (:background m)) |
| 457 | + (run-background-function m) |
| 458 | + :else |
444 | 459 | (run-function m))) |
445 | 460 |
|
446 | 461 | (defn get-login-info-from-desktop-backend |
|
0 commit comments