mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-11 16:52:18 +08:00
parent
5920a5b1b9
commit
d4a7d27ca4
@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
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 os = require("os");
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const githubClient_1 = require("../githubClient");
|
const githubClient_1 = require("../githubClient");
|
||||||
@ -151,12 +151,7 @@ function getDeploymentConfig() {
|
|||||||
for (const image of imageNames) {
|
for (const image of imageNames) {
|
||||||
let imageConfig, imageInspectResult;
|
let imageConfig, imageInspectResult;
|
||||||
try {
|
try {
|
||||||
yield checkDockerPath();
|
imageDockerfilePathMap[image] = yield getDockerfilePath(image);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
|
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
|
||||||
@ -191,24 +186,34 @@ function checkDockerPath() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getDockerfilePath(imageConfig) {
|
function getDockerfilePath(image) {
|
||||||
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const ref = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
|
let imageConfig, imageInspectResult;
|
||||||
let pathLabel, pathLink, pathValue = '';
|
var dockerExec = new docker_object_model_1.DockerExec('docker');
|
||||||
if (imageConfig) {
|
yield checkDockerPath();
|
||||||
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
|
dockerExec.pull(image, [], true);
|
||||||
pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
imageInspectResult = dockerExec.inspect(image, [], true);
|
||||||
if (pathValue.startsWith('./')) { //if it is relative filepath convert to link from current repo
|
imageConfig = JSON.parse(imageInspectResult)[0];
|
||||||
pathLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
|
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
|
||||||
pathValue = pathLink;
|
const ref = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
|
||||||
}
|
let pathValue = '';
|
||||||
else {
|
if (imageConfig) {
|
||||||
pathValue = pathLabel;
|
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 {
|
return pathValue;
|
||||||
pathValue = '';
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
return pathValue;
|
|
||||||
}
|
}
|
||||||
|
function isHttpUrl(url) {
|
||||||
|
const HTTP_REGEX = /^https?:\/\/.*$/;
|
||||||
|
return HTTP_REGEX.test(url);
|
||||||
|
}
|
||||||
|
exports.isHttpUrl = isHttpUrl;
|
||||||
|
|||||||
@ -150,12 +150,7 @@ export async function getDeploymentConfig(): Promise<DeploymentConfig> {
|
|||||||
let imageConfig: any, imageInspectResult: string;
|
let imageConfig: any, imageInspectResult: string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await checkDockerPath();
|
imageDockerfilePathMap[image] = await getDockerfilePath(image);
|
||||||
var dockerExec: DockerExec = new DockerExec('docker');
|
|
||||||
dockerExec.pull(image, [], true);
|
|
||||||
imageInspectResult = dockerExec.inspect(image, [], true);
|
|
||||||
imageConfig = JSON.parse(imageInspectResult)[0];
|
|
||||||
imageDockerfilePathMap[image] = getDockerfilePath(imageConfig);
|
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
|
core.warning(`Failed to get dockerfile path for image ${image.toString()} | ` + ex);
|
||||||
@ -190,25 +185,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 DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path';
|
||||||
const ref: string = process.env.GITHUB_REF && process.env.GITHUB_REF.replace('refs/heads/', '').replace('refs/tags/', '');
|
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) {
|
||||||
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
|
if ((imageConfig.Config) && (imageConfig.Config.Labels) && (imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
|
||||||
pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
const pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
||||||
if (pathValue.startsWith('./')) { //if it is relative filepath convert to link from current repo
|
if (!isHttpUrl(pathLabel)) { //if it is not an http url then convert to link from current repo and ref
|
||||||
pathLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
|
let pathLink: string = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${ref}/${pathLabel}`;
|
||||||
pathValue = pathLink;
|
pathValue = pathLink;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pathValue = pathLabel;
|
pathValue = pathLabel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
pathValue = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return pathValue;
|
return pathValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isHttpUrl(url: string) {
|
||||||
|
const HTTP_REGEX = /^https?:\/\/.*$/;
|
||||||
|
return HTTP_REGEX.test(url);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user