taskotron / taskotron-trigger

Created by tflink 2 years ago
Listens for fedmsg messages of specific types and triggers jobs in taskotron in buildbot as needed.  |  https://taskotron.fedoraproject.org
Members 2
FrantiĊĦek Zatloukal committed 4 months ago

Taskotron Job Trigger

Taskotron Trigger listens for fedmsg messages of specific types and triggers Taskotron jobs (currently using Buildbot) as needed.

Project page: https://pagure.io/taskotron/taskotron-trigger

Documentation

Look into docs/ directory.

Installation in Production

Install the rpm dependencies on the system (only works on Fedora for now):

$ sudo dnf install fedmsg-hub git koji

Then install the trigger. Please note that the following installation is suitable just for containers or similar systems, because it copies files directly to your system directories. It is much better to install an RPM version of trigger (available for Fedora). If you want to set up a development environment, look into that particular section (below) instead. If you really intend to install the files into system dirs, do:

$ sudo python setup.py install

Updating Production Logging Configuration

In /etc/fedmsg.d/logging.py, add the following handler:

filelog={
  "class": "logging.handlers.RotatingFileHandler",
  "formatter": "bare",
  "level": "INFO",
  "filename": "/var/log/fedmsg/taskotron-trigger.log",
  "mode": "a",
}

Then replace the console handler with the filelog handler for the fedmsg logger so that log messages are sent to a separate file instead of to the console:

fedmsg={
  "level": "INFO",
  "propagate": False,
- "handlers": ["console"],
+ "handlers": ["filelog"],
},

Running the Trigger

Once the fedmsg component has been installed, run the following command in the working directory with triggerjob.py:

$ fedmsg-hub

Setting Up a Dev Environment

Install the RPM dependencies mentioned in the Installation in Production section. Then also install the following:

$ sudo dnf install python2-virtualenv python-pip

Create a virtualenv for the trigger, including system site-packages:

$ virtualenv --system-site-packages env_trigger/
$ source env_trigger/bin/activate

Install requirements:

$ pip install -r requirements.txt

For dev environment, it's important that fedmsg-hub is installed in the virtualenv. That's because trigger installs fedmsg configuration, and running the system fedmsg-hub would not see it. You'll need to run this:

$ pip install --ignore-installed 'fedmsg[consumers]'

If you encounter any installation issues, it's possible that you don't have gcc and necessary C development headers installed to compile C extensions from PyPI. Install those based on the error messages, and repeat.

In the end, make sure that env_trigger/bin/fedmsg-hub file is present.

Next, install taskotron-trigger in a development mode:

$ pip install -e .

Create a local configuration file:

$ cp conf/trigger.cfg.example conf/trigger.cfg

Edit conf/trigger.cfg and set:

  • job_logging = True
  • joblog_file and git_cache_dir to a path where you have write access
  • rules_template to a file with your trigger rules, you can use conf/trigger_rules.yml.example as a starting point
  • critpath_filepath to a critpath definition (optional), you can use docker_data/critpath_whitelist.example as a starting point

Once this is all done, you can run fedmsg-hub (while still having the virtualenv active) and it will pick up the local configuration:

$ fedmsg-hub

If you use the default trigger rules, you should see similar messages to confirm they have been enabled:

[    fedmsg    INFO]   enabled by config  - jobtriggers.dist_git_commit_msg:DistGitCommitJobConsumer
[    fedmsg    INFO] No backlog handling.  status: None, url: None
[    fedmsg    INFO]   enabled by config  - jobtriggers.koji_build_msg:KojiBuildCompletedJobConsumer
[    fedmsg    INFO] No backlog handling.  status: None, url: None
[    fedmsg    INFO]   enabled by config  - jobtriggers.koji_tag_msg:KojiTagChangedJobConsumer
[    fedmsg    INFO] No backlog handling.  status: None, url: None

After a short time of waiting you should see new events being detected, e.g.:

[    fedmsg    INFO] triggering rpmlint for kig-16.12.2-1.fc26 on x86_64
[    fedmsg    INFO] StreamRunner received:
item: kig-16.12.2-1.fc26
item_type: koji_build
taskname: rpmlint
arch: x86_64

Running the test suite

From inside the virtualenv run:

$ py.test