Skip to content

Commit

Permalink
Minor update in Docker images and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikGartner committed Jun 12, 2018
1 parent 93113f3 commit 7b74212
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,41 @@ 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`.

#### Worker
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`.
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.supervisor
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ COPY . ./

RUN pip install -e .

ENV HYPERDOCK_IN_DOCKER true

ENTRYPOINT ["hyperdock-supervisor"]
CMD ["--help"]
2 changes: 2 additions & 0 deletions docker/Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ COPY . ./

RUN pip install -e .

ENV HYPERDOCK_IN_DOCKER true

ENTRYPOINT ["hyperdock-worker"]
CMD ["--help"]
2 changes: 1 addition & 1 deletion hyperdock/common/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 5 additions & 1 deletion hyperdock/supervisor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
3 changes: 2 additions & 1 deletion hyperdock/supervisor/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class Supervisor(Thread):
workers.
"""

def __init__(self, mongodb):
def __init__(self, mongodb, in_docker=False):
super().__init__(name='Supervisor')

self.logger = logging.getLogger('Supervisor')
self._mongodb = 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):
Expand Down
2 changes: 1 addition & 1 deletion hyperdock/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.4.1' # NOQA
__version__ = '0.4.2' # NOQA


if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion hyperdock/worker/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import json
import os

import click
from pymongo import MongoClient
Expand All @@ -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()


Expand Down
8 changes: 6 additions & 2 deletions hyperdock/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7b74212

Please sign in to comment.