khaze1

Untitled

Dec 21st, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.57 KB | None | 0 0
  1. self = <cpp_server_api.CppServer object at 0x7f5d72c7e040>, server_domain = '127.0.0.1', port = '8080', image = 'scores'
  2. start_pattern = '[Ss]erver (has )?started', extra_kwargs = {'entrypoint': '/app/game_server'}
  3. client = <docker.client.DockerClient object at 0x7f5d72c7ed00>, inspector = <docker.api.client.APIClient object at 0x7f5d71de7610>
  4. docker_network = None, kwargs = {'auto_remove': True, 'detach': True, 'entrypoint': '/app/game_server'}
  5. container_args = ['--config-file', '/app/data/config.json', '--www-root', '/app/static/'], pattern = '[Ss]erver (has )?started'
  6. logs = '{"timestamp":"2024-12-22T01:29:08.140486","data":{"address":"0.0.0.0","port":8080},"message":"Server has started..."}\n'
  7.  
  8.     def __init__(self,
  9.                  server_domain: str,
  10.                  port: Union[str, int] = '8080',
  11.                  image: Optional[str] = None,
  12.                  start_pattern: Optional[str] = '[Ss]erver (has )?started',
  13.                  **extra_kwargs):
  14.         self.url = f'http://{server_domain}:{port}'
  15.         self.port = port
  16.  
  17.         if image is None:
  18.             self.container = None
  19.             return
  20.  
  21.         client = docker.from_env()
  22.         inspector = docker.APIClient()
  23.         docker_network = os.environ.get('DOCKER_NETWORK')
  24.  
  25.         kwargs = {
  26.             'detach': True,
  27.             'auto_remove': True,
  28.         }
  29.  
  30.         if 'container_args' in extra_kwargs:
  31.             container_args = extra_kwargs.pop('container_args')
  32.         else:
  33.             container_args = None
  34.  
  35.         if docker_network:
  36.             kwargs['network'] = docker_network
  37.  
  38.         kwargs.update(extra_kwargs)
  39.  
  40.         try:
  41.             if container_args:
  42.                 self.container = client.containers.run(image, list(container_args), **kwargs)
  43.             else:
  44.                 self.container = client.containers.run(image, **kwargs)
  45.             if self.container is None:
  46.                 raise ServerException('Container does not exist', None)
  47.             pattern = start_pattern
  48.             logs = self.container.logs().decode()
  49.             start_time = time.time()
  50.             while re.search(pattern, logs) is None:
  51.                 time.sleep(1)
  52.                 logs = self.container.logs().decode()
  53.                 current_time = time.time()
  54.                 if current_time - start_time >= 3:
  55. >                   raise ServerException('Cannot get the right start phrase from the container.', {'logs': logs})
  56. E                   cpp_server_api.ServerException: <unprintable ServerException object>
  57.  
  58. ../../../tests/cpp_server_api.py:163: ServerException
  59.  
Add Comment
Please, Sign In to add comment