mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-08 14:22:16 +08:00
* Make pulling of images switchable (#178) * Make namespace annotation switchable (#177) * Bump tmpl from 1.0.4 to 1.0.5 (#152) Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5. - [Release notes](https://github.com/daaku/nodejs-tmpl/releases) - [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5) --- updated-dependencies: - dependency-name: tmpl dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ansi-regex from 5.0.0 to 5.0.1 (#166) Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 5.0.0 to 5.0.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v5.0.0...v5.0.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump minimist from 1.2.5 to 1.2.6 (#175) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add directory functionality (#181) * Add node modules and compiled JavaScript from main Co-authored-by: Jan Röhrich <roehrijn@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jaiveer Katariya <35347859+jaiveerk@users.noreply.github.com> Co-authored-by: Oliver King <oking3@uncc.edu>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
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 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 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,
|
|
});
|
|
}
|
|
|
|
async function getDockerfilePath(image: any): Promise<string> {
|
|
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";
|
|
|
|
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.");
|
|
}
|
|
}
|