-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
41 lines (31 loc) · 1.06 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, request
import threading
import config
import client
import service
app = Flask(__name__)
client = client.DockerAPIClient()
@app.route(config.APP_WEBHOOK_ENDPOINT, methods=['POST'])
def webhook():
# 非同期でイメージをプル
threading.Thread(target=service.pull_image, args=(client,)).start()
# request header から X-GitHub-Event を取得
event = request.headers.get('X-GitHub-Event')
hook_id = request.headers.get('X-GitHub-Delivery')
print('x-github-hook-id: ', hook_id)
print('x-github-event: ', event)
if event == 'workflow_job':
print('workflow_job')
payload = request.json
if payload['action'] == 'queued':
thread = threading.Thread(target=service.run_container(client, hook_id))
thread.start()
elif payload['action'] == 'completed':
print('completed')
return {
'status': 'ok'
}
if __name__ == '__main__':
# イメージをプル
service.pull_image(client)
app.run(host=config.APP_HOST, port=config.APP_PORT)