|
12 | 12 | _INSTANCE_DIRECTORY: str = '.instance-88888888-8888-8888-8888-888888888888' |
13 | 13 |
|
14 | 14 | _COMPOSE_CONTENT: str = """--- |
15 | | -version: '3.8' |
| 15 | +version: '2.4' |
16 | 16 | services: |
17 | 17 | job: |
18 | 18 | image: {image} |
19 | | - user: '{uid}:{gid}' |
| 19 | + container_name: {job}-{test}-jote |
| 20 | + user: '{uid}' |
20 | 21 | command: {command} |
21 | 22 | working_dir: {working_directory} |
22 | 23 | environment: |
23 | 24 | - DM_INSTANCE_DIRECTORY={instance_directory} |
24 | 25 | volumes: |
25 | 26 | - {test_path}:{project_directory} |
26 | | - deploy: |
27 | | - resources: |
28 | | - limits: |
29 | | - cpus: 1 |
30 | | - memory: 1G |
| 27 | + mem_limit: {memory_limit} |
| 28 | + cpus: {cpus}.0 |
31 | 29 | """ |
32 | 30 |
|
33 | 31 | # A default, 30 minute timeout |
@@ -64,17 +62,28 @@ def __init__(self, collection: str, |
64 | 62 | job: str, |
65 | 63 | test: str, |
66 | 64 | image: str, |
| 65 | + memory: str, |
| 66 | + cores: int, |
67 | 67 | project_directory: str, |
68 | 68 | working_directory: str, |
69 | 69 | command: str): |
70 | 70 |
|
71 | | - self._collection = collection |
72 | | - self._job = job |
73 | | - self._test = test |
74 | | - self._image = image |
75 | | - self._project_directory = project_directory |
76 | | - self._working_directory = working_directory |
77 | | - self._command = command |
| 71 | + # Memory must have a Mi or Gi suffix. |
| 72 | + # For docker-compose we translate to 'm' and 'g' |
| 73 | + if memory.endswith('Mi'): |
| 74 | + self._memory: str = f'{memory[:-2]}m' |
| 75 | + elif memory.endswith('Gi'): |
| 76 | + self._memory: str = f'{memory[:-2]}g' |
| 77 | + assert self._memory |
| 78 | + |
| 79 | + self._collection: str = collection |
| 80 | + self._job: str = job |
| 81 | + self._test: str = test |
| 82 | + self._image: str = image |
| 83 | + self._cores: int = cores |
| 84 | + self._project_directory: str = project_directory |
| 85 | + self._working_directory: str = working_directory |
| 86 | + self._command: str = command |
78 | 87 |
|
79 | 88 | def get_test_path(self) -> str: |
80 | 89 | """Returns the path to the root directory for a given test. |
@@ -113,15 +122,19 @@ def create(self) -> str: |
113 | 122 | if not os.path.exists(inst_path): |
114 | 123 | os.makedirs(inst_path) |
115 | 124 |
|
116 | | - # Write the Docker compose content to a file to the test directory |
117 | | - variables: Dict[str, Any] = {'test_path': project_path, |
118 | | - 'image': self._image, |
119 | | - 'uid': os.geteuid(), |
120 | | - 'gid': os.getegid(), |
121 | | - 'command': self._command, |
122 | | - 'project_directory': self._project_directory, |
123 | | - 'working_directory': self._working_directory, |
124 | | - 'instance_directory': _INSTANCE_DIRECTORY} |
| 125 | + # Write the Docker compose content to a file in the test directory |
| 126 | + variables: Dict[str, Any] =\ |
| 127 | + {'test_path': project_path, |
| 128 | + 'job': self._job, |
| 129 | + 'test': self._test, |
| 130 | + 'image': self._image, |
| 131 | + 'memory_limit': self._memory, |
| 132 | + 'cpus': self._cores, |
| 133 | + 'uid': os.geteuid(), |
| 134 | + 'command': self._command, |
| 135 | + 'project_directory': self._project_directory, |
| 136 | + 'working_directory': self._working_directory, |
| 137 | + 'instance_directory': _INSTANCE_DIRECTORY} |
125 | 138 | compose_content: str = _COMPOSE_CONTENT.format(**variables) |
126 | 139 | compose_path: str = f'{test_path}/docker-compose.yml' |
127 | 140 | with open(compose_path, 'wt', encoding='UTF-8') as compose_file: |
|
0 commit comments