#794 [rpmbuild] implement --task-file and --task-url parameters
Merged 4 years ago by msuchy. Opened 4 years ago by frostyx.

file modified
+23 -10
@@ -82,6 +82,9 @@ 

      base_parser.add_argument("--build-id", type=str, help="COPR build ID")

      base_parser.add_argument("--copr", type=str, help="copr for which to build, e.g. @group/project")

  

+     base_parser.add_argument("--task-url", help="Full URL to a json task definition")

+     base_parser.add_argument("--task-file", help="Path to a local json file with task definition")

+ 

      subparsers = base_parser.add_subparsers(title="submodes", dest="submode")

      scm_parser = subparsers.add_parser("scm", parents=[shared_parser],

                                         help="Build from an SCM repository.")
@@ -188,10 +191,16 @@ 

          'source_json': {}

      }

  

-     if build_config_url_path:

-         task.update(

-             get_vanilla_build_config(

-                 build_config_url_path, config))

+     if args.task_file:

+         task.update(read_task_from_file(args.task_file))

+     elif args.task_url:

+         task.update(get_vanilla_build_config(args.task_url))

+     elif build_config_url_path:

+         url = urljoin(config.get("main", "frontend_url"), build_config_url_path)

+         task.update(get_vanilla_build_config(url))

+ 

+     if task.get("source_json"):

+         task["source_json"] = json.loads(task["source_json"])

  

      if args.chroot:

          task['chroot'] = args.chroot
@@ -314,22 +323,26 @@ 

          log.info("Wrote: "+config_path)

  

  

- def get_vanilla_build_config(build_config_url_path, config):

+ def get_vanilla_build_config(url):

      try:

-         url = urljoin(config.get("main", "frontend_url"), build_config_url_path)

          response = requests.get(url)

          build_config = response.json()

- 

          if not build_config:

              raise RuntimeError("No valid build_config at {0}".format(url))

+         return build_config

  

-         if build_config.get("source_json"):

-             build_config["source_json"] = json.loads(build_config["source_json"])

      except JSONDecodeError:

          raise RuntimeError("No valid build_config at {0}".format(url))

  

  

-     return build_config

+ def read_task_from_file(path):

+     try:

+         with open(path, "r") as f:

+             return json.loads(f.read())

+     except OSError as ex:

+         raise RuntimeError(ex)

+     except json.decoder.JSONDecodeError:

+         raise RuntimeError("No valid build_config at {0}".format(path))

  

  

  if __name__ == "__main__":

See #517

Although this seems like I am adding possibly unnecessary features,
I am actually doing it to be able to simplify copr-rpmbuild
input and reduce the amount of sidesteps when obtainig task
defintion (hint: we will be able to get rid of the whole SCM
thingy while providing a convenient alternative, that will not
mess our code at all).

Also, --task-file and --task-url are useful for development,
please see the RFE for more information.

[copr-buld] Error downloading packages

The "No valid build_config" error sounds like you wanted to catch "not found" errors.

For some reason, I decided to let OSError be and catch it in main. I will update the code and catch it here.
This exception, that we are commenting is basically copy-pasted from get_vanilla_build_config to deal with invalid json input. I would like to revisit the code soon, but in another PR, since it is not related to this feature.

I will update the code and catch it here.

Maybe you wanted to say "invalid json format" only, or simply not handle exceptions here at all.

I'm not 100% convinced about the benefits (I deal with different copr instance a lot, and I really need to do more/different changes in copr-rpmbuild config to make my life less painful).

But I neither have objections against this patch...

I mean, what would really help would be if there was ideally no configuration at all on copr-rpmbuild side (everything provided by frontend), or if we at least could provide the instance-specific configuration as separate package (which doesn't collide with copr-rpmbuild files).

need to do more/different changes in copr-rpmbuild

As I said, this is not meant to solve all our issues with copr-rpmbuild, it is just a first step allowing me to fix some things, that frustrates me the most. Gradually, we will get there :-)

rebased onto bd009e6d5a4d739a065b18c9e917dd27aecaaf40

4 years ago

I've caught the OSError and rebased the PR. It is not very pretty, but I wanted to stay as close to get_vanilla_build_config as possible, so I will have an easier time refactoring it in following PR.

rebased onto 0ac8036

4 years ago

Pull-Request has been merged by msuchy

4 years ago