aboutsummaryrefslogtreecommitdiff
path: root/tools/svc/methods/docker.lua
blob: 766718f10e5c2e5ae108dbede88e44c7b5cd0429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local json = require "json"
local sh = require "sh"

if os.getenv("DIE_ON_ERROR") == "yes" then
  sh { abort = true }
end

-- given the name, docker image name and environment
-- variables for this service, deploy it via Docker
-- running locally.
function deploy(name, imagename, vars, settings)
  args = { "run", "-d", "--name", name, "--label", "xe.svc.name="..name}

  for k,v in pairs(vars) do
    table.insert(args, "--env")
    table.insert(args, k .. "=" .. v)
  end

  table.insert(args, imagename)

  local cmd = sh.docker(unpack(args))
  cmd:ok()

  local ctrid = cmd:lines()()
  return ctrid
end

-- given a container name, return a table of information
-- about it
function inspect(name)
  local obj = sh.docker("inspect", ctrid):combinedOutput()
  local tbl, err = json.decode(obj)
  if err ~= nil then
    error(err, obj)
  end

  return tbl
end

-- kill a container by a given name
function kill(name)
  sh.docker("rm", "-f", name):ok()
end