Пример #1
0
    def spawn_container(self,
                        add_envs=None,
                        add_labels=None,
                        entrypoint_func=None):
        add_envs = sly.take_with_default(add_envs, {})
        add_labels = sly.take_with_default(add_labels, {})
        if entrypoint_func is None:
            entrypoint_func = self.get_spawn_entrypoint

        self._container_lock.acquire()
        volumes = self._get_task_volumes()
        try:
            self._container = self._docker_api.containers.run(
                self.docker_image_name,
                runtime=self.docker_runtime,
                entrypoint=entrypoint_func(),
                detach=True,
                name='sly_task_{}_{}'.format(self.info['task_id'],
                                             constants.TASKS_DOCKER_LABEL()),
                remove=False,
                volumes=volumes,
                environment={
                    'LOG_LEVEL': 'DEBUG',
                    'LANG': 'C.UTF-8',
                    'PYTHONUNBUFFERED': '1',
                    constants._HTTP_PROXY: constants.HTTP_PROXY(),
                    constants._HTTPS_PROXY: constants.HTTPS_PROXY(),
                    'HOST_TASK_DIR': self.dir_task_host,
                    constants._NO_PROXY: constants.NO_PROXY(),
                    constants._HTTP_PROXY.lower(): constants.HTTP_PROXY(),
                    constants._HTTPS_PROXY.lower(): constants.HTTPS_PROXY(),
                    constants._NO_PROXY.lower(): constants.NO_PROXY(),
                    **add_envs
                },
                labels={
                    'ecosystem': 'supervisely',
                    'ecosystem_token': constants.TASKS_DOCKER_LABEL(),
                    'task_id': str(self.info['task_id']),
                    **add_labels
                },
                shm_size="1G",
                stdin_open=False,
                tty=False,
                cpu_period=constants.CPU_PERIOD(),
                cpu_quota=constants.CPU_QUOTA(),
                mem_limit=constants.MEM_LIMIT(),
                memswap_limit=constants.MEM_LIMIT())
            self._container.reload()
            self.logger.debug('After spawning. Container status: {}'.format(
                str(self._container.status)))
            self.logger.info('Docker container is spawned',
                             extra={
                                 'container_id': self._container.id,
                                 'container_name': self._container.name
                             })
        finally:
            self._container_lock.release()
Пример #2
0
 def spawn_container(self, add_envs=None):
     if add_envs is None:
         add_envs = {}
     self._container_lock.acquire()
     volumes = self._get_task_volumes()
     try:
         self._container = self._docker_api.containers.run(
             self.docker_image_name,
             runtime=self.docker_runtime,
             entrypoint=[
                 "sh", "-c", "python -u {}".format(self.entrypoint)
             ],
             detach=True,
             name='sly_task_{}_{}'.format(self.info['task_id'],
                                          constants.TASKS_DOCKER_LABEL()),
             remove=False,
             volumes=volumes,
             environment={
                 'LOG_LEVEL': 'DEBUG',
                 'LANG': 'C.UTF-8',
                 constants._HTTP_PROXY: constants.HTTP_PROXY(),
                 constants._HTTPS_PROXY: constants.HTTPS_PROXY(),
                 **add_envs
             },
             labels={
                 'ecosystem': 'supervisely',
                 'ecosystem_token': constants.TASKS_DOCKER_LABEL(),
                 'task_id': str(self.info['task_id'])
             },
             shm_size="1G",
             stdin_open=False,
             tty=False,
             cpu_period=constants.CPU_PERIOD(),
             cpu_quota=constants.CPU_QUOTA(),
             mem_limit=constants.MEM_LIMIT(),
             memswap_limit=constants.MEM_LIMIT())
         self._container.reload()
         self.logger.debug('After spawning. Container status: {}'.format(
             str(self._container.status)))
         self.logger.info('Docker container is spawned',
                          extra={
                              'container_id': self._container.id,
                              'container_name': self._container.name
                          })
     finally:
         self._container_lock.release()
Пример #3
0
 def _exec_command(self, command, add_envs=None, container_id=None):
     add_envs = sly.take_with_default(add_envs, {})
     self._exec_id = self._docker_api.api.exec_create(self._container.id if container_id is None else container_id,
                                                      cmd=command,
                                                      environment={
                                                          'LOG_LEVEL': 'DEBUG',
                                                          'LANG': 'C.UTF-8',
                                                          'PYTHONUNBUFFERED': '1',
                                                          constants._HTTP_PROXY: constants.HTTP_PROXY(),
                                                          constants._HTTPS_PROXY: constants.HTTPS_PROXY(),
                                                          'HOST_TASK_DIR': self.dir_task_host,
                                                          'TASK_ID': self.info['task_id'],
                                                          'SERVER_ADDRESS': self.info['server_address'],
                                                          'API_TOKEN': self.info['api_token'],
                                                          'AGENT_TOKEN': constants.TOKEN(),
                                                          **add_envs
                                                      })
     self._logs_output = self._docker_api.api.exec_start(self._exec_id, stream=True, demux=False)