Skip to content

Commit

Permalink
Inial docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Stubbs committed Jul 15, 2015
1 parent db5274e commit 42bae6f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
40 changes: 40 additions & 0 deletions actors/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import docker
from models import Actor
from stores import actors_store

class ActorError(Exception):
def __init__(self, message):
Exception.__init__(self, message)
self.message = message



def pull_image(actor_id):
"""
Update the local registry with an actor's image.
:param actor_id:
:return:
"""
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise ActorError("Unable to pull image -- actor {} not found.".format(actor_id))
image = actor.image
cli = docker.AutoVersionClient(base_url='unix://var/run/docker.sock')
try:
rsp = cli.pull(repository=image)
except Exception as e:
raise ActorError("Error pulling image for actor {} - exception: {} ".format(actor_id, str(e)))
return rsp

def execute_actor(image, msg):
cli = docker.AutoVersionClient(base_url='unix://var/run/docker.sock')
container = cli.create_container(image=image, environment={'message': msg})
cli.start(container=container.get('Id'))
cli.wait(container=container.get('Id'))


if __name__ == "__main__":
rsp = pull_image("foo_1")
print("Image pulled. Response: {}".format(str(rsp)))

3 changes: 2 additions & 1 deletion actors/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flask==0.10.1
Flask-RESTful==0.3.3
redis==2.10.3
pika==0.9.13
pika==0.9.13
docker-py

0 comments on commit 42bae6f

Please sign in to comment.