a152d97e3c
Harbormaster can send a request in url encoded form while buildkite expects a POST request with json. Instead of modifying harbormastar or buildkite this adds a simple proxy that accepts url encoded form and creates a request that buildkite expects. To avoid potential abuse, nginx asks for simple http auth credentials stored in harbormaster. All build parameters passed by proxy are put into build metadata and as ph_* env variables available during the build. Secrets involved: - harbormastert knows http-auth to proxy (stored in privatly and in k8 buildkite/http-auth as auth file); - proxy knows buildkite api token (mine atm); - build agent knows conduit API token (mine atm), and SSH key of llvm-premerge-tests-bot (in k8 buildkite/github-ssh). Sample build: https://reviews.llvm.org/harbormaster/build/64828/8/ https://buildkite.com/llvm-project/premerge/builds/48
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import flask
|
|
import requests
|
|
import os
|
|
from urllib.parse import urlparse, parse_qs
|
|
import json
|
|
|
|
app = flask.Flask(__name__)
|
|
app.config["DEBUG"] = True # TODO: make production
|
|
buildkite_api_token = os.getenv("BUILDKITE_API_TOKEN", "")
|
|
|
|
|
|
@app.route('/', methods=['GET'])
|
|
def home():
|
|
return "Hi LLVM!"
|
|
|
|
|
|
@app.route('/build', methods=['POST', 'GET'])
|
|
def build():
|
|
app.logger.info('request: %s %s', flask.request, flask.request.url)
|
|
app.logger.info('headers: %s', flask.request.headers)
|
|
if flask.request.method == 'POST':
|
|
app.logger.info('data: %s', flask.request.data)
|
|
app.logger.info('form: %s', flask.request.form)
|
|
url = urlparse(flask.request.url)
|
|
params = parse_qs(url.query)
|
|
metadata = {}
|
|
build_env = {}
|
|
for k, v in params.items():
|
|
if len(v) == 1:
|
|
metadata[k] = v[0]
|
|
build_env['ph_' + k] = v[0]
|
|
else:
|
|
metadata[k] = v
|
|
branch = 'master'
|
|
if 'scripts_branch' in metadata:
|
|
branch = metadata['scripts_branch']
|
|
build_request = {
|
|
'commit': 'HEAD',
|
|
'branch': branch,
|
|
'meta_data': metadata,
|
|
'env': build_env,
|
|
}
|
|
app.logger.info('buildkite request: %s', build_request)
|
|
headers = {'Authorization': f'Bearer {buildkite_api_token}'}
|
|
response = requests.post(
|
|
'https://api.buildkite.com/v2/organizations/llvm-project'
|
|
'/pipelines/premerge/builds',
|
|
json=build_request,
|
|
headers=headers)
|
|
app.logger.info('buildkite response: %s %s', response.status_code, response.text)
|
|
rjs = json.loads(response.text)
|
|
return rjs['id']
|
|
else:
|
|
return "expected POST request"
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0:8080')
|