mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-16 19:42:19 +08:00
Added reading dockerfile from env var, code cleanup
This commit is contained in:
parent
9fa045d9cf
commit
7ab8f38c56
@ -38,7 +38,7 @@ const getAllPodsMock = {
|
|||||||
|
|
||||||
const getNamespaceMock = {
|
const getNamespaceMock = {
|
||||||
'code': 0,
|
'code': 0,
|
||||||
'stdout': '{"apiVersion": "v1","kind": "Namespace","metadata": {"annotations": {"githubWorkflow_c11401b9d232942bac19cbc5bc32b42d": "{\'run\': \'202489005\',\'repository\': \'testUser/hello-kubernetes\',\'workflow\': \'workflow1\',\'jobName\': \'build-and-deploy\',\'createdBy\': \'testUser\',\'runUri\': \'https://github.com/testUser/hello-kubernetes/actions/runs/202489005\',\'commit\': \'currentCommit\',\'lastSuccessRunCommit\': \'lastCommit\',\'branch\': \'refs/heads/branch-rename\',\'deployTimestamp\': \'1597062957973\',\'filePathConfigs\': \'{}\',\'provider\': \'GitHub\'}","githubWorkflow_21fd7a597282ca5adc05ba99018b3706": "{\'run\': \'202504411\',\'repository\': \'testUser/hello-kubernetes\',\'workflow\': \'workflowMaster\',\'jobName\': \'build-and-deploy\',\'createdBy\': \'testUser\',\'runUri\': \'https://github.com/testUser/hello-kubernetes/actions/runs/202504411\',\'commit\': \'currentCommit1\',\'lastSuccessRunCommit\': \'NA\',\'branch\': \'refs/heads/master\',\'deployTimestamp\': \'1597063919873\',\'filePathConfigs\': \'{}\',\'provider\': \'GitHub\'}"}},"spec": {"finalizers": ["kubernetes"]},"status": {"phase": "Active"}}'
|
'stdout': '{"apiVersion": "v1","kind": "Namespace","metadata": {"annotations": {"githubWorkflow_c11401b9d232942bac19cbc5bc32b42d": "{\'run\': \'202489005\',\'repository\': \'testUser/hello-kubernetes\',\'workflow\': \'workflow1\',\'jobName\': \'build-and-deploy\',\'createdBy\': \'testUser\',\'runUri\': \'https://github.com/testUser/hello-kubernetes/actions/runs/202489005\',\'commit\': \'currentCommit\',\'lastSuccessRunCommit\': \'lastCommit\',\'branch\': \'refs/heads/branch-rename\',\'deployTimestamp\': \'1597062957973\',\'dockerfilePaths\': \'{}\',\'manifestsPaths\': \'[]\',\'helmChartPaths\': \'[]\',\'provider\': \'GitHub\'}","githubWorkflow_21fd7a597282ca5adc05ba99018b3706": "{\'run\': \'202504411\',\'repository\': \'testUser/hello-kubernetes\',\'workflow\': \'workflowMaster\',\'jobName\': \'build-and-deploy\',\'createdBy\': \'testUser\',\'runUri\': \'https://github.com/testUser/hello-kubernetes/actions/runs/202504411\',\'commit\': \'currentCommit1\',\'lastSuccessRunCommit\': \'NA\',\'branch\': \'refs/heads/master\',\'deployTimestamp\': \'1597063919873\',\'filePathConfigs\': \'{}\',\'provider\': \'GitHub\'}"}},"spec": {"finalizers": ["kubernetes"]},"status": {"phase": "Active"}}'
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWorkflowsUrlResponse = {
|
const getWorkflowsUrlResponse = {
|
||||||
|
|||||||
@ -150,14 +150,24 @@ function getFilePathsConfigs() {
|
|||||||
filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles;
|
filePathsConfig[MANIFEST_PATHS_KEY] = inputManifestFiles;
|
||||||
let helmChartPaths = (process.env.HELM_CHART_PATHS && process.env.HELM_CHART_PATHS.split('\n').filter(path => path != "")) || [];
|
let helmChartPaths = (process.env.HELM_CHART_PATHS && process.env.HELM_CHART_PATHS.split('\n').filter(path => path != "")) || [];
|
||||||
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;
|
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;
|
||||||
//Fetch labels from each image
|
//Parsing dockerfile paths for images
|
||||||
let imageNames = core.getInput('images').split('\n');
|
let imageNames = core.getInput('images').split('\n');
|
||||||
let imageDockerfilePathList = [];
|
let imageDockerfilePathMap = {};
|
||||||
|
let pathKey, pathVal;
|
||||||
|
//Fetching from env var if available
|
||||||
|
let dockerfilePathsList = (process.env.DOCKERFILEPATHS && process.env.DOCKERFILEPATHS.split('\n')) || [];
|
||||||
|
dockerfilePathsList.forEach(path => {
|
||||||
|
if (path) {
|
||||||
|
pathKey = path.split(' ')[0];
|
||||||
|
pathVal = path.split(' ')[1];
|
||||||
|
imageDockerfilePathMap[pathKey] = pathVal;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//Fetching from image lable if available
|
||||||
for (const image of imageNames) {
|
for (const image of imageNames) {
|
||||||
let args = [image];
|
let args = [image];
|
||||||
let resultObj;
|
let resultObj;
|
||||||
let containerRegistryName = image;
|
let containerRegistryName = image;
|
||||||
let imageDockerfilePathObj = {};
|
|
||||||
try {
|
try {
|
||||||
let usrname = process.env.CR_USERNAME || null;
|
let usrname = process.env.CR_USERNAME || null;
|
||||||
let pwd = process.env.CR_PASSWORD || null;
|
let pwd = process.env.CR_PASSWORD || null;
|
||||||
@ -189,15 +199,17 @@ function getFilePathsConfigs() {
|
|||||||
if (resultObj) {
|
if (resultObj) {
|
||||||
resultObj = resultObj[0];
|
resultObj = resultObj[0];
|
||||||
if ((resultObj.Config) && (resultObj.Config.Labels) && (resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
|
if ((resultObj.Config) && (resultObj.Config.Labels) && (resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])) {
|
||||||
imageDockerfilePathObj[image] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
pathVal = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
imageDockerfilePathObj[image] = 'Not available';
|
pathVal = 'Not available';
|
||||||
|
}
|
||||||
|
if (!imageDockerfilePathMap[image]) { //If (image : someVal) does not exist from env var parsing then add
|
||||||
|
imageDockerfilePathMap[image] = pathVal;
|
||||||
}
|
}
|
||||||
imageDockerfilePathList.push(imageDockerfilePathObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filePathsConfig[DOCKERFILE_PATH_KEY] = imageDockerfilePathList;
|
filePathsConfig[DOCKERFILE_PATH_KEY] = imageDockerfilePathMap;
|
||||||
return Promise.resolve(filePathsConfig);
|
return Promise.resolve(filePathsConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import { GitHubClient } from '../githubClient';
|
|||||||
import { StatusCodes } from "./httpClient";
|
import { StatusCodes } from "./httpClient";
|
||||||
import * as exec from "./exec";
|
import * as exec from "./exec";
|
||||||
import * as inputParams from "../input-parameters";
|
import * as inputParams from "../input-parameters";
|
||||||
import { Z_FILTERED } from 'zlib';
|
|
||||||
|
|
||||||
export function getExecutableExtension(): string {
|
export function getExecutableExtension(): string {
|
||||||
if (os.type().match(/^Win/)) {
|
if (os.type().match(/^Win/)) {
|
||||||
@ -144,16 +143,26 @@ export async function getFilePathsConfigs(): Promise<any> {
|
|||||||
let helmChartPaths = (process.env.HELM_CHART_PATHS && process.env.HELM_CHART_PATHS.split('\n').filter(path => path != "")) || [];
|
let helmChartPaths = (process.env.HELM_CHART_PATHS && process.env.HELM_CHART_PATHS.split('\n').filter(path => path != "")) || [];
|
||||||
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;
|
filePathsConfig[HELM_CHART_KEY] = helmChartPaths;
|
||||||
|
|
||||||
//Fetch labels from each image
|
//Parsing dockerfile paths for images
|
||||||
|
|
||||||
let imageNames = core.getInput('images').split('\n');
|
let imageNames = core.getInput('images').split('\n');
|
||||||
let imageDockerfilePathList: any = [];
|
let imageDockerfilePathMap: any = {};
|
||||||
|
let pathKey: any, pathVal: any;
|
||||||
|
|
||||||
|
//Fetching from env var if available
|
||||||
|
let dockerfilePathsList: any[] = (process.env.DOCKERFILEPATHS && process.env.DOCKERFILEPATHS.split('\n')) || [];
|
||||||
|
dockerfilePathsList.forEach(path => {
|
||||||
|
if(path){
|
||||||
|
pathKey = path.split(' ')[0];
|
||||||
|
pathVal = path.split(' ')[1];
|
||||||
|
imageDockerfilePathMap[pathKey] = pathVal;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//Fetching from image lable if available
|
||||||
for(const image of imageNames){
|
for(const image of imageNames){
|
||||||
let args: string[] = [image];
|
let args: string[] = [image];
|
||||||
let resultObj: any;
|
let resultObj: any;
|
||||||
let containerRegistryName = image;
|
let containerRegistryName = image;
|
||||||
let imageDockerfilePathObj: any = {};
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
let usrname = process.env.CR_USERNAME || null;
|
let usrname = process.env.CR_USERNAME || null;
|
||||||
@ -191,16 +200,18 @@ export async function getFilePathsConfigs(): Promise<any> {
|
|||||||
if(resultObj){
|
if(resultObj){
|
||||||
resultObj = resultObj[0];
|
resultObj = resultObj[0];
|
||||||
if((resultObj.Config) && (resultObj.Config.Labels) && (resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])){
|
if((resultObj.Config) && (resultObj.Config.Labels) && (resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY])){
|
||||||
imageDockerfilePathObj[image] = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
pathVal = resultObj.Config.Labels[DOCKERFILE_PATH_LABEL_KEY];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
imageDockerfilePathObj[image] = 'Not available';
|
pathVal = 'Not available';
|
||||||
|
}
|
||||||
|
if(!imageDockerfilePathMap[image]){ //If (image : someVal) does not exist from env var parsing then add
|
||||||
|
imageDockerfilePathMap[image] = pathVal;
|
||||||
}
|
}
|
||||||
imageDockerfilePathList.push(imageDockerfilePathObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filePathsConfig[DOCKERFILE_PATH_KEY] = imageDockerfilePathList;
|
filePathsConfig[DOCKERFILE_PATH_KEY] = imageDockerfilePathMap;
|
||||||
|
|
||||||
return Promise.resolve(filePathsConfig);
|
return Promise.resolve(filePathsConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user