Created
March 24, 2017 23:13
-
-
Save noc0lour/f45eae93cc9f0ca89f9759c47a73e3df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWorker(worker.Worker): | |
def __init__(self, name, properties, *args, **kwargs): | |
password = "mybuildbot", | |
super(MyWorker, self).__init__(name, password, *args, **kwargs) | |
class MyLatentWorker(worker.DockerLatentWorker): | |
def __init__(self, name, image, properties, *args, **kwargs): | |
password = "mybuildbot" | |
kwargs["image"] = str(image) | |
docker_host = "unix://var/run/docker.sock" | |
kwargs.setdefault("docker_host", docker_host) | |
hostconfig = kwargs.get("hostconfig", {}) | |
hostconfig.setdefault("network_mode","container:"+os.environ.get("HOSTNAME")) | |
kwargs["hostconfig"] = hostconfig | |
super(MyLatentWorker, self).__init__(name, password, *args, **kwargs) | |
def createWorkers(config_path): | |
workers = [] | |
with open(config_path) as f: | |
config_data = f.read() | |
config_data = json.loads(config_data) | |
for os_type, os_config in iteritems(config_data): | |
for os_flavour, flavour_config in iteritems(os_config): | |
for n in range(flavour_config.get("workers", 1)): | |
name = "_".join([os_flavour, str(n)]) | |
props = flavour_config.get("properties", {}) | |
props.setdefault("os", os_type) | |
if "image" in flavour_config: | |
worker = MyLatentWorker(name, flavour_config.get("image"), props) | |
else: | |
worker = MyWorker(name, props) | |
workers.append(worker) | |
return workers | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment