Verified Commit 50578b15 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

warn if no helm charts found'

parent 4e9473e2
Pipeline #32006 failed with stages
in 23 seconds
......@@ -54,35 +54,34 @@ class AutoDeploy(Resource):
else:
branch = body['object_attributes']['ref']
branch = body['object_attributes']['ref']
for stage in body['builds']:
if stage['stage'] == 'publish' and stage['status'] == 'success':
projectName = body['project']['path_with_namespace'].split('/')[-1]
repositoryUrl = body['project']['git_http_url']
repositoryPath = body['project']['path_with_namespace']
app.logger.info('deploy-request received from ' + repositoryUrl)
if body['object_attributes']['status'] == 'success':
projectName = body['project']['path_with_namespace'].split('/')[-1]
repositoryUrl = body['project']['git_http_url']
repositoryPath = body['project']['path_with_namespace']
app.logger.info('deploy-request received from ' + repositoryUrl)
# if tag = semver: deploy on prod+stage
if match(r'^(([0-9]+)\.([0-9]+)\.([0-9]+))$', tag):
app.logger.debug(
'commit with semver-tag detected: installing on prod+stage'
)
pullChartUri = (
environ['GITLAB_REGISTRY']
+ '/'
+ repositoryPath
+ ':'
+ tag
+ '-chart'
)
msgs, status = installFromRepo(pullChartUri)
output.extend(msgs)
# deploy on test
elif branch == 'master':
app.logger.debug(
'commit on master without semver-tag detected: installing on test'
)
msgs, status = installFromDir(repositoryUrl, projectName)
output.extend(msgs)
# if tag = semver: deploy on prod+stage
if match(r'^(([0-9]+)\.([0-9]+)\.([0-9]+))$', tag):
app.logger.debug(
'commit with semver-tag detected: installing on prod+stage'
)
pullChartUri = (
environ['GITLAB_REGISTRY']
+ '/'
+ repositoryPath
+ ':'
+ tag
+ '-chart'
)
msgs, status = installFromRepo(pullChartUri)
output.extend(msgs)
# deploy on test
elif branch == 'master':
app.logger.debug(
'commit on master without semver-tag detected: installing on test'
)
msgs, status = installFromDir(repositoryUrl, projectName)
output.extend(msgs)
except subprocess.CalledProcessError as ex:
msg = 'command {} failed with return code {} -- STDOUT: {} -- STDERR: {}'.format(
......@@ -226,6 +225,13 @@ def installFromRepo(pullChartUri):
output.append(msg)
status = 'failure'
rmtree(pulledChartsDir)
try:
proc = subprocess.run('helm chart remove {}'.format(pullChartUri), shell=True, capture_output=True, text=True, check=True)
except subprocess.CalledProcessError as ex:
msg = 'removing helm chart from local repository failed with return code {} -- STDOUT: {} -- STDERR: {}'.format(
ex.returncode, ex.stdout, ex.stderr
)
app.logger.warning(msg)
return output, status
......@@ -251,6 +257,11 @@ def installFromDir(repositoryUrl, projectName):
return output, 'failure'
helmChartDir = path.join(repoDir, 'helm-charts')
if not path.exists(helmChartDir):
msg = 'No helm-charts directory exists'
app.logger.warn(msg)
output.append(msg)
return output, 'failure'
helmValueDir = path.join(helmChartDir, 'helm-values')
if path.exists(helmValueDir):
app.logger.debug('helm value files detected')
......@@ -263,8 +274,9 @@ def installFromDir(repositoryUrl, projectName):
output.append(msg)
else:
# this section should be obsolete since we shouldn't have helm-charts w/o valuefiles
app.logger.warn('no helm-values directory found. this is DEPRECATED')
app.logger.warn('no helm value files detected. this is DEPRECATED')
msg, status = _upgrade_installation(helmChartDir, projectName, projectName)
output.append(msg)
app.logger.debug('Removing temp dir')
rmtree(repoDir)
return output, status
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