Created
May 10, 2014 03:28
-
-
Save quantonganh/a7a0e16fef8a388eb376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import json | |
import salt.client | |
import salt.syspaths as syspaths | |
def application(environ, start_response): | |
length = environ.get('CONTENT_LENGTH', '0') | |
length = 0 if length == '' else int(length) | |
body = environ['wsgi.input'].read() | |
data = json.loads(body) | |
project_name = json.dumps(data['repository']['name']) | |
tag = json.dumps(data['ref'])[1:-1].split('/')[2] | |
caller = salt.client.Caller(os.path.join(syspaths.CONFIG_DIR, 'minion')) | |
pillar = caller.sminion.functions['pillar.get']('{0}:deploy_{1}'.format(project_name, tag)) | |
repository = data['repository'] | |
repository.update(pillar) | |
payload = json.dumps(repository) | |
print('payload: {0}'.format(payload)) | |
start_response('200 OK', [('Content-Type','text/html')]) | |
os.system("sudo /Users/quanta/python/salt_fire_event.py -p '{0}' -t 'deploy_{1}'".format(payload, tag)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment