Bug fix for dockerfile path for default (#96)

* Bug fix for dockerfile path link
This commit is contained in:
Jyotsna 2020-12-30 21:55:39 +05:30 коммит произвёл GitHub
Родитель 04921d7d06
Коммит 4bd69f56a9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 48 добавлений и 43 удалений

Просмотреть файл

@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrentTime = exports.getRandomInt = exports.sleep = exports.getDeploymentConfig = exports.annotateChildPods = exports.getWorkflowFilePath = exports.getLastSuccessfulRunSha = exports.checkForErrors = exports.isEqual = exports.getExecutableExtension = void 0;
exports.isHttpUrl = exports.getCurrentTime = exports.getRandomInt = exports.sleep = exports.getDeploymentConfig = exports.annotateChildPods = exports.getWorkflowFilePath = exports.getLastSuccessfulRunSha = exports.checkForErrors = exports.isEqual = exports.getExecutableExtension = void 0;
const os = require("os");
const core = require("@actions/core");
const githubClient_1 = require("../githubClient");
@ -149,14 +149,8 @@ function getDeploymentConfig() {
let imageDockerfilePathMap = {};
//Fetching from image label if available
for (const image of imageNames) {
let imageConfig, imageInspectResult;
try {
yield checkDockerPath();
var dockerExec = new docker_object_model_1.DockerExec('docker');
dockerExec.pull(image, [], true);
imageInspectResult = dockerExec.inspect(image, [], true);
imageConfig = JSON.parse(imageInspectResult)[0];
imageDockerfilePathMap[image] = getDockerfilePath(imageConfig);
imageDockerfilePathMap[image] = yield getDockerfilePath(image);
}
catch (ex) {
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
@ -191,24 +185,34 @@ function checkDockerPath() {
}
});
}
function getDockerfilePath(imageConfig) {
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
const ref = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
let pathLabel, pathLink, pathValue = '';
if (imageConfig) {
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
if (pathValue.startsWith('./')) { //if it is relative filepath convert to link from current repo
pathLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
pathValue = pathLink;
}
else {
pathValue = pathLabel;
function getDockerfilePath(image) {
return __awaiter(this, void 0, void 0, function* () {
let imageConfig, imageInspectResult;
var dockerExec = new docker_object_model_1.DockerExec('docker');
yield checkDockerPath();
dockerExec.pull(image, [], true);
imageInspectResult = dockerExec.inspect(image, [], true);
imageConfig = JSON.parse(imageInspectResult)[0];
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
const ref = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
let pathValue = '';
if (imageConfig) {
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
const pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
if (!isHttpUrl(pathLabel)) { //if it is not an http url then convert to link from current repo and ref
let pathLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
pathValue = pathLink;
}
else {
pathValue = pathLabel;
}
}
}
else {
pathValue = '';
}
}
return pathValue;
return Promise.resolve(pathValue);
});
}
function isHttpUrl(url) {
const HTTP_REGEX = /^https?:\/\/.*$/;
return HTTP_REGEX.test(url);
}
exports.isHttpUrl = isHttpUrl;

Просмотреть файл

@ -147,15 +147,8 @@ export async function getDeploymentConfig(): Promise<DeploymentConfig> {
//Fetching from image label if available
for (const image of imageNames) {
let imageConfig: any, imageInspectResult: string;
try {
await checkDockerPath();
var dockerExec: DockerExec = new DockerExec('docker');
dockerExec.pull(image, [], true);
imageInspectResult = dockerExec.inspect(image, [], true);
imageConfig = JSON.parse(imageInspectResult)[0];
imageDockerfilePathMap[image] = getDockerfilePath(imageConfig);
imageDockerfilePathMap[image] = await getDockerfilePath(image);
}
catch (ex) {
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
@ -190,24 +183,32 @@ async function checkDockerPath() {
}
}
function getDockerfilePath(imageConfig: any): string {
async function getDockerfilePath(image: any): Promise<string> {
let imageConfig: any, imageInspectResult: string;
var dockerExec: DockerExec = new DockerExec('docker');
await checkDockerPath();
dockerExec.pull(image, [], true);
imageInspectResult = dockerExec.inspect(image, [], true);
imageConfig = JSON.parse(imageInspectResult)[0];
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
const ref: string = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
let pathLabel: string, pathLink: string, pathValue: string = '';
let pathValue: string = '';
if (imageConfig) {
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
if (pathValue.startsWith('./')) { //if it is relative filepath convert to link from current repo
pathLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
const pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
if (!isHttpUrl(pathLabel)) { //if it is not an http url then convert to link from current repo and ref
let pathLink: string = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
pathValue = pathLink;
}
else {
pathValue = pathLabel;
}
}
else {
pathValue = '';
}
}
return pathValue;
return Promise.resolve(pathValue);
}
export function isHttpUrl(url: string) {
const HTTP_REGEX = /^https?:\/\/.*$/;
return HTTP_REGEX.test(url);
}