|
105 | 105 | :throw false
|
106 | 106 | :as :stream}))
|
107 | 107 |
|
| 108 | +(defn parse-port [s] |
| 109 | + (let [[_ host container] (re-find #"(.*):(.*)" s)] |
| 110 | + {:host {:port host} |
| 111 | + :container {:port container |
| 112 | + :protocol "tcp"}})) |
| 113 | + |
| 114 | +(defn exposed-ports |
| 115 | + " params |
| 116 | + - coll of strings (e.g. [\"9222:9222\"])" |
| 117 | + [coll] |
| 118 | + (->> (for [s coll :let [{:keys [container]} (parse-port s)]] |
| 119 | + [(format "%s/%s" (:port container) (:protocol container)) {}]) |
| 120 | + (into {}))) |
| 121 | + |
| 122 | +(defn port-bindings |
| 123 | + " params |
| 124 | + - coll of strings (e.g. [\"9222:9222\"])" |
| 125 | + [coll] |
| 126 | + (->> |
| 127 | + (for [s coll :let [{:keys [container host]} (parse-port s)]] |
| 128 | + [(format "%s/%s" (:port container) (:protocol container)) [{:HostPort (:port host)}]]) |
| 129 | + (into {}))) |
| 130 | + |
| 131 | +(comment |
| 132 | + (port-bindings ["9222:9222"]) |
| 133 | + (exposed-ports ["9222:9222"])) |
| 134 | + |
108 | 135 | ;; check for 201
|
109 | 136 | ;; entrypoint is an array of strings
|
110 | 137 | ;; env is a map
|
111 | 138 | ;; Env is an array of name=value strings
|
| 139 | +;; |
| 140 | +;; opts |
| 141 | +;; |
112 | 142 | ;; Tty wraps the process in a pseudo terminal
|
113 |
| -{:StdinOnce true |
114 |
| - :OpenStdin true} |
115 |
| -(defn create-container [{:keys [image entrypoint workdir command host-dir env thread-id opts mounts volumes ports] |
| 143 | +;; StdinOnce closes the stdin after the first client detaches |
| 144 | +;; OpenStdin just opens stdin |
| 145 | +(defn create-container [{:keys [image entrypoint workdir command host-dir env thread-id opts mounts volumes ports network_mode] |
116 | 146 | :or {opts {:Tty true}}}]
|
117 | 147 | (let [payload (json/generate-string
|
118 | 148 | (merge
|
|
123 | 153 | (into []))})
|
124 | 154 | {:HostConfig
|
125 | 155 | (merge
|
126 |
| - {:Binds |
127 |
| - (concat ["docker-lsp:/docker-lsp" |
128 |
| - "/var/run/docker.sock:/var/run/docker.sock"] |
129 |
| - (when host-dir [(format "%s:/project:rw" host-dir)]) |
130 |
| - (when thread-id [(format "%s:/thread:rw" thread-id)]) |
131 |
| - (or volumes mounts))} |
132 |
| - (when ports |
133 |
| - {:PortBindings {"9222/tcp" [{:HostPort "9222"}]}})) |
| 156 | + {:Binds |
| 157 | + (concat ["docker-lsp:/docker-lsp" |
| 158 | + "/var/run/docker.sock:/var/run/docker.sock"] |
| 159 | + (when host-dir [(format "%s:/project:rw" host-dir)]) |
| 160 | + (when thread-id [(format "%s:/thread:rw" thread-id)]) |
| 161 | + (or volumes mounts))} |
| 162 | + (when network_mode |
| 163 | + {:NetworkMode network_mode}) |
| 164 | + (when ports |
| 165 | + {:PortBindings (port-bindings ports)})) |
134 | 166 | :WorkingDir (or workdir "/project")}
|
135 |
| - (when ports {:ExposedPorts {"9222/tcp" {}}}) |
| 167 | + (when ports {:ExposedPorts (exposed-ports ports)}) |
136 | 168 | (when entrypoint {:Entrypoint entrypoint})
|
137 | 169 | (when command {:Cmd command})))
|
138 | 170 | ascii-payload (String. (.getBytes payload "ASCII"))]
|
|
0 commit comments