Giter VIP home page Giter VIP logo

ampule's Introduction

Ampule

An elixir library for Linux containers.

Description

Why not model a container as part of a pipeline? 1

What is a pipeline? A pipeline calls a function which acts as a filter. A filter transforms the data. It can map over the elements or reduce them, maintaining internal state. A filter could be modeled as a closure.

A Linux container is a closure.

ampule returns a closure which is running a virtual machine. Data may be passed into the closure and transformed.

The key here is Erlang distribution. We start containers running erlang nodes and run the code within the container.

It'd be possible to do this "safely" in the future by passing terms in the Erlang external term format between nodes rather than using distribution, maybe over SSL or SSH.

Just as Elixir processes are cheap compared to system processes, wouldn't it be nice if creating virtual machines was as cheap as creating a system process?

ampule works by creating a chroot with a script running busybox to get a dhcp address before exec'ing an unprivileged erlang instance in distributed mode.

ampule is basically a primitive imitation of the Erlang slave module, except that instead of running over, e.g., ssh, it creates the container and starts the erlang node.

Dependencies

ampule requires erlxc, which in turn requires a recent version of liblxc. erlxc needs root privileges, see the README for setup:

https://github.com/msantos/erlxc

Examples

iex must be running in distributed mode:

iex --name [email protected] -S mix
  • Run a pipeline via anonymous containers:
{:erlang,:node,[]}
  |> Ampule.call
  |> Ampule.mfa(:erlang, :atom_to_list)
  |> Ampule.call

This example runs :erlang.node in a container, converts the output to a tuple ({:erlang, :atom_to_list, nodename}) which can be passed back into Ampule.call/1 to be run in a new container.

  • Run a pipeline via named containers:
container = Ampule.spawn
{:erlang,:node,[]}
  |> Ampule.call(container)
  |> Ampule.mfa(:erlang, :atom_to_list)
  |> Ampule.call(container)
  |> list_to_atom

Gets the nodename of the container as a list, does the conversion of the atom to a list inside the same container, then completes the cycle of life by making the list into an atom again.

  • Spawn a process in a container
container = Ampule.spawn
pid = self
Node.spawn(container.nodename, fn -> ls = :os.cmd('ls -al'); send(pid, ls) end)
  • Boot a container running Ubuntu

    Anything written to the system console is sent as messages to the process.

container = Ampule.create

# default username
"ubuntu\n" |> Ampule.console container

# default passowrd
"ubuntu\n" |> Ampule.console container

# run a command
"ls -al\n" |> Ampule.console container

TODO

  • To be safer, ampule could, by default, use a bridge disconnected from the network. The bridge could be a system bridge or an Erlang bridge.

  • Timeout and destroy if container creation/erlang boot fails

  • Support other functions in the rpc module

  • ampule vs ampoule vs ampul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.