Comments (3)
I think this sounds like a good start
Two question
Do we just parse
docker_arg_1 docker_arg_2 ...
directly to docker run?
and when we call ManagedDocker.Container.run
this would be run on the sidekick node though something like :rpc.call
so the process id would exists on the sicknode or on the caller node. Or what does starter process
refer to in this case?
Here is what I had from a while ago, I think it would be fine to continue based on this
defmodule Ci.Docker do
use GenServer
require Logger
def start_link([]) do
GenServer.start_link(__MODULE__, [], name: {:global, __MODULE__})
end
@impl true
def init([]) do
{:ok, %{}}
end
def run(name) do
GenServer.call({:global, __MODULE__}, {:start, name})
end
def stop() do
GenServer.call({:global, __MODULE__}, :stop)
end
@impl true
def handle_call({:start, name}, {from, _ref}, state) do
{id, _} = System.cmd("docker", ["run", "-dt", name])
container_id = String.trim(id)
monitor_ref = Process.monitor(from)
state = Map.put(state, from, {container_id, monitor_ref})
{:reply, :ok, state}
end
@impl true
def handle_call(:stop, {pid, _ref}, state) do
{{container_id, monitor_ref}, state} = Map.pop(state, pid)
cleanup(container_id, monitor_ref)
{:reply, :ok, state}
end
@impl true
def handle_info({:down, pid}, state) do
{{container_id, monitor_ref}, state} = Map.pop(state, pid)
cleanup(container_id, monitor_ref)
{:noreply, state}
end
@impl true
def terminate(_reason, state) do
Logger.debug("Termination #{__MODULE__}")
Enum.each(state, fn {_pid, {container_id, monitor_ref}} ->
cleanup(container_id, monitor_ref)
end)
state
end
defp cleanup(container_id, monitor_ref) do
Process.demonitor(monitor_ref)
System.cmd("docker", ["rm", "-f", container_id])
end
end
from ci.
Do we just parse
docker_arg_1 docker_arg_2 ...
directly to docker run?
If you mean "pass", then yeah, we'd just prepend "docker run"
and invoke the command, e.g. using OsCmd.run
from this library.
and when we call
ManagedDocker.Container.run
this would be run on the sidekick node though something like:rpc.call
so the process id would exists on the sicknode or on the caller node.
Yes, we need to make a call on the sidekick node. I don't think you need :rpc
. On the sidekick node we'd start a registered GenServer (ManagedDocker.Container
registered under the same name). To make a call from the main node you simply need to do GenServer.call({ManagedDocker.Container, sidekick_node}, arg)
. So something like:
defmodule ManagedDocker.Container do
use GenServer
def start_link(arg), do: GenServer.start_link(__MODULE__, arg, name: __MODULE__)
def run(sidekick_node, args), do: GenServer.call({__MODULE__, node}, {:run, args}, timeout)
# ...
end
Or what does
starter process
refer to in this case?
The starter process in my original description refers to the process on the main node that invoked Container.run
. The genserver on the sidekick node needs to keep the mapping of each such process to the list of container ids. It also needs to monitor the starter process. If the starter process stops, the containers it started should be terminated by the genserver on the sidekick node.
Does that make sense?
from ci.
Got started on this here
#11
from ci.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ci.