-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwaiter.py
55 lines (45 loc) · 1.88 KB
/
waiter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import docker
def _ensure_image(testkit_path, branch_name, artifacts_path):
"""Ensure that an up to date Docker image exists."""
# Construct Docker image name from branch name
image_name = "waiter:%s" % branch_name
image_path = os.path.join(testkit_path, "waiter")
docker.build_and_tag(image_name, image_path, log_path=artifacts_path)
return image_name
def start_container(testkit_path, branch_name, network, secondary_network,
docker_artifacts_path, build_artifacts_path,
artifacts_path):
image = _ensure_image(testkit_path, branch_name, docker_artifacts_path)
container_name = "waiter"
docker.create_or_replace(image, container_name, network=network)
docker.network_connect(secondary_network, container_name)
container = docker.start(container_name)
return Container(container, build_artifacts_path, artifacts_path)
class Container:
def __init__(self, container, build_artifacts_path, artifacts_path):
self._container = container
self._build_artifacts_path = build_artifacts_path
self._artifacts_path = artifacts_path
self._init_container()
def _init_container(self):
self._container.exec(
["python3", "-m", "venv", "venv"],
log_path=self._build_artifacts_path
)
self._container.exec(
["venv/bin/pip", "install", "-U", "pip"],
log_path=self._build_artifacts_path
)
self._container.exec(
["venv/bin/pip", "install", "-Ur", "requirements.txt"],
log_path=self._build_artifacts_path
)
def wait_for_all_dbs(self, host, port, user, password):
self._container.exec(
[
"venv/bin/python", "wait_for_all_dbs.py",
host, str(port), user, password,
],
log_path=self._artifacts_path,
)