Hi!
I written a docker client asyncdocker. It's asynchronous (non-blocking) that it can be used to write web services. Of course, it can also be used to write any local deployment tools.
Still needs some tests. Maybe someone could help me. :)
export DOCKER_HOST=127.0.0.1:2375
docker create --name hello --hostname 192.168.0.1 \
ubuntu:14.04 /bin/bash -c 'echo hello'
docker start hello
vs
import asyncdocker, asyncdispatch, json
proc main() {.async.} =
var docker = newAsyncDocker("127.0.0.1", Port(2375))
var ret = await docker.create(image = "ubuntu:14.04",
name = "hello",
hostname = "192.168.0.1",
cmd = @["/bin/bash", "-c", "echo hello"])
echo "Container Id: ", ret["Id"].getStr()
await docker.start(name = "hello")
docker.close()
waitFor main()
See tests and test_ssl to get started; deploy docker and deploy tls docker to deploy docker daemon automatically.
Nice.
I notice you include an async http client. What is that for? Why not use this:
Fixed some bugs, now asyncdocker work in normal.
Here is an example simulates the docker cli docker pull ubuntu:14.10 to download an image and print progress bars:
import asyncdocker, asyncdispatch, json
const
hostname = "127.0.0.1"
port = Port(2375)
proc main() {.async.} =
var docker = newAsyncDocker(hostname, port)
await docker.pull(fromImage = "ubuntu", tag = "14.10",
cb = proc(state: JsonNode): bool =
if state.hasKey("progress"):
let current = state["progressDetail"]["current"].getNum()
let total = state["progressDetail"]["total"].getNum()
stdout.write("\r")
stdout.write(state["id"].getStr())
stdout.write(": ")
stdout.write(state["status"].getStr())
stdout.write(" ")
stdout.write($current & "/" & $total)
stdout.write(" ")
stdout.write(state["progress"].getStr())
if current == total:
stdout.write("\n")
stdout.flushFile()
else:
if state.hasKey("id"):
stdout.write(state["id"].getStr())
stdout.write(": ")
stdout.write(state["status"].getStr())
stdout.write("\n")
else:
stdout.write(state["status"].getStr())
stdout.write("\n"))
docker.close()
waitFor main()
It will output:
14.10: Pulling from library/ubuntu
b0efe5c05b4c: Pulling fs layer
0a1f1b169319: Pulling fs layer
1ceb0a3c7c48: Pulling fs layer
a3ed95caeb02: Pulling fs layer
a3ed95caeb02: Waiting
1ceb0a3c7c48: Downloading 682/682 [==================================================>] 682 B/682 B
1ceb0a3c7c48: Verifying Checksum
1ceb0a3c7c48: Download complete
a3ed95caeb02: Downloading 32/32 [==================================================>] 32 B/32 BB/77.8 kB
a3ed95caeb02: Verifying Checksum
a3ed95caeb02: Download complete
0a1f1b169319: Downloading 77797/77797 [==================================================>] 77.8 kB/77.8 kB
0a1f1b169319: Verifying Checksum
0a1f1b169319: Download complete
b0efe5c05b4c: Downloading 4848810/68321236 [===> ] 4.849 MB/68.32 MB