def _run_container(self, run_command_instance, callback): """ this is internal method """ tmpfile = os.path.join(get_backend_tmpdir(), random_tmp_filename()) # the cid file must not exist run_command_instance.options += ["--cidfile=%s" % tmpfile] logger.debug("docker command: %s" % run_command_instance) response = callback() # and we need to wait now; inotify would be better but is way more complicated and # adds dependency Probe(timeout=10, count=10, pause=0.1, fnc=lambda: os.path.exists(tmpfile)).run() with open(tmpfile, 'r') as fd: container_id = fd.read() return container_id, response
def run_via_binary(self, run_command_instance=None, command=None, volumes=None, additional_opts=None, **kwargs): """ create a buildah container using this image :param run_command_instance: not used :param command: not used, please use exec :param volumes: tuple or list of tuples in the form: * `("/path/to/directory", )` * `("/host/path", "/container/path")` * `("/host/path", "/container/path", "mode")` * `(conu.Directory('/host/path'), "/container/path")` (source can be also Directory instance) :param additional_opts: list of str, additional options for `buildah from` :return: instance of BuildahContainer """ logger.info("create buildah container") if not run_command_instance: run_command_instance = BuildahRunBuilder( command=command, additional_opts=additional_opts) run_command_instance.image_name = self.get_full_name() tmpfile = os.path.join(get_backend_tmpdir(), random_tmp_filename()) run_command_instance.options += ["--cidfile=%s" % tmpfile] # TODO: add support for the skopeo transport names cmd = run_command_instance.build() # TODO: fix this using the run builder # if volumes: # cmd += self.get_volume_options(volumes=volumes) run_cmd(cmd) Probe(timeout=10, count=10, pause=0.1, fnc=lambda: self._file_not_empty(tmpfile)).run() with open(tmpfile, 'r') as fd: container_id = fd.read() return BuildahContainer(self, container_id, image_class=self.__class__)
def _run_container(self, run_command_instance, callback): """ this is internal method """ tmpfile = os.path.join(get_backend_tmpdir(), random_tmp_filename()) # the cid file must not exist run_command_instance.options += ["--cidfile=%s" % tmpfile] logger.debug("podman command: %s" % run_command_instance) response = callback() # and we need to wait now; inotify would be better but is way more complicated and # adds dependency try: Probe(timeout=10, count=25, pause=0.2, fnc=lambda: self._file_not_empty(tmpfile)).run() except (CountExceeded, ProbeTimeout) as ex: logger.info("exception while running a container: %s", ex) raise ConuException("Container was not created, please see the logs.") with open(tmpfile, 'r') as fd: container_id = fd.read() return container_id, response
def _run_container(self, run_command_instance, callback): """ this is internal method """ tmpfile = os.path.join(get_backend_tmpdir(), random_tmp_filename()) # the cid file must not exist run_command_instance.options += ["--cidfile=%s" % tmpfile] logger.debug("docker command: %s" % run_command_instance) response = callback() def get_cont_id(): if not os.path.exists(tmpfile): return False with open(tmpfile, 'r') as fd: content = fd.read() return bool(content) Probe(timeout=2, count=10, pause=0.1, fnc=get_cont_id).run() with open(tmpfile, 'r') as fd: container_id = fd.read() if not container_id: raise ConuException("We could not get container's ID, it probably was not created") return container_id, response