mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-25 22:29:26 +08:00
v4 new release (#205)
* Add missing API switch for GHES (#200) * Vidya reddy/prettier code (#203) * Add node modules and compiled JavaScript from main Co-authored-by: nv35 <76777923+nv35@users.noreply.github.com> Co-authored-by: Vidya <59590642+Vidya2606@users.noreply.github.com> Co-authored-by: Oliver King <oking3@uncc.edu>
This commit is contained in:
committed by
GitHub
parent
d7506e9702
commit
6ecb006985
@@ -1,75 +1,75 @@
|
||||
import * as io from "@actions/io";
|
||||
import { DeploymentConfig } from "../types/deploymentConfig";
|
||||
import * as core from "@actions/core";
|
||||
import { DockerExec } from "../types/docker";
|
||||
import { getNormalizedPath } from "./githubUtils";
|
||||
import * as io from '@actions/io'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import * as core from '@actions/core'
|
||||
import {DockerExec} from '../types/docker'
|
||||
import {getNormalizedPath} from './githubUtils'
|
||||
|
||||
export async function getDeploymentConfig(): Promise<DeploymentConfig> {
|
||||
let helmChartPaths: string[] =
|
||||
process.env?.HELM_CHART_PATHS?.split(";").filter((path) => path != "") ||
|
||||
[];
|
||||
helmChartPaths = helmChartPaths.map((helmchart) =>
|
||||
getNormalizedPath(helmchart.trim())
|
||||
);
|
||||
let helmChartPaths: string[] =
|
||||
process.env?.HELM_CHART_PATHS?.split(';').filter((path) => path != '') ||
|
||||
[]
|
||||
helmChartPaths = helmChartPaths.map((helmchart) =>
|
||||
getNormalizedPath(helmchart.trim())
|
||||
)
|
||||
|
||||
let inputManifestFiles: string[] =
|
||||
core
|
||||
.getInput("manifests")
|
||||
.split(/[\n,;]+/)
|
||||
.filter((manifest) => manifest.trim().length > 0) || [];
|
||||
if (helmChartPaths?.length == 0) {
|
||||
inputManifestFiles = inputManifestFiles.map((manifestFile) =>
|
||||
getNormalizedPath(manifestFile)
|
||||
);
|
||||
}
|
||||
let inputManifestFiles: string[] =
|
||||
core
|
||||
.getInput('manifests')
|
||||
.split(/[\n,;]+/)
|
||||
.filter((manifest) => manifest.trim().length > 0) || []
|
||||
if (helmChartPaths?.length == 0) {
|
||||
inputManifestFiles = inputManifestFiles.map((manifestFile) =>
|
||||
getNormalizedPath(manifestFile)
|
||||
)
|
||||
}
|
||||
|
||||
const imageNames = core.getInput("images").split("\n") || [];
|
||||
const imageDockerfilePathMap: { [id: string]: string } = {};
|
||||
const imageNames = core.getInput('images').split('\n') || []
|
||||
const imageDockerfilePathMap: {[id: string]: string} = {}
|
||||
|
||||
const pullImages = !(core.getInput("pull-images").toLowerCase() === "false");
|
||||
if (pullImages) {
|
||||
//Fetching from image label if available
|
||||
for (const image of imageNames) {
|
||||
try {
|
||||
imageDockerfilePathMap[image] = await getDockerfilePath(image);
|
||||
} catch (ex) {
|
||||
core.warning(
|
||||
`Failed to get dockerfile path for image ${image.toString()}: ${ex} `
|
||||
);
|
||||
const pullImages = !(core.getInput('pull-images').toLowerCase() === 'false')
|
||||
if (pullImages) {
|
||||
//Fetching from image label if available
|
||||
for (const image of imageNames) {
|
||||
try {
|
||||
imageDockerfilePathMap[image] = await getDockerfilePath(image)
|
||||
} catch (ex) {
|
||||
core.warning(
|
||||
`Failed to get dockerfile path for image ${image.toString()}: ${ex} `
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(<DeploymentConfig>{
|
||||
manifestFilePaths: inputManifestFiles,
|
||||
helmChartFilePaths: helmChartPaths,
|
||||
dockerfilePaths: imageDockerfilePathMap,
|
||||
});
|
||||
return Promise.resolve(<DeploymentConfig>{
|
||||
manifestFilePaths: inputManifestFiles,
|
||||
helmChartFilePaths: helmChartPaths,
|
||||
dockerfilePaths: imageDockerfilePathMap
|
||||
})
|
||||
}
|
||||
|
||||
async function getDockerfilePath(image: any): Promise<string> {
|
||||
await checkDockerPath();
|
||||
const dockerExec: DockerExec = new DockerExec("docker");
|
||||
await dockerExec.pull(image, [], false);
|
||||
await checkDockerPath()
|
||||
const dockerExec: DockerExec = new DockerExec('docker')
|
||||
await dockerExec.pull(image, [], false)
|
||||
|
||||
const imageInspectResult: string = await dockerExec.inspect(image, [], false);
|
||||
const imageConfig = JSON.parse(imageInspectResult)[0];
|
||||
const DOCKERFILE_PATH_LABEL_KEY = "dockerfile-path";
|
||||
const imageInspectResult: string = await dockerExec.inspect(image, [], false)
|
||||
const imageConfig = JSON.parse(imageInspectResult)[0]
|
||||
const DOCKERFILE_PATH_LABEL_KEY = 'dockerfile-path'
|
||||
|
||||
let pathValue: string = "";
|
||||
if (
|
||||
imageConfig?.Config?.Labels &&
|
||||
imageConfig?.Config?.Labels[DOCKERFILE_PATH_LABEL_KEY]
|
||||
) {
|
||||
const pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
||||
pathValue = getNormalizedPath(pathLabel);
|
||||
}
|
||||
return Promise.resolve(pathValue);
|
||||
let pathValue: string = ''
|
||||
if (
|
||||
imageConfig?.Config?.Labels &&
|
||||
imageConfig?.Config?.Labels[DOCKERFILE_PATH_LABEL_KEY]
|
||||
) {
|
||||
const pathLabel = imageConfig.Config.Labels[DOCKERFILE_PATH_LABEL_KEY]
|
||||
pathValue = getNormalizedPath(pathLabel)
|
||||
}
|
||||
return Promise.resolve(pathValue)
|
||||
}
|
||||
|
||||
export async function checkDockerPath() {
|
||||
const dockerPath = await io.which("docker", false);
|
||||
if (!dockerPath) {
|
||||
throw new Error("Docker is not installed.");
|
||||
}
|
||||
const dockerPath = await io.which('docker', false)
|
||||
if (!dockerPath) {
|
||||
throw new Error('Docker is not installed.')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user