Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self = <cpp_server_api.CppServer object at 0x7f5d72c7e040>, server_domain = '127.0.0.1', port = '8080', image = 'scores'
- start_pattern = '[Ss]erver (has )?started', extra_kwargs = {'entrypoint': '/app/game_server'}
- client = <docker.client.DockerClient object at 0x7f5d72c7ed00>, inspector = <docker.api.client.APIClient object at 0x7f5d71de7610>
- docker_network = None, kwargs = {'auto_remove': True, 'detach': True, 'entrypoint': '/app/game_server'}
- container_args = ['--config-file', '/app/data/config.json', '--www-root', '/app/static/'], pattern = '[Ss]erver (has )?started'
- logs = '{"timestamp":"2024-12-22T01:29:08.140486","data":{"address":"0.0.0.0","port":8080},"message":"Server has started..."}\n'
- def __init__(self,
- server_domain: str,
- port: Union[str, int] = '8080',
- image: Optional[str] = None,
- start_pattern: Optional[str] = '[Ss]erver (has )?started',
- **extra_kwargs):
- self.url = f'http://{server_domain}:{port}'
- self.port = port
- if image is None:
- self.container = None
- return
- client = docker.from_env()
- inspector = docker.APIClient()
- docker_network = os.environ.get('DOCKER_NETWORK')
- kwargs = {
- 'detach': True,
- 'auto_remove': True,
- }
- if 'container_args' in extra_kwargs:
- container_args = extra_kwargs.pop('container_args')
- else:
- container_args = None
- if docker_network:
- kwargs['network'] = docker_network
- kwargs.update(extra_kwargs)
- try:
- if container_args:
- self.container = client.containers.run(image, list(container_args), **kwargs)
- else:
- self.container = client.containers.run(image, **kwargs)
- if self.container is None:
- raise ServerException('Container does not exist', None)
- pattern = start_pattern
- logs = self.container.logs().decode()
- start_time = time.time()
- while re.search(pattern, logs) is None:
- time.sleep(1)
- logs = self.container.logs().decode()
- current_time = time.time()
- if current_time - start_time >= 3:
- > raise ServerException('Cannot get the right start phrase from the container.', {'logs': logs})
- E cpp_server_api.ServerException: <unprintable ServerException object>
- ../../../tests/cpp_server_api.py:163: ServerException
Add Comment
Please, Sign In to add comment