bug fixes

This commit is contained in:
Jyotsna 2020-11-18 20:13:57 +05:30
parent faf09632f3
commit c3ad59d720
4 changed files with 27 additions and 14 deletions

View File

@ -38,7 +38,7 @@ function getWorkflowAnnotationsJson(lastSuccessRunSha, workflowFilePath, filePat
+ `'lastSuccessRunCommit': '${lastSuccessRunSha}',` + `'lastSuccessRunCommit': '${lastSuccessRunSha}',`
+ `'branch': '${process.env.GITHUB_REF}',` + `'branch': '${process.env.GITHUB_REF}',`
+ `'deployTimestamp': '${Date.now()}',` + `'deployTimestamp': '${Date.now()}',`
+ `'filePathConfigs': '${JSON.stringify(filePathConfigs)}',` + `'filePathConfigs': ${JSON.stringify(filePathConfigs)},`
+ `'provider': 'GitHub'` + `'provider': 'GitHub'`
+ `}`; + `}`;
} }

View File

@ -148,8 +148,8 @@ function getFilePathsConfigs() {
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path'; const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
const DOCKERFILE_PATH_KEY = 'dockerfilePath'; const DOCKERFILE_PATH_KEY = 'dockerfilePath';
const CONTAINER_REG_KEY = 'containerRegistryServer'; const CONTAINER_REG_KEY = 'containerRegistryServer';
let inputManifestFiles = inputParams.manifests; let inputManifestFiles = inputParams.manifests || [];
filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles || ''; filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles;
let helmChartPath = process.env.HELM_CHART_PATH || ''; let helmChartPath = process.env.HELM_CHART_PATH || '';
filePathsConfig[HELM_CHART_KEY] = helmChartPath; filePathsConfig[HELM_CHART_KEY] = helmChartPath;
//Fetch labels from each image //Fetch labels from each image
@ -180,21 +180,26 @@ function getFilePathsConfigs() {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(`docker inspect call failed with: ${res.stderr.match(/(.*)\s*$/)[0]}`); throw new Error(`docker inspect call failed with: ${res.stderr.match(/(.*)\s*$/)[0]}`);
} }
resultObj = JSON.parse(res.stdout)[0]; if (res.stdout != null && res.stdout != '') {
resultObj = JSON.parse(res.stdout);
}
}); });
} }
catch (ex) { catch (ex) {
core.warning(`Failed to get dockerfile paths for image ${image.toString()} | ` + ex); core.warning(`Failed to get dockerfile paths for image ${image.toString()} | ` + ex);
} }
if (resultObj != null && resultObj.Config != null && resultObj.Config.Labels != null) { if (resultObj != null) {
if (resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY] != null) { resultObj = resultObj[0];
if (resultObj.Config != null && resultObj.Config.Labels != null && resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY] != null) {
buildConfigMap[DOCKERFILE_PATH_KEY] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY]; buildConfigMap[DOCKERFILE_PATH_KEY] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
} }
//Add CR server name to build config //Add CR server name to build config
buildConfigMap[CONTAINER_REG_KEY] = containerRegistryName; buildConfigMap[CONTAINER_REG_KEY] = containerRegistryName;
if (resultObj.Id != null) {
imageToBuildConfigMap[resultObj.Id] = buildConfigMap; imageToBuildConfigMap[resultObj.Id] = buildConfigMap;
} }
} }
}
filePathsConfig[BUILD_CONFIG_KEY] = imageToBuildConfigMap; filePathsConfig[BUILD_CONFIG_KEY] = imageToBuildConfigMap;
return Promise.resolve(filePathsConfig); return Promise.resolve(filePathsConfig);
}); });

View File

@ -38,7 +38,7 @@ export function getWorkflowAnnotationsJson(lastSuccessRunSha: string, workflowFi
+ `'lastSuccessRunCommit': '${lastSuccessRunSha}',` + `'lastSuccessRunCommit': '${lastSuccessRunSha}',`
+ `'branch': '${process.env.GITHUB_REF}',` + `'branch': '${process.env.GITHUB_REF}',`
+ `'deployTimestamp': '${Date.now()}',` + `'deployTimestamp': '${Date.now()}',`
+ `'filePathConfigs': '${JSON.stringify(filePathConfigs)}',` + `'filePathConfigs': ${JSON.stringify(filePathConfigs)},`
+ `'provider': 'GitHub'` + `'provider': 'GitHub'`
+ `}`; + `}`;
} }

View File

@ -139,8 +139,8 @@ export async function getFilePathsConfigs(): Promise<any> {
const DOCKERFILE_PATH_KEY = 'dockerfilePath'; const DOCKERFILE_PATH_KEY = 'dockerfilePath';
const CONTAINER_REG_KEY = 'containerRegistryServer'; const CONTAINER_REG_KEY = 'containerRegistryServer';
let inputManifestFiles = inputParams.manifests; let inputManifestFiles = inputParams.manifests || [];
filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles || ''; filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles;
let helmChartPath = process.env.HELM_CHART_PATH || ''; let helmChartPath = process.env.HELM_CHART_PATH || '';
filePathsConfig[HELM_CHART_KEY] = helmChartPath; filePathsConfig[HELM_CHART_KEY] = helmChartPath;
@ -179,23 +179,31 @@ export async function getFilePathsConfigs(): Promise<any> {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(`docker inspect call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`); throw new Error(`docker inspect call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`);
} }
resultObj = JSON.parse(res.stdout)[0];
if(res.stdout!= null && res.stdout != ''){
resultObj = JSON.parse(res.stdout);
}
}); });
} }
catch (ex) { catch (ex) {
core.warning(`Failed to get dockerfile paths for image ${image.toString()} | ` + ex); core.warning(`Failed to get dockerfile paths for image ${image.toString()} | ` + ex);
} }
if(resultObj != null && resultObj.Config != null && resultObj.Config.Labels != null ){ if(resultObj != null){
if(resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY] !=null){ resultObj = resultObj[0];
if(resultObj.Config != null && resultObj.Config.Labels != null && resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY] !=null){
buildConfigMap[DOCKERFILE_PATH_KEY] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY]; buildConfigMap[DOCKERFILE_PATH_KEY] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
} }
//Add CR server name to build config //Add CR server name to build config
buildConfigMap[CONTAINER_REG_KEY] = containerRegistryName; buildConfigMap[CONTAINER_REG_KEY] = containerRegistryName;
if(resultObj.Id != null){
imageToBuildConfigMap[resultObj.Id] = buildConfigMap; imageToBuildConfigMap[resultObj.Id] = buildConfigMap;
} }
} }
}
filePathsConfig[BUILD_CONFIG_KEY] = imageToBuildConfigMap; filePathsConfig[BUILD_CONFIG_KEY] = imageToBuildConfigMap;
return Promise.resolve(filePathsConfig); return Promise.resolve(filePathsConfig);