From 7b74212c82a193ad06270a398ae6096d2953f601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20G=C3=A4rtner?= Date: Tue, 12 Jun 2018 11:05:58 +0200 Subject: [PATCH] Minor update in Docker images and docs --- README.md | 29 ++++++++++++++--------------- docker/Dockerfile.supervisor | 2 ++ docker/Dockerfile.worker | 2 ++ hyperdock/common/experiment.py | 2 +- hyperdock/supervisor/main.py | 6 +++++- hyperdock/supervisor/supervisor.py | 3 ++- hyperdock/version.py | 2 +- hyperdock/worker/main.py | 6 +++++- hyperdock/worker/worker.py | 8 ++++++-- 9 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b3f9ae0..523a074 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,19 @@ You can either use the built Docker images for Hyperdock or run the parts direct #### Supervisor To start the Hyperdock Supervisor using the Docker image run the following command: ```bash -docker run -it --rm --name hyperdock-supervisor \ +docker run -it --rm --name hyperdock-supervisor --link hyperdock-mongo \ erikgartner/hyperdock-supervisor:latest \ - --mongo mongo://localhost:27017/hyperdock + --mongodb mongodb://hyperdock-mongo:27017/hyperdock ``` Or run it on your host with Python 3.6 and install with pip: ```bash pip install hyperdock -hyperdock-supervisor --mongo mongo://localhost:27017/hyperdock +hyperdock-supervisor --mongodb mongodb://localhost:27017/hyperdock ``` ##### Options: -- `--mongo mongo://localhost:27017/hyperdock` URL to the Mongo database +- `--mongo mongodb://localhost:27017/hyperdock` URL to the Mongo database For full arguments to the supervisor run: `hyperdock-supervisor --help`. @@ -51,22 +51,21 @@ For full arguments to the supervisor run: `hyperdock-supervisor --help`. To start the Hyperdock Worker using the Docker image run the following command: ```bash docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock \ - -v $(pwd)/results:/results \ - -v $(pwd)/data:/data:ro \ - erikgartner/hyperdock-worker:latest \ - --mongo mongo://localhost:27017/hyperdock + --link hyperdock-mongo \ + -v $(pwd):$(pwd) \ + erikgartner/hyperdock-worker:latest \ + --mongodb mongodb://hyperdock-mongo:27017/hyperdock ``` ##### Options: -- `-v $(pwd)/results:/results` sets folder to store the results from target image to the host -- `-v $(pwd)/data:/data:ro` sets folder to store the results from target image to the host +- `-v $(pwd):$(pwd)` mirrors the path structure from the host in to the Docker container. This is needed since the paths must be the the same when the worker starts the Target Image and mounts the data and results folders. - `-v /var/run/docker.sock:/var/run/docker.sock` gives the Docker image access to control the outer Docker daemon. This is crucial for worker to start new containers Or run it on your host with Python 3.6 and install with pip: ```bash pip install hyperdock -hyperdock-worker --mongo mongo://localhost:27017/hyperdock +hyperdock-worker --mongodb mongodb://localhost:27017/hyperdock ``` For full arguments to the worker run: `hyperdock-worker --help`. @@ -76,16 +75,16 @@ For full arguments to the worker run: `hyperdock-worker --help`. #### WebUI To start the Hyperdock WebUI using the Docker image run the following command: ```bash -docker run -d --rm --name hyperdock-webui --link hyperdock-mongo \ - -e ROOT_URL=http://localhost \ - -e MONGO_URL=mongodb://localhost:27017/hyperdock \ +docker run -it --rm --name hyperdock-webui --link hyperdock-mongo \ + -e ROOT_URL=http://localhost:3000/ \ + -e MONGO_URL=mongodb://hyperdock-mongo:27017/hyperdock \ -p 3000:3000 \ erikgartner/hyperdock-webui:latest ``` ##### Options: -- `-e MONGO_URL=mongodb://localhost:27017/hyperdock` sets the Mongo database +- `-e MONGO_URL=mongodb://hyperdock-mongo:27017/hyperdock` sets the Mongo database - `-p 3000:3000` publish the port to the host Or run it on your host with Meteor: diff --git a/docker/Dockerfile.supervisor b/docker/Dockerfile.supervisor index 31c13bb..7d7407a 100644 --- a/docker/Dockerfile.supervisor +++ b/docker/Dockerfile.supervisor @@ -6,5 +6,7 @@ COPY . ./ RUN pip install -e . +ENV HYPERDOCK_IN_DOCKER true + ENTRYPOINT ["hyperdock-supervisor"] CMD ["--help"] diff --git a/docker/Dockerfile.worker b/docker/Dockerfile.worker index 66ccef1..3687b5c 100644 --- a/docker/Dockerfile.worker +++ b/docker/Dockerfile.worker @@ -11,5 +11,7 @@ COPY . ./ RUN pip install -e . +ENV HYPERDOCK_IN_DOCKER true + ENTRYPOINT ["hyperdock-worker"] CMD ["--help"] diff --git a/hyperdock/common/experiment.py b/hyperdock/common/experiment.py index 3be02b5..ed40741 100644 --- a/hyperdock/common/experiment.py +++ b/hyperdock/common/experiment.py @@ -190,7 +190,7 @@ def _fetch_result(self): except: self.logger.error('Failed to read loss') - self._result = {'state': 'fail'} + self._result = {'state': 'fail', 'msg': 'Failed to read loss.'} def _setup_volumes(self): """ diff --git a/hyperdock/supervisor/main.py b/hyperdock/supervisor/main.py index eb61422..dd4c639 100644 --- a/hyperdock/supervisor/main.py +++ b/hyperdock/supervisor/main.py @@ -12,7 +12,11 @@ def launch_supervisor(mongodb): utils.setup_logging() database = MongoClient(mongodb).get_default_database() - supervisor = Supervisor(database) + + # Checks to see if it is running in Docker + in_docker = os.env.get('HYPERDOCK_IN_DOCKER', 'false').lower() == 'true' + + supervisor = Supervisor(database, in_docker) supervisor.start() diff --git a/hyperdock/supervisor/supervisor.py b/hyperdock/supervisor/supervisor.py index 57b51b1..c10f089 100644 --- a/hyperdock/supervisor/supervisor.py +++ b/hyperdock/supervisor/supervisor.py @@ -19,7 +19,7 @@ class Supervisor(Thread): workers. """ - def __init__(self, mongodb): + def __init__(self, mongodb, in_docker=False): super().__init__(name='Supervisor') self.logger = logging.getLogger('Supervisor') @@ -27,6 +27,7 @@ def __init__(self, mongodb): self.trialqueue = TrialQueue(mongodb) self.workqueue = WorkQueue(mongodb) self.worker_collection = mongodb.workers + self.in_docker = in_docker self._running = True def run(self): diff --git a/hyperdock/version.py b/hyperdock/version.py index 653966a..aeaa48d 100644 --- a/hyperdock/version.py +++ b/hyperdock/version.py @@ -1,4 +1,4 @@ -__version__ = '0.4.1' # NOQA +__version__ = '0.4.2' # NOQA if __name__ == '__main__': diff --git a/hyperdock/worker/main.py b/hyperdock/worker/main.py index 56ddcd0..6a9e677 100644 --- a/hyperdock/worker/main.py +++ b/hyperdock/worker/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import json +import os import click from pymongo import MongoClient @@ -24,8 +25,11 @@ def launch_worker(mongodb, env, parallelism): if not isinstance(docker_env, list): raise ValueError('Environment must be in Docker list format.') + # Checks to see if it is running in Docker + in_docker = os.env.get('HYPERDOCK_IN_DOCKER', 'false').lower() == 'true' + # Start worker - worker = Worker(database, docker_env, parallelism) + worker = Worker(database, docker_env, parallelism, in_docker) worker.start() diff --git a/hyperdock/worker/worker.py b/hyperdock/worker/worker.py index a7c49bb..a62d264 100644 --- a/hyperdock/worker/worker.py +++ b/hyperdock/worker/worker.py @@ -13,7 +13,7 @@ class Worker(Thread): - def __init__(self, mongodb, docker_env, parallelism=1): + def __init__(self, mongodb, docker_env, parallelism=1, in_docker=False): super().__init__(name='Worker') self._mongodb = mongodb @@ -24,6 +24,7 @@ def __init__(self, mongodb, docker_env, parallelism=1): self.experiments = [] self.max_experiments = parallelism self.docker_env = docker_env + self.in_docker = in_docker def run(self): """ @@ -54,13 +55,16 @@ def _register_worker(self): Updates the worker list with this worker. Also used as a keep-alive message. """ + host_name = platform.node() + host = '(Docker) %s' % host_name if self.in_docker else host_name + data = { 'id': self.id, 'time': datetime.utcnow(), 'parallelism': self.max_experiments, 'jobs': [e.id for e in self.experiments], 'env': self.docker_env, - 'host': platform.node(), + 'host': host, } self._mongodb.workers.update_one({'id': self.id}, {'$set': data}, upsert=True)