def build(dockerfile): nonlocal cid cmd = ['docker', 'build', '-f', dockerfile, '-t', tag, '.'] run(cmd, cwd=prj_dir, check=True) port = 8080 cmd = ['docker', 'run', '--detach', '-p', f'{port}:{port}', tag] out = run(cmd, stdout=PIPE, check=True) cid = out.stdout.decode('utf-8').strip() url = f'http://localhost:{port}/api/healthz' timeout = 30 assert wait_for_server(url, timeout), \ f'server failed to start after {timeout} seconds, url={url}' return cid
def test_docker(): tag = f'mlrun/test-{uuid4().hex}' cid = None cmd = ['docker', 'build', '-f', 'Dockerfile.httpd', '-t', tag, '.'] run(cmd, cwd=prj_dir, check=True) with clean_docker('rmi', tag): port = 8080 cmd = ['docker', 'run', '--detach', '-p', f'{port}:{port}', tag] out = run(cmd, stdout=PIPE, check=True) cid = out.stdout.decode('utf-8').strip() with clean_docker('rm', cid): url = f'http://localhost:{port}/api/healthz' timeout = 30 assert wait_for_server(url, timeout), \ f'server failed to start after {timeout} seconds, url={url}'
def check_server_up(url): health_url = f'{url}/api/healthz' timeout = 30 if not wait_for_server(health_url, timeout): raise RuntimeError('server did not start after {timeout}sec')