Skip to content

Instantly share code, notes, and snippets.

@YarekTyshchenko
Last active February 2, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YarekTyshchenko/4dfd6670b9605ecb15ef to your computer and use it in GitHub Desktop.
Save YarekTyshchenko/4dfd6670b9605ecb15ef to your computer and use it in GitHub Desktop.
Docker lsyncd script

Docker Lsyncd script

Usage:

sync {
    docker,
    source = ".",
    target="container:/path/in/container/",
    host=os.getenv("DOCKER_HOST"),
    excludes = {
        '.git'
    },
}
docker = {
checkgauge = {
host = true,
excludes = true
},
delay = 0,
maxProcesses = 1,
action = function(inlet)
local config = inlet.getConfig()
local event = inlet.getEvent()
local p = event.pathname
local target = event.targetPathname
if config.host == nil then
log("Normal", "No DOCKER_HOST set, defaulting to 'unix://'")
config.host = 'unix://'
end
log("Normal", "Event "..event.etype..", Pathname is ."..p)
for key,exclude in ipairs(config.excludes) do
if string.match(p, exclude) then
log("Normal", "Path is excluded '"..p.."' by '"..exclude.."'")
inlet.discardEvent(event);
return;
end
end
if event.etype == "Create" or event.etype == "Modify" then
spawnShell(event, "docker -H "..config.host.." cp ."..p.." "..target)
return
end
inlet.discardEvent(event)
end,
collect = function(agent, exitcode)
return 'ok'
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment