Skip to content

Commit 79c7724

Browse files
author
Alan Christie
committed
Uses of compose file v2.4
- Test images now given explicit names - Support for image memory/cores - Now displays compose stderr on failure
1 parent 9ee0379 commit 79c7724

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

jote/compose.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
_INSTANCE_DIRECTORY: str = '.instance-88888888-8888-8888-8888-888888888888'
1313

1414
_COMPOSE_CONTENT: str = """---
15-
version: '3.8'
15+
version: '2.4'
1616
services:
1717
job:
1818
image: {image}
19-
user: '{uid}:{gid}'
19+
container_name: {job}-{test}-jote
20+
user: '{uid}'
2021
command: {command}
2122
working_dir: {working_directory}
2223
environment:
2324
- DM_INSTANCE_DIRECTORY={instance_directory}
2425
volumes:
2526
- {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
3129
"""
3230

3331
# A default, 30 minute timeout
@@ -64,17 +62,28 @@ def __init__(self, collection: str,
6462
job: str,
6563
test: str,
6664
image: str,
65+
memory: str,
66+
cores: int,
6767
project_directory: str,
6868
working_directory: str,
6969
command: str):
7070

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
7887

7988
def get_test_path(self) -> str:
8089
"""Returns the path to the root directory for a given test.
@@ -113,15 +122,19 @@ def create(self) -> str:
113122
if not os.path.exists(inst_path):
114123
os.makedirs(inst_path)
115124

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}
125138
compose_content: str = _COMPOSE_CONTENT.format(**variables)
126139
compose_path: str = f'{test_path}/docker-compose.yml'
127140
with open(compose_path, 'wt', encoding='UTF-8') as compose_file:

jote/jote.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ def _test(args: argparse.Namespace,
271271
tests_failed: int = 0
272272

273273
job_image: str = f'{job_definition.image.name}:{job_definition.image.tag}'
274+
job_image_memory: str = job_definition.image['memory']
275+
if job_image_memory is None:
276+
job_image_memory = '1Gi'
277+
job_image_cores: int = job_definition.image['cores']
278+
if job_image_cores is None:
279+
job_image_cores = 1
274280
job_project_directory: str = job_definition.image['project-directory']
275281
job_working_directory: str = job_definition.image['working-directory']
276282

@@ -396,6 +402,8 @@ def _test(args: argparse.Namespace,
396402
job,
397403
job_test_name,
398404
job_image,
405+
job_image_memory,
406+
job_image_cores,
399407
job_project_directory,
400408
job_working_directory,
401409
job_command)
@@ -413,7 +421,7 @@ def _test(args: argparse.Namespace,
413421
if test_status and not args.dry_run:
414422
# Run the container
415423
assert t_compose
416-
exit_code, out, _ = t_compose.run()
424+
exit_code, out, err = t_compose.run()
417425

418426
# Delete the test directory?
419427
# Not if there's an error
@@ -425,8 +433,10 @@ def _test(args: argparse.Namespace,
425433
print('! FAILURE')
426434
print(f'! exit_code={exit_code}'
427435
f' expected_exit_code={expected_exit_code}')
428-
print('! Container output follows...')
436+
print('! Container stdout follows...')
429437
print(out)
438+
print('! Container stderr follows...')
439+
print(err)
430440
test_status = False
431441

432442
if args.verbose:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
docker-compose == 1.29.2
2-
im-data-manager-job-decoder == 1.3.0
2+
im-data-manager-job-decoder == 1.4.1
33
munch == 2.5.0
44
pyyaml == 5.4.1
55
yamllint == 1.26.3

0 commit comments

Comments
 (0)