Arguments: fichiers de mot de passe
This commit is contained in:
parent
1ea5329cd0
commit
31b7171656
26
server.py
26
server.py
@ -10,14 +10,12 @@ import tarfile
|
|||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
from gitlab import Gitlab
|
from gitlab import Gitlab
|
||||||
|
import argparse
|
||||||
|
|
||||||
whitelist = ['nyanloutre/site-musique']
|
whitelist = ['nyanloutre/site-musique']
|
||||||
secret = open('secret', 'r').readline().splitlines()[0]
|
|
||||||
gitlab_token = open('gitlab_token', 'r').readline().splitlines()[0]
|
|
||||||
out_dir = './run'
|
|
||||||
|
|
||||||
def build(payload, gl):
|
def build(payload, gl):
|
||||||
gl.projects.get(payload['project']['path_with_namespace']).commits.get(payload['checkout_sha']).statuses.create({'state': 'running'})
|
gl.projects.get(payload['project']['path_with_namespace']).commits.get(payload['checkout_sha']).statuses.create({'state': 'running', 'name': 'Python CI'})
|
||||||
print("push from " + payload['user_name'])
|
print("push from " + payload['user_name'])
|
||||||
print("repo: " + payload['project']['path_with_namespace'])
|
print("repo: " + payload['project']['path_with_namespace'])
|
||||||
print("commit: " + payload['checkout_sha'])
|
print("commit: " + payload['checkout_sha'])
|
||||||
@ -30,7 +28,7 @@ def build(payload, gl):
|
|||||||
gitlab_repo_files.extractall(path=temp_dir.name)
|
gitlab_repo_files.extractall(path=temp_dir.name)
|
||||||
check_call(['ls', '-lha', repo_dir])
|
check_call(['ls', '-lha', repo_dir])
|
||||||
try:
|
try:
|
||||||
check_call(['nix-build', '-o', out_dir + '/' + payload['project']['path_with_namespace'], repo_dir])
|
check_call(['nix-build', '-o', args.output + '/' + payload['project']['path_with_namespace'], repo_dir])
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
return {'payload': payload, 'gitlab': gl, 'status': 'failed'}
|
return {'payload': payload, 'gitlab': gl, 'status': 'failed'}
|
||||||
|
|
||||||
@ -39,24 +37,26 @@ def build(payload, gl):
|
|||||||
def build_success(result):
|
def build_success(result):
|
||||||
gl = result['gitlab']
|
gl = result['gitlab']
|
||||||
payload = result['payload']
|
payload = result['payload']
|
||||||
gl.projects.get(payload['project']['path_with_namespace']).commits.get(payload['checkout_sha']).statuses.create({'state': result['status']})
|
gl.projects.get(payload['project']['path_with_namespace']).commits.get(payload['checkout_sha']).statuses.create({'state': result['status'], 'name': 'Python CI'})
|
||||||
print("build: " + result['status'])
|
print("build: " + result['status'])
|
||||||
|
|
||||||
|
|
||||||
@view_defaults(
|
@view_defaults(
|
||||||
route_name="gitlab_payload", renderer="json", request_method="POST"
|
route_name="gitlab_payload", renderer="json", request_method="POST"
|
||||||
)
|
)
|
||||||
class PayloadView(object):
|
class GitlabBuild(object):
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
self.request = request
|
self.request = request
|
||||||
self.payload = self.request.json
|
self.payload = self.request.json
|
||||||
self.gl = Gitlab('https://gitlab.com', private_token=gitlab_token)
|
self.secret = open('secret', 'r').readline().splitlines()[0]
|
||||||
|
self.gitlab_token = open('gitlab_token', 'r').readline().splitlines()[0]
|
||||||
|
self.gl = Gitlab('https://gitlab.com', private_token=self.gitlab_token)
|
||||||
|
|
||||||
@view_config(header="X-Gitlab-Event:Push Hook")
|
@view_config(header="X-Gitlab-Event:Push Hook")
|
||||||
def payload_push(self):
|
def payload_push(self):
|
||||||
if self.payload['project']['path_with_namespace'] in whitelist and self.request.headers['X-Gitlab-Token'] == secret:
|
if self.payload['project']['path_with_namespace'] in whitelist and self.request.headers['X-Gitlab-Token'] == self.secret:
|
||||||
self.gl.projects.get(self.payload['project']['path_with_namespace']).commits.get(self.payload['checkout_sha']).statuses.create({'state': 'pending'})
|
self.gl.projects.get(self.payload['project']['path_with_namespace']).commits.get(self.payload['checkout_sha']).statuses.create({'state': 'pending', 'name': 'Python CI'})
|
||||||
pool.apply_async(build, (self.payload, self.gl), callback=build_success)
|
pool.apply_async(build, (self.payload, self.gl), callback=build_success)
|
||||||
return "build started"
|
return "build started"
|
||||||
else:
|
else:
|
||||||
@ -64,6 +64,12 @@ class PayloadView(object):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description='CI server')
|
||||||
|
parser.add_argument('--output', help='output directory')
|
||||||
|
parser.add_argument('--secret', help='repo secret file')
|
||||||
|
parser.add_argument('--gitlab-token', help='gitlab token file')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
pool = Pool(1)
|
pool = Pool(1)
|
||||||
|
|
||||||
config = Configurator()
|
config = Configurator()
|
||||||
|
Loading…
Reference in New Issue
Block a user