now patches local dependencies for multitag dependent docker builds

This commit is contained in:
Philipp Kunz 2016-06-05 14:27:56 +02:00
parent e3c1ac1897
commit ee54cbf78d
3 changed files with 102 additions and 44 deletions

View File

@ -1,8 +1,8 @@
export declare let build: () => any; export declare let build: () => any;
export declare let readDockerfiles: () => any; export declare let readDockerfiles: () => any;
export declare let cleanTagsArrayFunction: (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]) => string[];
export declare let sortDockerfiles: (sortableArrayArg: Dockerfile[]) => any; export declare let sortDockerfiles: (sortableArrayArg: Dockerfile[]) => any;
export declare let buildDockerfiles: () => any; export declare let mapDockerfiles: (sortedArray: Dockerfile[]) => any;
export declare let buildDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
export declare class Dockerfile { export declare class Dockerfile {
filePath: string; filePath: string;
repo: string; repo: string;
@ -10,7 +10,10 @@ export declare class Dockerfile {
cleanTag: string; cleanTag: string;
buildTag: string; buildTag: string;
content: string; content: string;
patchedContent: string;
baseImage: string; baseImage: string;
localBaseImageDependent: boolean;
localBaseDockerfile: Dockerfile;
constructor(options: { constructor(options: {
filePath?: string; filePath?: string;
fileContents?: string | Buffer; fileContents?: string | Buffer;
@ -18,7 +21,10 @@ export declare class Dockerfile {
}); });
build(): void; build(): void;
push(): void; push(): void;
patchContents(): void;
restoreContents(): void;
} }
export declare let dockerFileVersion: (dockerfileNameArg: string) => string; export declare let dockerFileVersion: (dockerfileNameArg: string) => string;
export declare let dockerBaseImage: (dockerfileContentArg: string) => string; export declare let dockerBaseImage: (dockerfileContentArg: string) => string;
export declare let dockerTag: (repoArg: string, versionArg: string) => string; export declare let dockerTag: (repoArg: string, versionArg: string) => string;
export declare let cleanTagsArrayFunction: (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]) => string[];

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,10 @@ import * as NpmciEnv from "./npmci.env";
export let build = function(){ export let build = function(){
let done = plugins.q.defer(); let done = plugins.q.defer();
readDockerfiles()
.then(sortDockerfiles)
.then(mapDockerfiles)
.then(buildDockerfiles);
return done.promise; return done.promise;
} }
@ -24,36 +27,21 @@ export let readDockerfiles = function(){
return done.promise; return done.promise;
} }
export let cleanTagsArrayFunction = function(dockerfileArrayArg:Dockerfile[],trackingArrayArg:Dockerfile[]):string[]{
let cleanTagsArray:string[] = [];
dockerfileArrayArg.forEach(function(dockerfileArg){
if(trackingArrayArg.indexOf(dockerfileArg) == -1){
cleanTagsArray.push(dockerfileArg.cleanTag);
}
});
return cleanTagsArray;
}
export let sortDockerfiles = function(sortableArrayArg:Dockerfile[]){ export let sortDockerfiles = function(sortableArrayArg:Dockerfile[]){
let done = plugins.q.defer(); let done = plugins.q.defer();
let sortedArray:Dockerfile[] = []; let sortedArray:Dockerfile[] = [];
let trackingArray:Dockerfile[] = []; let trackingArray:Dockerfile[] = [];
let sorterFunctionCounter:number = 0; let sorterFunctionCounter:number = 0;
console.log(sortableArrayArg);
console.log(sortedArray);
let sorterFunction = function(){ let sorterFunction = function(){
plugins.beautylog.log("++++++++++++++++++++++++++++++++++++++++++++++");
console.log(sorterFunctionCounter);
sortableArrayArg.forEach((dockerfileArg)=>{ sortableArrayArg.forEach((dockerfileArg)=>{
console.log(dockerfileArg);
let cleanTags = cleanTagsArrayFunction(sortableArrayArg,trackingArray); let cleanTags = cleanTagsArrayFunction(sortableArrayArg,trackingArray);
console.log(cleanTags);
if(cleanTags.indexOf(dockerfileArg.baseImage) == -1 && trackingArray.indexOf(dockerfileArg) == -1){ if(cleanTags.indexOf(dockerfileArg.baseImage) == -1 && trackingArray.indexOf(dockerfileArg) == -1){
sortedArray.push(dockerfileArg); sortedArray.push(dockerfileArg);
trackingArray.push(dockerfileArg); trackingArray.push(dockerfileArg);
} } else if(cleanTags.indexOf(dockerfileArg.baseImage) != -1){
dockerfileArg.localBaseImageDependent = true;
};
}); });
plugins.beautylog.info(sortedArray.length.toString());
if(sortableArrayArg.length == sortedArray.length){ if(sortableArrayArg.length == sortedArray.length){
done.resolve(sortedArray); done.resolve(sortedArray);
} else if (sorterFunctionCounter < 10) { } else if (sorterFunctionCounter < 10) {
@ -63,11 +51,27 @@ export let sortDockerfiles = function(sortableArrayArg:Dockerfile[]){
} }
sorterFunction(); sorterFunction();
return done.promise; return done.promise;
};
export let mapDockerfiles = function(sortedArray:Dockerfile[]){
let done = plugins.q.defer();
sortedArray.forEach((dockerfileArg) => {
if(dockerfileArg.localBaseImageDependent){
let dockerfileDependency:Dockerfile;
sortedArray.forEach((dockfile2:Dockerfile) => {
if(dockfile2.cleanTag == dockerfileArg.baseImage){
dockerfileArg.localBaseDockerfile = dockfile2;
}
})
};
});
done.resolve(sortedArray);
return done.promise;
} }
export let buildDockerfiles = function(){ export let buildDockerfiles = function(sortedArrayArg:Dockerfile[]){
let done = plugins.q.defer(); let done = plugins.q.defer();
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){ sortedArrayArg.forEach(function(dockerfileArg){
dockerfileArg.build(); dockerfileArg.build();
}) })
done.resolve(); done.resolve();
@ -81,7 +85,10 @@ export class Dockerfile {
cleanTag:string; cleanTag:string;
buildTag:string; buildTag:string;
content:string; content:string;
patchedContent:string;
baseImage:string; baseImage:string;
localBaseImageDependent:boolean;
localBaseDockerfile:Dockerfile;
constructor(options:{filePath?:string,fileContents?:string|Buffer,read?:boolean}){ constructor(options:{filePath?:string,fileContents?:string|Buffer,read?:boolean}){
this.filePath = options.filePath; this.filePath = options.filePath;
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo; this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
@ -91,15 +98,18 @@ export class Dockerfile {
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath)); this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
}; };
this.baseImage = dockerBaseImage(this.content); this.baseImage = dockerBaseImage(this.content);
this.localBaseImageDependent = false;
}; };
build(){ build(){
if(!this.buildTag){ if(!this.buildTag){
this.patchContents();
let tag = dockerTag(this.repo,this.version); let tag = dockerTag(this.repo,this.version);
plugins.shelljs.exec("docker build -t " + tag + " -f " + this.filePath + " ."); plugins.shelljs.exec("docker build -t " + tag + " -f " + this.filePath + " .");
this.buildTag = tag; this.buildTag = tag;
NpmciEnv.dockerFilesBuilt.push(this); NpmciEnv.dockerFilesBuilt.push(this);
this.restoreContents();
} else { } else {
plugins.beautylog.error("This Dockerfile already has been built!"); plugins.beautylog.error("This Dockerfile has already been built!");
} }
}; };
@ -110,6 +120,12 @@ export class Dockerfile {
plugins.beautylog.error("Dockerfile hasn't been built yet!"); plugins.beautylog.error("Dockerfile hasn't been built yet!");
} }
} }
patchContents(){
};
restoreContents(){
};
} }
export let dockerFileVersion = function(dockerfileNameArg:string):string{ export let dockerFileVersion = function(dockerfileNameArg:string):string{
@ -144,3 +160,13 @@ export let dockerTag = function(repoArg:string,versionArg:string):string{
tagString = registry + "/" + repo + ":" + version; tagString = registry + "/" + repo + ":" + version;
return tagString; return tagString;
}; };
export let cleanTagsArrayFunction = function(dockerfileArrayArg:Dockerfile[],trackingArrayArg:Dockerfile[]):string[]{
let cleanTagsArray:string[] = [];
dockerfileArrayArg.forEach(function(dockerfileArg){
if(trackingArrayArg.indexOf(dockerfileArg) == -1){
cleanTagsArray.push(dockerfileArg.cleanTag);
}
});
return cleanTagsArray;
}