Commit 20239237 authored by Matthias's avatar Matthias
Browse files

fix deployment process

parent 886eedf6
Pipeline #11054 passed with stages
in 6 minutes and 20 seconds
......@@ -39,37 +39,43 @@ class AutoDeploy(Resource):
"""
status = 'no action required'
status = 'success'
body = ''
output = ''
output = 'no action required'
try:
body = json.loads(flaskRequest.data.decode('utf-8'))
tag = body['object_attributes']['tag']
if re.match("^([0-9]+)\\.([0-9]+)\\.([0-9]+)$", tag): # only deploy if tag is a semver
tag = str(body['object_attributes']['tag'])
if re.match(r'^(([0-9]+)\.([0-9]+)\.([0-9]+))$', tag): # only deploy if tag is a semver
for stage in body['builds']:
if stage['stage'] == 'publish' and stage['status'] == 'success':
projectName = body['project']['name']
repositoryUrl = 'git@gitlab.switch.ch:'\
+ body['project']['path_with_namespace'] + '.git'
proc = subprocess.run('kubectl delete deployment ' + projectName +
'-deployment', shell=True,
capture_output=True, text=True)
output = 'deleting ' + projectName + '-deployment \n' +\
proc.stdout + '\n' + proc.stderr
proc = subprocess.run('rm -rf $(pwd)/autodeploy-workdir/', shell=True,
capture_output=True, text=True)
output += 'removing autodeploy-workdir\n' +\
proc.stdout.decode('utf-8') + '\n' + proc.stderr.decode('utf-8')
proc.stdout + '\n' + proc.stderr
proc = subprocess.run('git clone ' + repositoryUrl +
' $(pwd)/autodeploy-workdir/', shell=True,
capture_output=True, text=True)
output += 'git clone ' + repositoryUrl + '\n' +\
proc.stdout.decode('utf-8') + '\n' + proc.stderr.decode('utf-8')
proc.stdout + '\n' + proc.stderr
proc = subprocess.run('kubectl apply -f $(pwd)' +
'/autodeploy-workdir/k8s-manifests/', shell=True,
capture_output=True, text=True)
output += 'kubectly apply -f k8s-manifests/\n' +\
proc.stdout.decode('utf-8') + '\n' + proc.stderr.decode('utf-8')
proc.stdout + '\n' + proc.stderr
status = 'successfully installed manifests'
except subprocess.CalledProcessError as ex:
status = 'something failed during installation: ' + ex.output + ' \n ' + ex.returncode
except json.JSONDecodeError as ex:
status = 'the json in the body could not be decoded: ' + ex.msg
status = 'the json in the body could not be decoded: ' + str(ex)
except Exception as ex:
status = 'an exception occured: ' + str(ex)
returnVal = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment