Compare commits

...

6 commits

Author SHA1 Message Date
e0e386c804 merge 0.2 2025-01-26 08:38:34 +03:00
993773bea1 WIP add wsgi process user and group 2025-01-26 07:51:51 +03:00
3532fccead WIP add build execution with shell 2025-01-26 03:00:50 +03:00
2df80f6d41 WIP add trailing EOL 2025-01-25 22:41:37 +03:00
e6ab985c12 WIP add apache wsgi configuration 2025-01-25 22:07:39 +03:00
viacheslav anzhiganov
27b342623a add koji call 2025-01-25 05:56:19 +03:00
3 changed files with 32 additions and 6 deletions

View file

@ -1,5 +1,6 @@
[DEFAULT]
SECRET_KEY = $3cr3tk3y
KOJI_SERVER = https://kojidev.stackwebservices.org/kojihub
KOJI_SERVER = https://kojidev.stackwebservices.com/kojihub
KOJI_TARGET = rl9-candidate
KOJI_USE_SHELL = true
WEBHOOK_SECRET_KEY = your_secret_key

View file

@ -1,4 +1,4 @@
WSGIDaemonProcess forgejo processes=2 threads=4
WSGIDaemonProcess forgejo user=builder group=builder processes=2 threads=4
WSGIScriptAlias /forgejo-webhook /opt/koji-forgejo-webhook/koji_forgejo_webhook.wsgi
<Directory /opt/koji-forgejo-webhook>
Require all granted

View file

@ -3,21 +3,42 @@ import hashlib
import hmac
import logging
import configparser
from flask import Flask, request, abort
import subprocess
from flask import Flask, request, abort, current_app
import koji
# Load configuration from .ini file
config = configparser.ConfigParser()
config.read('config.ini')
app = Flask(__name__)
app.config.from_mapping(config['DEFAULT'])
app = Flask(__name__, instance_relative_config=True)
# app.config.from_mapping(config['DEFAULT'])
app.config['SECRET_KEY'] = config.get('DEFAULT', 'SECRET_KEY')
app.config['KOJI_SERVER'] = config.get('DEFAULT', 'KOJI_SERVER')
app.config['KOJI_TARGET'] = config.get('DEFAULT', 'KOJI_TARGET')
app.config['KOJI_USE_SHELL'] = config.getboolean('DEFAULT', 'KOJI_USE_SHELL')
app.config['WEBHOOK_SECRET_KEY'] = config.get('DEFAULT', 'WEBHOOK_SECRET_KEY')
class KojiProcessor:
def __init__(self):
pass
def koji_build_shell(self, build_target, git_url):
try:
# Construct the koji build command
command = ['koji', 'build', build_target, git_url]
# Start the build process
result = subprocess.run(command, check=True, capture_output=True, text=True)
# Print output from the command
logging.info(f"Build started successfully!")
logging.info(result.stdout)
except subprocess.CalledProcessError as e:
logging.error("Error starting build:")
logging.error(e.stderr)
def koji_build(self, server_url, build_target, source_url):
"""
Perform a Koji build
@ -91,7 +112,10 @@ class ForgejoWebhookProcessor:
git_url = f"git+{clone_url}#{commit_id}"
KojiProcessor().koji_build(app.config['KOJI_SERVER'], app.config['KOJI_TARGET'], git_url)
if int(app.config.get('KOJI_USE_SHELL')) == 1:
KojiProcessor().koji_build_shell(app.config['KOJI_TARGET'], git_url)
else:
KojiProcessor().koji_build(app.config['KOJI_SERVER'], app.config['KOJI_TARGET'], git_url)
except json.JSONDecodeError:
logging.error("Invalid JSON payload")
@ -100,6 +124,7 @@ class ForgejoWebhookProcessor:
@app.route('/', methods=['POST'])
@app.route('/forgejo-webhook', methods=['POST'])
@app.route('/forgejo-webhook/', methods=['POST'])
def webhook():
processor = ForgejoWebhookProcessor(app.config['WEBHOOK_SECRET_KEY'])