start tests
This commit is contained in:
parent
229c3ae27b
commit
ea01b87949
6
dist/npmci.build.docker.d.ts
vendored
6
dist/npmci.build.docker.d.ts
vendored
@ -1,4 +1,8 @@
|
|||||||
export declare let build: () => any;
|
export declare let build: () => any;
|
||||||
|
export declare let readDockerfiles: () => any;
|
||||||
|
export declare let cleanTagsArrayFunction: (dockerfileArrayArg: Dockerfile[]) => string[];
|
||||||
|
export declare let sortDockerfiles: (sortableArrayArg: Dockerfile[]) => any;
|
||||||
|
export declare let buildDockerfiles: () => any;
|
||||||
export declare class Dockerfile {
|
export declare class Dockerfile {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
@ -15,4 +19,6 @@ export declare class Dockerfile {
|
|||||||
build(): void;
|
build(): void;
|
||||||
push(): void;
|
push(): void;
|
||||||
}
|
}
|
||||||
|
export declare let dockerFileVersion: (dockerfileNameArg: 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;
|
||||||
|
57
dist/npmci.build.docker.js
vendored
57
dist/npmci.build.docker.js
vendored
File diff suppressed because one or more lines are too long
@ -20,7 +20,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/npmci#README",
|
"homepage": "https://gitlab.com/pushrocks/npmci#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"npmts": "^5.2.1"
|
"npmts": "^5.2.1",
|
||||||
|
"should": "^9.0.0",
|
||||||
|
"typings-test": "^1.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "^5.0.8",
|
"beautylog": "^5.0.8",
|
||||||
|
2
test/assets/Dockerfile
Normal file
2
test/assets/Dockerfile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
FROM ubuntu
|
||||||
|
RUN apt-get update
|
2
test/assets/Dockerfile_sometag1
Normal file
2
test/assets/Dockerfile_sometag1
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
FROM myrepo/mygroup:sometag2
|
||||||
|
RUN apt-get update
|
1
test/assets/Dockerfile_sometag2
Normal file
1
test/assets/Dockerfile_sometag2
Normal file
@ -0,0 +1 @@
|
|||||||
|
FROM mygroup/myrepo:latest
|
2
test/test.d.ts
vendored
Normal file
2
test/test.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import "typings-test";
|
||||||
|
import "should";
|
41
test/test.js
Normal file
41
test/test.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-test");
|
||||||
|
require("should");
|
||||||
|
var path = require("path");
|
||||||
|
//set up environment
|
||||||
|
process.env.CI_BUILD_REPO = "https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git";
|
||||||
|
process.cwd = function () {
|
||||||
|
return path.join(__dirname, "assets/");
|
||||||
|
};
|
||||||
|
//require NPMCI files
|
||||||
|
var NpmciBuildDocker = require("../dist/npmci.build.docker");
|
||||||
|
var dockerfile1;
|
||||||
|
var dockerfile2;
|
||||||
|
var sortableArray;
|
||||||
|
describe("NPMCI", function () {
|
||||||
|
describe("build.docker", function () {
|
||||||
|
it("should return valid Dockerfiles", function () {
|
||||||
|
dockerfile1 = new NpmciBuildDocker.Dockerfile({ filePath: "./Dockerfile", read: true });
|
||||||
|
dockerfile2 = new NpmciBuildDocker.Dockerfile({ filePath: "./Dockerfile_sometag1", read: true });
|
||||||
|
dockerfile1.version.should.equal("latest");
|
||||||
|
dockerfile2.version.should.equal("sometag1");
|
||||||
|
});
|
||||||
|
it("should read a directory of Dockerfiles", function (done) {
|
||||||
|
NpmciBuildDocker.readDockerfiles()
|
||||||
|
.then(function (readDockerfilesArrayArg) {
|
||||||
|
readDockerfilesArrayArg[1].version.should.equal("sometag1");
|
||||||
|
sortableArray = readDockerfilesArrayArg;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should sort an array of Dockerfiles", function (done) {
|
||||||
|
NpmciBuildDocker.sortDockerfiles(sortableArray)
|
||||||
|
.then(function (sortedArrayArg) {
|
||||||
|
console.log(sortedArrayArg);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQixJQUFPLElBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUM5QixvQkFBb0I7QUFDcEIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhLEdBQUcsdURBQXVELENBQUM7QUFDcEYsT0FBTyxDQUFDLEdBQUcsR0FBRztJQUNWLE1BQU0sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxTQUFTLENBQUMsQ0FBQztBQUMxQyxDQUFDLENBQUM7QUFFRixxQkFBcUI7QUFDckIsSUFBTyxnQkFBZ0IsV0FBVyw0QkFBNEIsQ0FBQyxDQUFDO0FBR2hFLElBQUksV0FBdUMsQ0FBQztBQUM1QyxJQUFJLFdBQXVDLENBQUM7QUFDNUMsSUFBSSxhQUEyQyxDQUFDO0FBRWhELFFBQVEsQ0FBQyxPQUFPLEVBQUM7SUFDYixRQUFRLENBQUMsY0FBYyxFQUFDO1FBQ3BCLEVBQUUsQ0FBQyxpQ0FBaUMsRUFBQztZQUNqQyxXQUFXLEdBQUcsSUFBSSxnQkFBZ0IsQ0FBQyxVQUFVLENBQUMsRUFBQyxRQUFRLEVBQUMsY0FBYyxFQUFDLElBQUksRUFBQyxJQUFJLEVBQUMsQ0FBQyxDQUFDO1lBQ25GLFdBQVcsR0FBRyxJQUFJLG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nKTtcbiAgICAgICAgICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgICAgIH0pXG4gICAgICAgIH0pXG4gICAgfSlcbn0pIl19
|
42
test/test.ts
Normal file
42
test/test.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import "typings-test";
|
||||||
|
import "should";
|
||||||
|
import path = require("path");
|
||||||
|
//set up environment
|
||||||
|
process.env.CI_BUILD_REPO = "https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git";
|
||||||
|
process.cwd = () => {
|
||||||
|
return path.join(__dirname,"assets/");
|
||||||
|
};
|
||||||
|
|
||||||
|
//require NPMCI files
|
||||||
|
import NpmciBuildDocker = require("../dist/npmci.build.docker");
|
||||||
|
|
||||||
|
|
||||||
|
let dockerfile1:NpmciBuildDocker.Dockerfile;
|
||||||
|
let dockerfile2:NpmciBuildDocker.Dockerfile;
|
||||||
|
let sortableArray:NpmciBuildDocker.Dockerfile[];
|
||||||
|
|
||||||
|
describe("NPMCI",function(){
|
||||||
|
describe("build.docker",function(){
|
||||||
|
it("should return valid Dockerfiles",function(){
|
||||||
|
dockerfile1 = new NpmciBuildDocker.Dockerfile({filePath:"./Dockerfile",read:true});
|
||||||
|
dockerfile2 = new NpmciBuildDocker.Dockerfile({filePath:"./Dockerfile_sometag1",read:true});
|
||||||
|
dockerfile1.version.should.equal("latest");
|
||||||
|
dockerfile2.version.should.equal("sometag1");
|
||||||
|
});
|
||||||
|
it("should read a directory of Dockerfiles",function(done){
|
||||||
|
NpmciBuildDocker.readDockerfiles()
|
||||||
|
.then(function(readDockerfilesArrayArg:NpmciBuildDocker.Dockerfile[]){
|
||||||
|
readDockerfilesArrayArg[1].version.should.equal("sometag1");
|
||||||
|
sortableArray = readDockerfilesArrayArg
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
it("should sort an array of Dockerfiles",function(done){
|
||||||
|
NpmciBuildDocker.sortDockerfiles(sortableArray)
|
||||||
|
.then(function(sortedArrayArg:NpmciBuildDocker.Dockerfile[]){
|
||||||
|
console.log(sortedArrayArg);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
@ -4,55 +4,51 @@ import * as NpmciEnv from "./npmci.env";
|
|||||||
|
|
||||||
export let build = function(){
|
export let build = function(){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
plugins.gulp.src("./Dockerfile*")
|
|
||||||
.pipe(readDockerfiles())
|
|
||||||
.pipe(plugins.gulpFunction(function(){
|
|
||||||
sortDockerfiles()
|
|
||||||
.then(buildDockerfiles)
|
|
||||||
.then(done.resolve);
|
|
||||||
},"atEnd"));
|
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let readDockerfiles = function(){
|
export let readDockerfiles = function(){
|
||||||
return plugins.through2.obj(function(file,enc,cb){
|
let done = plugins.q.defer();
|
||||||
|
let readDockerfilesArray:Dockerfile[] = []
|
||||||
|
plugins.gulp.src("./Dockerfile*")
|
||||||
|
.pipe(plugins.through2.obj(function(file,enc,cb){
|
||||||
let myDockerfile = new Dockerfile({
|
let myDockerfile = new Dockerfile({
|
||||||
filePath:file.path,
|
filePath:file.path,
|
||||||
read:true
|
read:true
|
||||||
});
|
});
|
||||||
NpmciEnv.dockerFiles.push(
|
readDockerfilesArray.push(myDockerfile);
|
||||||
myDockerfile
|
|
||||||
);
|
|
||||||
cb(null,file);
|
cb(null,file);
|
||||||
});
|
},function(){
|
||||||
|
done.resolve(readDockerfilesArray);
|
||||||
|
}));
|
||||||
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cleanTagsArrayFunction = function(){
|
export let cleanTagsArrayFunction = function(dockerfileArrayArg:Dockerfile[]):string[]{
|
||||||
let cleanTagsArray = [];
|
let cleanTagsArray:string[] = [];
|
||||||
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){
|
dockerfileArrayArg.forEach(function(dockerfileArg){
|
||||||
cleanTagsArray.push(dockerfileArg.cleanTag);
|
cleanTagsArray.push(dockerfileArg.cleanTag);
|
||||||
});
|
});
|
||||||
return cleanTagsArray;
|
return cleanTagsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sortDockerfiles = function(){
|
export let sortDockerfiles = function(sortableArrayArg:Dockerfile[]){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
let sortableArray = NpmciEnv.dockerFiles;
|
|
||||||
let sortedArray:Dockerfile[] = [];
|
let sortedArray:Dockerfile[] = [];
|
||||||
let sorterFunctionCounter:number = 0;
|
let sorterFunctionCounter:number = 0;
|
||||||
let sorterFunction = function(){
|
let sorterFunction = function(){
|
||||||
let cleanTags = cleanTagsArrayFunction();
|
console.log(sorterFunctionCounter);
|
||||||
sortableArray.forEach((dockerfileArg)=>{
|
let cleanTags = cleanTagsArrayFunction(sortableArrayArg);
|
||||||
|
sortableArrayArg.forEach((dockerfileArg)=>{
|
||||||
if(cleanTags.indexOf(dockerfileArg.baseImage) == -1){
|
if(cleanTags.indexOf(dockerfileArg.baseImage) == -1){
|
||||||
let dockerfileArgIndex = sortableArray.indexOf(dockerfileArg);
|
let dockerfileArgIndex = sortableArrayArg.indexOf(dockerfileArg);
|
||||||
sortableArray.splice(dockerfileArgIndex);
|
sortableArrayArg.splice(dockerfileArgIndex,1);
|
||||||
sortedArray.push(dockerfileArg);
|
sortedArray.push(dockerfileArg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(sortableArray.length == 0){
|
if(sortableArrayArg.length == 0){
|
||||||
console.log(sortedArray);
|
done.resolve(sortedArray);
|
||||||
NpmciEnv.dockerFiles = sortedArray;
|
|
||||||
done.resolve();
|
|
||||||
} else if (sorterFunctionCounter < 100) {
|
} else if (sorterFunctionCounter < 100) {
|
||||||
sorterFunctionCounter++;
|
sorterFunctionCounter++;
|
||||||
sorterFunction();
|
sorterFunction();
|
||||||
@ -62,7 +58,7 @@ let sortDockerfiles = function(){
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
let buildDockerfiles = function(){
|
export let buildDockerfiles = function(){
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){
|
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){
|
||||||
dockerfileArg.build();
|
dockerfileArg.build();
|
||||||
@ -109,7 +105,7 @@ export class Dockerfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let dockerFileVersion = function(dockerfileNameArg:string):string{
|
export let dockerFileVersion = function(dockerfileNameArg:string):string{
|
||||||
let versionString:string;
|
let versionString:string;
|
||||||
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
|
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
|
||||||
let regexResultArray = versionRegex.exec(dockerfileNameArg);
|
let regexResultArray = versionRegex.exec(dockerfileNameArg);
|
||||||
@ -121,8 +117,8 @@ let dockerFileVersion = function(dockerfileNameArg:string):string{
|
|||||||
return versionString;
|
return versionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dockerBaseImage = function(dockerfileContentArg:string){
|
export let dockerBaseImage = function(dockerfileContentArg:string){
|
||||||
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n/
|
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
|
||||||
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
||||||
return regexResultArray[1];
|
return regexResultArray[1];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user