After discussion with @jskladan I did some initial hacking on branch feature/rules_engine as we think we should update the upcoming code of new trigger. More code and tests will follow...
When docker image is build, koji produces fedmsg in following format:
"msg": { "build_id": 799051, "instance": "primary", "name": "cockpit", "owner": "containerbuild", "release": "0.6", "tag": "f24-docker", "tag_id": 353, "user": "containerbuild", "version": "0.95" },
There is no way to directly tell where to get the image, therefore koji has to be queried, I found the image repository info in archives for given image, it can be obtained with python code:
koji_session.listArchives(799051, type='image')
This query returns:
[{'build_id': 799051, 'type_description': 'Tar files', 'extra': {'image': {'arch': 'x86_64'}, 'docker': {'parent_id': 'sha256:db3bcd639b428283818ea0271fdaa5d1a3c416f11c3e920cdd75cb341e8d653b', 'repositories': ['candidate-registry.fedoraproject.org/fedora/cockpit:0.95-0.6', 'candidate-registry.fedoraproject.org/fedora/cockpit@sha256:e9af81955559007ce0562e8f380ce161622596411b70014786942a0ef84268da'], 'id': '50c728b7bf54fe66aef9577c48069c62aa0a4931434d59f196aaadd029d6a6e4'}}, 'checksum': '4d5615b7a96d11723eea0c9e372dbf01', 'type_name': 'tar', 'filename': 'docker-image-50c728b7bf54fe66aef9577c48069c62aa0a4931434d59f196aaadd029d6a6e4.x86_64.tar.gz', 'buildroot_id': 6376011, 'metadata_only': False, 'type_extensions': 'tar tar.gz tar.bz2 tar.xz', 'type_id': 4, 'checksum_type': 0, 'arch': 'x86_64', 'id': 13564, 'size': 198489144}]
the part we are interested is 'candidate-registry.fedoraproject.org/fedora/cockpit:0.95-0.6' at [0]['extra']['docker']['repositories'][0], but I find this access a little clumsy.
With @kparal, I discussed where do we want to query koji, whether do it in trigger or in task using a koji directive. Kamil is for koji directive, me and Josef are for trigger. The trigger approach can have problem, when the koji is slow, but it produces item in 'docker pullable' format (URL to registry), and compared to directive approach, the koji is queried only once when there are several tasks for given image.
When item is URL to registry, we would need to extract cockpit:0.95-0.6 from the URL, to get 'proper' item name to report against, or start passing more arguments for runtask and be sure that the test is reported against correct nvr.
With the new trigger and this code, the rules for docker images could look like this:
- when: {message_type: KojiBuildDockerCompleted} do: - {discover: {repo: 'http://pkgs.fedoraproject.org/git/docker-checks/${name}.git', branch: "${distgit_branch}"}}
Since you moved most of the code to the class, move this method as well.