fix tagging logic
This commit is contained in:
parent
11c0341c76
commit
2f827a7696
17
dist/npmci.build.docker.d.ts
vendored
17
dist/npmci.build.docker.d.ts
vendored
@ -3,20 +3,20 @@ export declare let readDockerfiles: () => any;
|
|||||||
export declare let sortDockerfiles: (sortableArrayArg: Dockerfile[]) => any;
|
export declare let sortDockerfiles: (sortableArrayArg: Dockerfile[]) => any;
|
||||||
export declare let mapDockerfiles: (sortedArray: Dockerfile[]) => any;
|
export declare let mapDockerfiles: (sortedArray: Dockerfile[]) => any;
|
||||||
export declare let buildDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
export declare let buildDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
||||||
export declare let pushDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
export declare let pushDockerfiles: (sortedArrayArg: Dockerfile[], regsitryArg?: string) => any;
|
||||||
export declare let pullDockerfileImages: (sortableArrayArg: Dockerfile[]) => any;
|
export declare let pullDockerfileImages: (sortableArrayArg: Dockerfile[], registryArg?: string) => any;
|
||||||
export declare let testDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
export declare let testDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
||||||
export declare let releaseDockerfiles: (sortedArrayArg: Dockerfile[]) => any;
|
export declare let releaseDockerfiles: (sortedArrayArg: Dockerfile[], registryArg?: any) => any;
|
||||||
export declare class Dockerfile {
|
export declare class Dockerfile {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
version: string;
|
version: string;
|
||||||
cleanTag: string;
|
cleanTag: string;
|
||||||
buildTag: string;
|
buildTag: string;
|
||||||
|
testTag: string;
|
||||||
releaseTag: string;
|
releaseTag: string;
|
||||||
containerName: string;
|
containerName: string;
|
||||||
content: string;
|
content: string;
|
||||||
patchedContent: string;
|
|
||||||
baseImage: string;
|
baseImage: string;
|
||||||
localBaseImageDependent: boolean;
|
localBaseImageDependent: boolean;
|
||||||
localBaseDockerfile: Dockerfile;
|
localBaseDockerfile: Dockerfile;
|
||||||
@ -26,15 +26,12 @@ export declare class Dockerfile {
|
|||||||
read?: boolean;
|
read?: boolean;
|
||||||
});
|
});
|
||||||
build(): any;
|
build(): any;
|
||||||
push(): any;
|
push(registryArg: string): any;
|
||||||
pull(): void;
|
pull(registryArg: string): void;
|
||||||
test(): void;
|
test(): void;
|
||||||
release(): void;
|
|
||||||
getId(): string;
|
getId(): string;
|
||||||
patchContents(): any;
|
|
||||||
restoreContents(): any;
|
|
||||||
}
|
}
|
||||||
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, stageArg: string) => string;
|
export declare let dockerTag: (registryArg: string, repoArg: string, versionArg: string, suffixArg?: string) => string;
|
||||||
export declare let cleanTagsArrayFunction: (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]) => string[];
|
export declare let cleanTagsArrayFunction: (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]) => string[];
|
||||||
|
86
dist/npmci.build.docker.js
vendored
86
dist/npmci.build.docker.js
vendored
File diff suppressed because one or more lines are too long
@ -83,19 +83,19 @@ export let buildDockerfiles = (sortedArrayArg:Dockerfile[]) => {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let pushDockerfiles = function(sortedArrayArg:Dockerfile[]){
|
export let pushDockerfiles = function(sortedArrayArg:Dockerfile[],regsitryArg = "registry.gitlab.com"){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
sortedArrayArg.forEach(function(dockerfileArg){
|
sortedArrayArg.forEach(function(dockerfileArg){
|
||||||
dockerfileArg.push();
|
dockerfileArg.push(regsitryArg);
|
||||||
});
|
});
|
||||||
done.resolve(sortedArrayArg);
|
done.resolve(sortedArrayArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let pullDockerfileImages = (sortableArrayArg:Dockerfile[]) => {
|
export let pullDockerfileImages = (sortableArrayArg:Dockerfile[],registryArg = "registry.gitlab.com") => {
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
sortableArrayArg.forEach((dockerfileArg) => {
|
sortableArrayArg.forEach((dockerfileArg) => {
|
||||||
dockerfileArg.pull();
|
dockerfileArg.pull(registryArg);
|
||||||
});
|
});
|
||||||
done.resolve(sortableArrayArg);
|
done.resolve(sortableArrayArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -110,10 +110,10 @@ export let testDockerfiles = (sortedArrayArg:Dockerfile[]) => {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
export let releaseDockerfiles = (sortedArrayArg:Dockerfile[]) => {
|
export let releaseDockerfiles = (sortedArrayArg:Dockerfile[], registryArg = NpmciEnv.dockerRegistry) => {
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
sortedArrayArg.forEach(function(dockerfileArg){
|
sortedArrayArg.forEach(function(dockerfileArg){
|
||||||
dockerfileArg.release();
|
dockerfileArg.push(registryArg);
|
||||||
});
|
});
|
||||||
done.resolve(sortedArrayArg);
|
done.resolve(sortedArrayArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -125,10 +125,10 @@ export class Dockerfile {
|
|||||||
version:string;
|
version:string;
|
||||||
cleanTag:string;
|
cleanTag:string;
|
||||||
buildTag:string;
|
buildTag:string;
|
||||||
|
testTag:string;
|
||||||
releaseTag:string;
|
releaseTag:string;
|
||||||
containerName:string
|
containerName:string
|
||||||
content:string;
|
content:string;
|
||||||
patchedContent:string;
|
|
||||||
baseImage:string;
|
baseImage:string;
|
||||||
localBaseImageDependent:boolean;
|
localBaseImageDependent:boolean;
|
||||||
localBaseDockerfile:Dockerfile;
|
localBaseDockerfile:Dockerfile;
|
||||||
@ -137,8 +137,9 @@ export class Dockerfile {
|
|||||||
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
|
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
|
||||||
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base);
|
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base);
|
||||||
this.cleanTag = this.repo + ":" + this.version;
|
this.cleanTag = this.repo + ":" + this.version;
|
||||||
this.buildTag = dockerTag(this.repo,this.version,"build");
|
this.buildTag = this.cleanTag;
|
||||||
this.releaseTag = dockerTag(this.repo,this.version,"release");
|
this.testTag = dockerTag("registry.gitlab.com",this.repo,this.version,"test");
|
||||||
|
this.releaseTag = dockerTag(NpmciEnv.dockerRegistry,this.repo,this.version);
|
||||||
this.containerName = "dockerfile-" + this.version;
|
this.containerName = "dockerfile-" + this.version;
|
||||||
if(options.filePath && options.read){
|
if(options.filePath && options.read){
|
||||||
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
|
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
|
||||||
@ -147,27 +148,26 @@ export class Dockerfile {
|
|||||||
this.localBaseImageDependent = false;
|
this.localBaseImageDependent = false;
|
||||||
};
|
};
|
||||||
build(){
|
build(){
|
||||||
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
|
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
this.patchContents();
|
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
|
||||||
bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
|
bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
|
||||||
NpmciEnv.dockerFilesBuilt.push(this);
|
NpmciEnv.dockerFilesBuilt.push(this);
|
||||||
this.restoreContents();
|
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
push(){
|
push(registryArg:string){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
if(this.buildTag){
|
let pushTag;
|
||||||
bashBare("docker push " + this.buildTag);
|
NpmciEnv.buildStage == "test" ? pushTag = this.testTag : pushTag = this.releaseTag;
|
||||||
} else {
|
bashBare("docker tag " + this.buildTag + " " + pushTag);
|
||||||
plugins.beautylog.error("Dockerfile hasn't been built yet!");
|
bashBare("docker push " + pushTag);
|
||||||
}
|
|
||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
pull(){
|
pull(registryArg:string){
|
||||||
bashBare("docker pull " + this.buildTag);
|
let pullTag = this.testTag;
|
||||||
|
bashBare("docker pull " + pullTag);
|
||||||
|
bashBare("docker tag " + pullTag + " " + this.buildTag);
|
||||||
};
|
};
|
||||||
test(){
|
test(){
|
||||||
let testFile:string = plugins.path.join(paths.NpmciTestDir,"test_" + this.version + ".sh");
|
let testFile:string = plugins.path.join(paths.NpmciTestDir,"test_" + this.version + ".sh");
|
||||||
@ -183,44 +183,10 @@ export class Dockerfile {
|
|||||||
plugins.beautylog.warn("skipping tests for " + this.cleanTag + " because no testfile was found!");
|
plugins.beautylog.warn("skipping tests for " + this.cleanTag + " because no testfile was found!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
release(){
|
|
||||||
bashBare("docker tag " + this.buildTag + " " + this.releaseTag);
|
|
||||||
bashBare("docker push " + this.releaseTag);
|
|
||||||
}
|
|
||||||
getId(){
|
getId(){
|
||||||
let containerId = bashBare("docker inspect --type=image --format=\"{{.Id}}\" " + this.buildTag);
|
let containerId = bashBare("docker inspect --type=image --format=\"{{.Id}}\" " + this.buildTag);
|
||||||
return containerId;
|
return containerId;
|
||||||
};
|
};
|
||||||
patchContents(){
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
if(this.localBaseImageDependent == true){
|
|
||||||
plugins.beautylog.info("patching Dockerfile due to local build dependency!");
|
|
||||||
this.patchedContent = this.content.replace(/FROM\s[a-zA-Z0-9\/\-\:]*/, 'FROM ' + this.localBaseDockerfile.buildTag);
|
|
||||||
plugins.smartfile.memory.toFsSync(
|
|
||||||
this.patchedContent,
|
|
||||||
{
|
|
||||||
fileName:plugins.path.parse(this.filePath).name,
|
|
||||||
filePath:plugins.path.parse(this.filePath).dir
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
restoreContents(){
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
if(this.localBaseImageDependent == true){
|
|
||||||
plugins.smartfile.memory.toFsSync(
|
|
||||||
this.content,
|
|
||||||
{
|
|
||||||
fileName:plugins.path.parse(this.filePath).name,
|
|
||||||
filePath:plugins.path.parse(this.filePath).dir
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export let dockerFileVersion = function(dockerfileNameArg:string):string{
|
export let dockerFileVersion = function(dockerfileNameArg:string):string{
|
||||||
@ -241,17 +207,14 @@ export let dockerBaseImage = function(dockerfileContentArg:string){
|
|||||||
return regexResultArray[1];
|
return regexResultArray[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export let dockerTag = function(repoArg:string,versionArg:string,stageArg:string):string{
|
export let dockerTag = function(registryArg:string,repoArg:string,versionArg:string,suffixArg?:string):string{
|
||||||
let tagString:string;
|
let tagString:string;
|
||||||
let registry = NpmciEnv.dockerRegistry;
|
let registry = registryArg;
|
||||||
if(stageArg == "build" || stageArg == "test"){
|
|
||||||
registry = "registry.gitlab.com";
|
|
||||||
}
|
|
||||||
let repo = repoArg;
|
let repo = repoArg;
|
||||||
let version = versionArg;
|
let version = versionArg;
|
||||||
if(stageArg == "build" || stageArg == "test"){
|
if(suffixArg){
|
||||||
version = version + "_test";
|
version = versionArg + "_" + suffixArg;
|
||||||
}
|
};
|
||||||
tagString = registry + "/" + repo + ":" + version;
|
tagString = registry + "/" + repo + ":" + version;
|
||||||
return tagString;
|
return tagString;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user