WIP add build execution with shell
This commit is contained in:
parent
2df80f6d41
commit
3532fccead
2 changed files with 31 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
SECRET_KEY = $3cr3tk3y
|
SECRET_KEY = $3cr3tk3y
|
||||||
KOJI_SERVER = https://kojidev.stackwebservices.org/kojihub
|
KOJI_SERVER = https://kojidev.stackwebservices.com/kojihub
|
||||||
KOJI_TARGET = rl9-candidate
|
KOJI_TARGET = rl9-candidate
|
||||||
|
KOJI_USE_SHELL = true
|
||||||
WEBHOOK_SECRET_KEY = your_secret_key
|
WEBHOOK_SECRET_KEY = your_secret_key
|
||||||
|
|
|
@ -3,21 +3,42 @@ import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import logging
|
import logging
|
||||||
import configparser
|
import configparser
|
||||||
from flask import Flask, request, abort
|
import subprocess
|
||||||
|
from flask import Flask, request, abort, current_app
|
||||||
import koji
|
import koji
|
||||||
|
|
||||||
# Load configuration from .ini file
|
# Load configuration from .ini file
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('config.ini')
|
config.read('config.ini')
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__, instance_relative_config=True)
|
||||||
app.config.from_mapping(config['DEFAULT'])
|
# 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:
|
class KojiProcessor:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
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):
|
def koji_build(self, server_url, build_target, source_url):
|
||||||
"""
|
"""
|
||||||
Perform a Koji build
|
Perform a Koji build
|
||||||
|
@ -91,7 +112,10 @@ class ForgejoWebhookProcessor:
|
||||||
|
|
||||||
git_url = f"git+{clone_url}#{commit_id}"
|
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:
|
except json.JSONDecodeError:
|
||||||
logging.error("Invalid JSON payload")
|
logging.error("Invalid JSON payload")
|
||||||
|
@ -100,6 +124,7 @@ class ForgejoWebhookProcessor:
|
||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
@app.route('/forgejo-webhook', methods=['POST'])
|
@app.route('/forgejo-webhook', methods=['POST'])
|
||||||
|
@app.route('/forgejo-webhook/', methods=['POST'])
|
||||||
def webhook():
|
def webhook():
|
||||||
processor = ForgejoWebhookProcessor(app.config['WEBHOOK_SECRET_KEY'])
|
processor = ForgejoWebhookProcessor(app.config['WEBHOOK_SECRET_KEY'])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue