npmci/ts/npmci.build.docker.ts

74 lines
1.9 KiB
TypeScript
Raw Normal View History

2016-06-04 16:41:35 +00:00
import * as plugins from "./npmci.plugins"
2016-06-04 23:31:21 +00:00
import * as NpmciEnv from "./npmci.env";
2016-06-04 16:41:35 +00:00
export let build = function(){
let done = plugins.q.defer();
done.resolve();
return done.promise;
}
let readDockerfiles = function(){
plugins.gulp.dest("./Dockerfile*")
.pipe(makeDockerfiles);
};
let makeDockerfiles = function(){
return function(file,enc,cb){
NpmciEnv.dockerFiles.push(
new Dockerfile({
filePath:file.path,
read:true
})
);
2016-06-05 02:19:54 +00:00
cb();
};
}
2016-06-04 23:22:04 +00:00
export class Dockerfile {
2016-06-04 23:31:21 +00:00
repo:string;
version:string;
2016-06-05 02:19:54 +00:00
content:string;
2016-06-04 23:31:21 +00:00
baseImage:string;
constructor(options:{filePath?:string,fileContents?:string|Buffer,read?:boolean}){
2016-06-05 02:19:54 +00:00
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base);
if(options.filePath && options.read){
2016-06-05 02:19:54 +00:00
this.content = plugins.smartfile.local.toStringSync(plugins.path.resolve(options.filePath));
};
this.baseImage = dockerBaseImage(this.content);
2016-06-04 23:31:21 +00:00
};
build(){
};
push(){
}
2016-06-04 23:31:21 +00:00
}
2016-06-05 02:19:54 +00:00
let dockerFileVersion = function(dockerfileNameArg:string):string{
let versionString:string;
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
let regexResultArray = versionRegex.exec(dockerfileNameArg);
if(regexResultArray.length = 2){
versionString = regexResultArray[1];
2016-06-04 23:31:21 +00:00
} else {
2016-06-05 02:19:54 +00:00
versionString = "latest";
2016-06-04 23:31:21 +00:00
}
2016-06-05 02:19:54 +00:00
return versionString;
2016-06-04 23:31:21 +00:00
}
2016-06-05 02:19:54 +00:00
let dockerBaseImage = function(dockerfileContentArg:string){
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n/
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
return regexResultArray[1];
2016-06-04 23:31:21 +00:00
}
2016-06-04 23:22:04 +00:00
2016-06-05 02:19:54 +00:00
export let dockerTagVersion = function(){
if(process.env.CI_BUILD_STAGE == "test"){
return "test";
} else {
return "latest"
}
};