test
This commit is contained in:
89
ts/index.ts
89
ts/index.ts
@ -1,89 +1,88 @@
|
||||
#!/usr/bin/env node
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import * as paths from "./npmci.paths";
|
||||
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot);
|
||||
plugins.beautylog.log("npmci version: " + npmciInfo.version);
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import * as paths from './npmci.paths'
|
||||
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot)
|
||||
plugins.beautylog.log('npmci version: ' + npmciInfo.version)
|
||||
|
||||
import {build} from "./npmci.build"
|
||||
import {clean} from "./npmci.clean";
|
||||
import {command} from "./npmci.command";
|
||||
import {install} from "./npmci.install";
|
||||
import {publish} from "./npmci.publish";
|
||||
import {prepare} from "./npmci.prepare";
|
||||
import {test} from "./npmci.test";
|
||||
import {trigger} from "./npmci.trigger";
|
||||
import * as NpmciEnv from "./npmci.env";
|
||||
import {build} from './npmci.build'
|
||||
import {clean} from './npmci.clean'
|
||||
import {command} from './npmci.command'
|
||||
import {install} from './npmci.install'
|
||||
import {publish} from './npmci.publish'
|
||||
import {prepare} from './npmci.prepare'
|
||||
import {test} from './npmci.test'
|
||||
import {trigger} from './npmci.trigger'
|
||||
import * as NpmciEnv from './npmci.env'
|
||||
|
||||
export {build} from "./npmci.build"
|
||||
export {install} from "./npmci.install";
|
||||
export {publish} from "./npmci.publish";
|
||||
export {build} from './npmci.build'
|
||||
export {install} from './npmci.install';
|
||||
export {publish} from './npmci.publish';
|
||||
|
||||
|
||||
let smartcli = new plugins.smartcli.Smartcli();
|
||||
smartcli.addVersion(npmciInfo.version);
|
||||
let smartcli = new plugins.smartcli.Smartcli()
|
||||
smartcli.addVersion(npmciInfo.version)
|
||||
|
||||
// build
|
||||
smartcli.addCommand({
|
||||
commandName:"build"
|
||||
commandName: 'build'
|
||||
}).then((argv) => {
|
||||
build(argv._[1])
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// clean
|
||||
smartcli.addCommand({
|
||||
commandName:"clean"
|
||||
commandName: 'clean'
|
||||
}).then((argv) => {
|
||||
clean()
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// command
|
||||
smartcli.addCommand({
|
||||
commandName:"command"
|
||||
commandName: 'command'
|
||||
}).then((argv) => {
|
||||
command()
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// install
|
||||
smartcli.addCommand({
|
||||
commandName:"install"
|
||||
commandName: 'install'
|
||||
}).then((argv) => {
|
||||
install(argv._[1])
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// prepare
|
||||
smartcli.addCommand({
|
||||
commandName:"prepare"
|
||||
commandName: 'prepare'
|
||||
}).then((argv) => {
|
||||
prepare(argv._[1])
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// publish
|
||||
smartcli.addCommand({
|
||||
commandName:"publish"
|
||||
commandName: 'publish'
|
||||
}).then((argv) => {
|
||||
publish(argv._[1])
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// test
|
||||
smartcli.addCommand({
|
||||
commandName:"test"
|
||||
commandName: 'test'
|
||||
}).then((argv) => {
|
||||
test(argv._[1])
|
||||
.then(NpmciEnv.configStore);
|
||||
});
|
||||
.then(NpmciEnv.configStore)
|
||||
})
|
||||
|
||||
// trigger
|
||||
smartcli.addCommand({
|
||||
commandName:"trigger"
|
||||
commandName: 'trigger'
|
||||
}).then((argv) => {
|
||||
trigger();
|
||||
});
|
||||
trigger()
|
||||
})
|
||||
|
||||
smartcli.startParse();
|
||||
smartcli.startParse()
|
||||
|
@ -1,50 +1,49 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
|
||||
|
||||
let nvmSourceString: string = "";
|
||||
export let nvmAvailable: boolean = false;
|
||||
let nvmSourceString: string = ''
|
||||
export let nvmAvailable: boolean = false
|
||||
let checkNvm = () => {
|
||||
if (plugins.shelljs.exec(`bash -c "source /usr/local/nvm/nvm.sh"`,{silent:true}).code === 0) {
|
||||
if (plugins.shelljs.exec(`bash -c "source /usr/local/nvm/nvm.sh"`,{silent: true}).code === 0) {
|
||||
nvmSourceString = `source /usr/local/nvm/nvm.sh && `
|
||||
nvmAvailable = true;
|
||||
} else if (plugins.shelljs.exec(`bash -c "source ~/.nvm/nvm.sh"`,{silent:true}).code === 0) {
|
||||
nvmAvailable = true
|
||||
} else if (plugins.shelljs.exec(`bash -c "source ~/.nvm/nvm.sh"`,{silent: true}).code === 0) {
|
||||
nvmSourceString = `source ~/.nvm/nvm.sh && `
|
||||
nvmAvailable = true;
|
||||
nvmAvailable = true
|
||||
};
|
||||
};
|
||||
checkNvm();
|
||||
}
|
||||
checkNvm()
|
||||
|
||||
export let bash = (commandArg: string, retryArg = 2, bareArg = false) => {
|
||||
let exitCode: number;
|
||||
let stdOut: string;
|
||||
let execResult;
|
||||
let exitCode: number
|
||||
let stdOut: string
|
||||
let execResult
|
||||
if (!process.env.NPMTS_TEST) { // NPMTS_TEST is used during testing
|
||||
for (let i = 0; i <= retryArg; i++) {
|
||||
if (!bareArg) {
|
||||
execResult = plugins.shelljs.exec(
|
||||
`bash -c "${nvmSourceString} ${commandArg}"`
|
||||
);
|
||||
)
|
||||
} else {
|
||||
execResult = plugins.shelljs.exec(commandArg);
|
||||
execResult = plugins.shelljs.exec(commandArg)
|
||||
}
|
||||
exitCode = execResult.code;
|
||||
stdOut = execResult.stdout;
|
||||
if (exitCode !== 0 && i == retryArg) {
|
||||
process.exit(1);
|
||||
} else if (exitCode == 0) {
|
||||
i = retryArg + 1; // if everything works out ok retrials are not wanted
|
||||
exitCode = execResult.code
|
||||
stdOut = execResult.stdout
|
||||
if (exitCode !== 0 && i === retryArg) {
|
||||
process.exit(1)
|
||||
} else if (exitCode === 0) {
|
||||
i = retryArg + 1 // if everything works out ok retrials are not wanted
|
||||
} else {
|
||||
plugins.beautylog.warn("Something went wrong! Exit Code: " + exitCode.toString());
|
||||
plugins.beautylog.info("Retry " + (i + 1).toString() + " of " + retryArg.toString());
|
||||
plugins.beautylog.warn('Something went wrong! Exit Code: ' + exitCode.toString())
|
||||
plugins.beautylog.info('Retry ' + (i + 1).toString() + ' of ' + retryArg.toString())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugins.beautylog.log("ShellExec would be: " + commandArg)
|
||||
plugins.beautylog.log('ShellExec would be: ' + commandArg)
|
||||
}
|
||||
return stdOut;
|
||||
return stdOut
|
||||
}
|
||||
|
||||
export let bashBare = (commandArg, retryArg = 2) => {
|
||||
return bash(commandArg, retryArg, true);
|
||||
}
|
||||
return bash(commandArg, retryArg, true)
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import * as paths from "./npmci.paths";
|
||||
import * as NpmciEnv from "./npmci.env";
|
||||
import {bashBare} from "./npmci.bash";
|
||||
import * as plugins from './npmci.plugins'
|
||||
import * as paths from './npmci.paths'
|
||||
import * as NpmciEnv from './npmci.env'
|
||||
import {bashBare} from './npmci.bash'
|
||||
|
||||
/**
|
||||
* builds a cwd of Dockerfiles by triggering a promisechain
|
||||
*/
|
||||
export let build = function(){
|
||||
let done = plugins.q.defer();
|
||||
let done = plugins.q.defer()
|
||||
readDockerfiles()
|
||||
.then(sortDockerfiles)
|
||||
.then(mapDockerfiles)
|
||||
.then(buildDockerfiles)
|
||||
.then(pushDockerfiles)
|
||||
.then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* creates instance of class Dockerfile for all Dockerfiles in cwd
|
||||
* @returns Promise<Dockerfile[]>
|
||||
*/
|
||||
export let readDockerfiles = function():plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>();
|
||||
let readDockerfilesArray:Dockerfile[] = []
|
||||
plugins.gulp.src("./Dockerfile*")
|
||||
export let readDockerfiles = function(): plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>()
|
||||
let readDockerfilesArray: Dockerfile[] = []
|
||||
plugins.gulp.src('./Dockerfile*')
|
||||
.pipe(plugins.through2.obj(function(file,enc,cb){
|
||||
let myDockerfile = new Dockerfile({
|
||||
filePath:file.path,
|
||||
read:true
|
||||
});
|
||||
readDockerfilesArray.push(myDockerfile);
|
||||
cb(null,file);
|
||||
filePath: file.path,
|
||||
read: true
|
||||
})
|
||||
readDockerfilesArray.push(myDockerfile)
|
||||
cb(null,file)
|
||||
},function(){
|
||||
done.resolve(readDockerfilesArray);
|
||||
}));
|
||||
return done.promise;
|
||||
done.resolve(readDockerfilesArray)
|
||||
}))
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,249 +45,249 @@ export let readDockerfiles = function():plugins.q.Promise<Dockerfile[]>{
|
||||
* @param sortableArrayArg an array of instances of class Dockerfile
|
||||
* @returns Promise<Dockerfile[]>
|
||||
*/
|
||||
export let sortDockerfiles = function(sortableArrayArg:Dockerfile[]):plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>();
|
||||
let sortedArray:Dockerfile[] = [];
|
||||
let cleanTagsOriginal = cleanTagsArrayFunction(sortableArrayArg,sortedArray);
|
||||
let sorterFunctionCounter:number = 0;
|
||||
export let sortDockerfiles = function(sortableArrayArg: Dockerfile[]): plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>()
|
||||
let sortedArray: Dockerfile[] = []
|
||||
let cleanTagsOriginal = cleanTagsArrayFunction(sortableArrayArg,sortedArray)
|
||||
let sorterFunctionCounter: number = 0
|
||||
let sorterFunction = function(){
|
||||
sortableArrayArg.forEach((dockerfileArg)=>{
|
||||
let cleanTags = cleanTagsArrayFunction(sortableArrayArg,sortedArray);
|
||||
if(cleanTags.indexOf(dockerfileArg.baseImage) == -1 && sortedArray.indexOf(dockerfileArg) == -1){
|
||||
sortedArray.push(dockerfileArg);
|
||||
sortableArrayArg.forEach((dockerfileArg) => {
|
||||
let cleanTags = cleanTagsArrayFunction(sortableArrayArg,sortedArray)
|
||||
if (cleanTags.indexOf(dockerfileArg.baseImage) === -1 && sortedArray.indexOf(dockerfileArg) === -1) {
|
||||
sortedArray.push(dockerfileArg)
|
||||
};
|
||||
if(cleanTagsOriginal.indexOf(dockerfileArg.baseImage) != -1){
|
||||
dockerfileArg.localBaseImageDependent = true;
|
||||
if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) {
|
||||
dockerfileArg.localBaseImageDependent = true
|
||||
};
|
||||
});
|
||||
if(sortableArrayArg.length == sortedArray.length){
|
||||
done.resolve(sortedArray);
|
||||
})
|
||||
if (sortableArrayArg.length === sortedArray.length) {
|
||||
done.resolve(sortedArray)
|
||||
} else if (sorterFunctionCounter < 10) {
|
||||
sorterFunctionCounter++;
|
||||
sorterFunction();
|
||||
sorterFunctionCounter++
|
||||
sorterFunction()
|
||||
};
|
||||
}
|
||||
sorterFunction();
|
||||
return done.promise;
|
||||
};
|
||||
sorterFunction()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* maps local Dockerfiles dependencies to the correspoding Dockerfile class instances
|
||||
*/
|
||||
export let mapDockerfiles = function(sortedArray:Dockerfile[]):plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>();
|
||||
export let mapDockerfiles = function(sortedArray: Dockerfile[]): plugins.q.Promise<Dockerfile[]>{
|
||||
let done = plugins.q.defer<Dockerfile[]>()
|
||||
sortedArray.forEach((dockerfileArg) => {
|
||||
if(dockerfileArg.localBaseImageDependent){
|
||||
sortedArray.forEach((dockfile2:Dockerfile) => {
|
||||
if(dockfile2.cleanTag == dockerfileArg.baseImage){
|
||||
dockerfileArg.localBaseDockerfile = dockfile2;
|
||||
if (dockerfileArg.localBaseImageDependent) {
|
||||
sortedArray.forEach((dockfile2: Dockerfile) => {
|
||||
if (dockfile2.cleanTag === dockerfileArg.baseImage) {
|
||||
dockerfileArg.localBaseDockerfile = dockfile2
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
done.resolve(sortedArray);
|
||||
return done.promise;
|
||||
})
|
||||
done.resolve(sortedArray)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* builds the correspoding real docker image for each Dockerfile class instance
|
||||
*/
|
||||
export let buildDockerfiles = (sortedArrayArg:Dockerfile[]) => {
|
||||
let done = plugins.q.defer();
|
||||
export let buildDockerfiles = (sortedArrayArg: Dockerfile[]) => {
|
||||
let done = plugins.q.defer()
|
||||
sortedArrayArg.forEach(function(dockerfileArg){
|
||||
dockerfileArg.build();
|
||||
dockerfileArg.build()
|
||||
})
|
||||
done.resolve(sortedArrayArg);
|
||||
return done.promise;
|
||||
done.resolve(sortedArrayArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* pushes the real Dockerfile images to a Docker registry
|
||||
*/
|
||||
export let pushDockerfiles = function(sortedArrayArg:Dockerfile[]){
|
||||
let done = plugins.q.defer();
|
||||
export let pushDockerfiles = function(sortedArrayArg: Dockerfile[]){
|
||||
let done = plugins.q.defer()
|
||||
sortedArrayArg.forEach(function(dockerfileArg){
|
||||
dockerfileArg.push(NpmciEnv.buildStage);
|
||||
});
|
||||
done.resolve(sortedArrayArg);
|
||||
return done.promise;
|
||||
dockerfileArg.push(NpmciEnv.buildStage)
|
||||
})
|
||||
done.resolve(sortedArrayArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* pulls corresponding real Docker images for instances of Dockerfile from a registry.
|
||||
* This is needed if building, testing, and publishing of Docker images is carried out in seperate CI stages.
|
||||
*/
|
||||
export let pullDockerfileImages = (sortableArrayArg:Dockerfile[],registryArg = "registry.gitlab.com") => {
|
||||
let done = plugins.q.defer();
|
||||
export let pullDockerfileImages = (sortableArrayArg: Dockerfile[],registryArg = 'registry.gitlab.com') => {
|
||||
let done = plugins.q.defer()
|
||||
sortableArrayArg.forEach((dockerfileArg) => {
|
||||
dockerfileArg.pull(registryArg);
|
||||
});
|
||||
done.resolve(sortableArrayArg);
|
||||
return done.promise;
|
||||
dockerfileArg.pull(registryArg)
|
||||
})
|
||||
done.resolve(sortableArrayArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* tests all Dockerfiles in by calling class Dockerfile.test();
|
||||
* @param sortedArrayArg Dockerfile[] that contains all Dockerfiles in cwd
|
||||
*/
|
||||
export let testDockerfiles = (sortedArrayArg:Dockerfile[]) => {
|
||||
let done = plugins.q.defer();
|
||||
export let testDockerfiles = (sortedArrayArg: Dockerfile[]) => {
|
||||
let done = plugins.q.defer()
|
||||
sortedArrayArg.forEach(function(dockerfileArg){
|
||||
dockerfileArg.test();
|
||||
});
|
||||
done.resolve(sortedArrayArg);
|
||||
return done.promise;
|
||||
};
|
||||
dockerfileArg.test()
|
||||
})
|
||||
done.resolve(sortedArrayArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* class Dockerfile represents a Dockerfile on disk in npmci
|
||||
*/
|
||||
export class Dockerfile {
|
||||
filePath:string;
|
||||
repo:string;
|
||||
version:string;
|
||||
cleanTag:string;
|
||||
buildTag:string;
|
||||
testTag:string;
|
||||
releaseTag:string;
|
||||
containerName:string
|
||||
content:string;
|
||||
baseImage:string;
|
||||
localBaseImageDependent:boolean;
|
||||
localBaseDockerfile:Dockerfile;
|
||||
constructor(options:{filePath?:string,fileContents?:string|Buffer,read?:boolean}){
|
||||
this.filePath = options.filePath;
|
||||
this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo;
|
||||
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base);
|
||||
this.cleanTag = this.repo + ":" + this.version;
|
||||
this.buildTag = this.cleanTag;
|
||||
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;
|
||||
if(options.filePath && options.read){
|
||||
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath));
|
||||
filePath: string
|
||||
repo: string
|
||||
version: string
|
||||
cleanTag: string
|
||||
buildTag: string
|
||||
testTag: string
|
||||
releaseTag: string
|
||||
containerName: string
|
||||
content: string
|
||||
baseImage: string
|
||||
localBaseImageDependent: boolean
|
||||
localBaseDockerfile: Dockerfile
|
||||
constructor(options: {filePath?: string,fileContents?: string|Buffer,read?: boolean}) {
|
||||
this.filePath = options.filePath
|
||||
this.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo
|
||||
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base)
|
||||
this.cleanTag = this.repo + ':' + this.version
|
||||
this.buildTag = this.cleanTag
|
||||
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
|
||||
if (options.filePath && options.read) {
|
||||
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath))
|
||||
};
|
||||
this.baseImage = dockerBaseImage(this.content);
|
||||
this.localBaseImageDependent = false;
|
||||
this.baseImage = dockerBaseImage(this.content)
|
||||
this.localBaseImageDependent = false
|
||||
};
|
||||
|
||||
/**
|
||||
* builds the Dockerfile
|
||||
*/
|
||||
build(){
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.info("now building Dockerfile for " + this.cleanTag);
|
||||
bashBare("docker build -t " + this.buildTag + " -f " + this.filePath + " .");
|
||||
NpmciEnv.dockerFilesBuilt.push(this);
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
build() {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag)
|
||||
bashBare('docker build -t ' + this.buildTag + ' -f ' + this.filePath + ' .')
|
||||
NpmciEnv.dockerFilesBuilt.push(this)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
};
|
||||
|
||||
/**
|
||||
* pushes the Dockerfile to a registry
|
||||
*/
|
||||
push(stageArg){
|
||||
let done = plugins.q.defer();
|
||||
let pushTag;
|
||||
switch (stageArg){
|
||||
case "release":
|
||||
pushTag = this.releaseTag;
|
||||
break;
|
||||
case "test":
|
||||
push(stageArg) {
|
||||
let done = plugins.q.defer()
|
||||
let pushTag
|
||||
switch (stageArg) {
|
||||
case 'release':
|
||||
pushTag = this.releaseTag
|
||||
break
|
||||
case 'test':
|
||||
default:
|
||||
pushTag = this.testTag;
|
||||
break;
|
||||
pushTag = this.testTag
|
||||
break
|
||||
}
|
||||
bashBare("docker tag " + this.buildTag + " " + pushTag);
|
||||
bashBare("docker push " + pushTag);
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
bashBare('docker tag ' + this.buildTag + ' ' + pushTag)
|
||||
bashBare('docker push ' + pushTag)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
};
|
||||
|
||||
/**
|
||||
* pulls the Dockerfile from a registry
|
||||
*/
|
||||
pull(registryArg:string){
|
||||
let pullTag = this.testTag;
|
||||
bashBare("docker pull " + pullTag);
|
||||
bashBare("docker tag " + pullTag + " " + this.buildTag);
|
||||
pull(registryArg: string) {
|
||||
let pullTag = this.testTag
|
||||
bashBare('docker pull ' + pullTag)
|
||||
bashBare('docker tag ' + pullTag + ' ' + this.buildTag)
|
||||
};
|
||||
|
||||
/**
|
||||
* tests the Dockerfile;
|
||||
*/
|
||||
test(){
|
||||
let testFile:string = plugins.path.join(paths.NpmciTestDir,"test_" + this.version + ".sh");
|
||||
let testFileExists:boolean = plugins.smartfile.fs.fileExistsSync(testFile);
|
||||
if(testFileExists){
|
||||
bashBare("docker run --name npmci_test_container " + this.buildTag + " mkdir /npmci_test");
|
||||
bashBare("docker cp " + testFile + " npmci_test_container:/npmci_test/test.sh");
|
||||
bashBare("docker commit npmci_test_container npmci_test_image");
|
||||
bashBare("docker run npmci_test_image sh /npmci_test/test.sh");
|
||||
bashBare("docker rm npmci_test_container");
|
||||
bashBare("docker rmi --force npmci_test_image");
|
||||
test() {
|
||||
let testFile: string = plugins.path.join(paths.NpmciTestDir,'test_' + this.version + '.sh')
|
||||
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile)
|
||||
if (testFileExists) {
|
||||
bashBare('docker run --name npmci_test_container ' + this.buildTag + ' mkdir /npmci_test')
|
||||
bashBare('docker cp ' + testFile + ' npmci_test_container:/npmci_test/test.sh')
|
||||
bashBare('docker commit npmci_test_container npmci_test_image')
|
||||
bashBare('docker run npmci_test_image sh /npmci_test/test.sh')
|
||||
bashBare('docker rm npmci_test_container')
|
||||
bashBare('docker rmi --force npmci_test_image')
|
||||
} else {
|
||||
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!')
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* gets the id of a Dockerfile
|
||||
*/
|
||||
getId(){
|
||||
let containerId = bashBare("docker inspect --type=image --format=\"{{.Id}}\" " + this.buildTag);
|
||||
return containerId;
|
||||
getId() {
|
||||
let containerId = bashBare('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
|
||||
return containerId
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export let dockerFileVersion = function(dockerfileNameArg:string):string{
|
||||
let versionString:string;
|
||||
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
|
||||
let regexResultArray = versionRegex.exec(dockerfileNameArg);
|
||||
if(regexResultArray && regexResultArray.length == 2){
|
||||
versionString = regexResultArray[1];
|
||||
export let dockerFileVersion = function(dockerfileNameArg: string): string{
|
||||
let versionString: string
|
||||
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/
|
||||
let regexResultArray = versionRegex.exec(dockerfileNameArg)
|
||||
if (regexResultArray && regexResultArray.length === 2) {
|
||||
versionString = regexResultArray[1]
|
||||
} else {
|
||||
versionString = "latest";
|
||||
versionString = 'latest'
|
||||
}
|
||||
return versionString;
|
||||
return versionString
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export let dockerBaseImage = function(dockerfileContentArg:string){
|
||||
export let dockerBaseImage = function(dockerfileContentArg: string){
|
||||
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
|
||||
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
||||
return regexResultArray[1];
|
||||
return regexResultArray[1]
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export let dockerTag = function(registryArg:string,repoArg:string,versionArg:string,suffixArg?:string):string{
|
||||
let tagString:string;
|
||||
let registry = registryArg;
|
||||
let repo = repoArg;
|
||||
let version = versionArg;
|
||||
if(suffixArg){
|
||||
version = versionArg + "_" + suffixArg;
|
||||
export let dockerTag = function(registryArg: string,repoArg: string,versionArg: string,suffixArg?: string): string{
|
||||
let tagString: string
|
||||
let registry = registryArg
|
||||
let repo = repoArg
|
||||
let version = versionArg
|
||||
if (suffixArg) {
|
||||
version = versionArg + '_' + suffixArg
|
||||
};
|
||||
tagString = registry + "/" + repo + ":" + version;
|
||||
return tagString;
|
||||
};
|
||||
tagString = registry + '/' + repo + ':' + version
|
||||
return tagString
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export let cleanTagsArrayFunction = function(dockerfileArrayArg:Dockerfile[],trackingArrayArg:Dockerfile[]):string[]{
|
||||
let cleanTagsArray:string[] = [];
|
||||
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);
|
||||
if (trackingArrayArg.indexOf(dockerfileArg) === -1) {
|
||||
cleanTagsArray.push(dockerfileArg.cleanTag)
|
||||
}
|
||||
});
|
||||
return cleanTagsArray;
|
||||
}
|
||||
})
|
||||
return cleanTagsArray
|
||||
}
|
||||
|
@ -1,26 +1,23 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import {bash} from "./npmci.bash";
|
||||
import * as env from "./npmci.env";
|
||||
import * as buildDocker from "./npmci.build.docker"
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import {bash} from './npmci.bash'
|
||||
import * as env from './npmci.env'
|
||||
import * as buildDocker from './npmci.build.docker'
|
||||
|
||||
/**
|
||||
* defines possible build services
|
||||
*/
|
||||
export type TBuildService = "docker";
|
||||
export type TBuildService = 'docker';
|
||||
|
||||
/**
|
||||
* builds for a specific service
|
||||
*/
|
||||
export let build = function(commandArg):plugins.q.Promise<any> {
|
||||
switch(commandArg){
|
||||
case "docker":
|
||||
return buildDocker.build();
|
||||
export let build = function(commandArg): plugins.q.Promise<any> {
|
||||
switch (commandArg) {
|
||||
case 'docker':
|
||||
return buildDocker.build()
|
||||
default:
|
||||
plugins.beautylog.log("build target " + commandArg + " not recognised!");
|
||||
plugins.beautylog.log('build target ' + commandArg + ' not recognised!')
|
||||
};
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
20
ts/npmci.config.ts
Normal file
20
ts/npmci.config.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as q from 'q'
|
||||
|
||||
import * as plugins from './npmci.plugins'
|
||||
import * as paths from './npmci.paths'
|
||||
|
||||
export interface INpmciOptions {
|
||||
globalNpmTools: string[]
|
||||
}
|
||||
|
||||
export let getConfig = () => {
|
||||
console.log('getting config')
|
||||
let done = q.defer<INpmciOptions>()
|
||||
let npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd)
|
||||
let defaultConfig: INpmciOptions = {
|
||||
globalNpmTools: []
|
||||
}
|
||||
let npmciConfig = npmciNpmextra.dataFor<INpmciOptions>('npmci', defaultConfig)
|
||||
done.resolve(npmciConfig)
|
||||
return done.promise
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import 'typings-global';
|
||||
import * as plugins from './npmci.plugins';
|
||||
import { bash } from './npmci.bash';
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import * as configModule from './npmci.config'
|
||||
import { bash } from './npmci.bash'
|
||||
import { nvmAvailable } from './npmci.bash'
|
||||
|
||||
export let install = (versionArg) => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.log(`now installing node version ${versionArg}`)
|
||||
@ -24,6 +24,15 @@ export let install = (versionArg) => {
|
||||
};
|
||||
bash('node -v')
|
||||
bash('npm -v')
|
||||
done.resolve()
|
||||
|
||||
// lets look for further config
|
||||
configModule.getConfig()
|
||||
.then(config => {
|
||||
for (let npmTool of config.globalNpmTools) {
|
||||
plugins.beautylog.info(`globally installing ${npmTool} from npm`)
|
||||
bash(`npm install --loglevel=silent -g ${npmTool}`)
|
||||
}
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
|
||||
export let cwd = process.cwd();
|
||||
export let cwd = process.cwd()
|
||||
|
||||
export let NpmciPackageRoot = plugins.path.join(__dirname,"../");
|
||||
export let NpmciPackageConfig = plugins.path.join(NpmciPackageRoot,"./config.json");
|
||||
export let NpmciProjectDir = cwd;
|
||||
export let NpmciTestDir = plugins.path.join(cwd,"./test");
|
||||
export let NpmciPackageRoot = plugins.path.join(__dirname,'../')
|
||||
export let NpmciPackageConfig = plugins.path.join(NpmciPackageRoot,'./config.json')
|
||||
export let NpmciProjectDir = cwd
|
||||
export let NpmciTestDir = plugins.path.join(cwd,'./test')
|
||||
|
@ -1,17 +1,18 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export let gulp = require("gulp");
|
||||
export let gulpFunction = require("gulp-function");
|
||||
export let lodash = require("lodash");
|
||||
export import path = require("path");
|
||||
export import projectinfo = require("projectinfo");
|
||||
export import q = require("q");
|
||||
export let request = require("request");
|
||||
export import shelljs = require("shelljs");
|
||||
export import smartcli = require("smartcli");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartparam = require("smartparam");
|
||||
export import smartsocket = require("smartsocket");
|
||||
export import smartssh = require("smartssh");
|
||||
export import smartstring = require("smartstring");
|
||||
export let through2 = require("through2");
|
||||
import 'typings-global'
|
||||
export import beautylog = require('beautylog')
|
||||
export let gulp = require('gulp')
|
||||
export import gulpFunction = require('gulp-function')
|
||||
export import lodash = require('lodash')
|
||||
export import npmextra = require('npmextra')
|
||||
export import path = require('path')
|
||||
export import projectinfo = require('projectinfo')
|
||||
export import q = require('q')
|
||||
export let request = require('request')
|
||||
export import shelljs = require('shelljs')
|
||||
export import smartcli = require('smartcli')
|
||||
export import smartfile = require('smartfile')
|
||||
export import smartparam = require('smartparam')
|
||||
export import smartsocket = require('smartsocket')
|
||||
export import smartssh = require('smartssh')
|
||||
export import smartstring = require('smartstring')
|
||||
export import through2 = require('through2')
|
||||
|
@ -1,94 +1,94 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import {bash} from "./npmci.bash";
|
||||
import * as env from "./npmci.env"
|
||||
import * as sshModule from "./npmci.ssh"
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import {bash} from './npmci.bash'
|
||||
import * as env from './npmci.env'
|
||||
import * as sshModule from './npmci.ssh'
|
||||
|
||||
|
||||
//types
|
||||
// types
|
||||
|
||||
/**
|
||||
* defines possible prepare services
|
||||
*/
|
||||
export type TPrepService = "npm" | "docker" | "docker-gitlab" | "ssh";
|
||||
export type TPrepService = 'npm' | 'docker' | 'docker-gitlab' | 'ssh';
|
||||
|
||||
/**
|
||||
* authenticates npm with token from env var
|
||||
*/
|
||||
let npm = function(){
|
||||
let done = plugins.q.defer();
|
||||
|
||||
let npmrcPrefix:string = "//registry.npmjs.org/:_authToken=";
|
||||
let npmToken:string = process.env.NPMCI_TOKEN_NPM;
|
||||
let npmrcFileString = npmrcPrefix + npmToken;
|
||||
|
||||
if(npmToken){
|
||||
plugins.beautylog.info("found access token");
|
||||
let done = plugins.q.defer()
|
||||
|
||||
let npmrcPrefix: string = '//registry.npmjs.org/:_authToken='
|
||||
let npmToken: string = process.env.NPMCI_TOKEN_NPM
|
||||
let npmrcFileString = npmrcPrefix + npmToken
|
||||
|
||||
if (npmToken) {
|
||||
plugins.beautylog.info('found access token')
|
||||
} else {
|
||||
plugins.beautylog.error("no access token found! Exiting!");
|
||||
process.exit(1);
|
||||
plugins.beautylog.error('no access token found! Exiting!')
|
||||
process.exit(1)
|
||||
}
|
||||
plugins.smartfile.memory.toFsSync(npmrcFileString,"/root/.npmrc");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
plugins.smartfile.memory.toFsSync(npmrcFileString,'/root/.npmrc')
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* logs in docker
|
||||
*/
|
||||
let docker = function(){
|
||||
let done = plugins.q.defer();
|
||||
env.setDockerRegistry("docker.io");
|
||||
let done = plugins.q.defer()
|
||||
env.setDockerRegistry('docker.io')
|
||||
let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/
|
||||
if(!process.env.NPMCI_LOGIN_DOCKER){
|
||||
plugins.beautylog.error("You have to specify Login Data to the Docker Registry");
|
||||
process.exit(1);
|
||||
if (!process.env.NPMCI_LOGIN_DOCKER) {
|
||||
plugins.beautylog.error('You have to specify Login Data to the Docker Registry')
|
||||
process.exit(1)
|
||||
}
|
||||
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com"); // Always also login to GitLab Registry
|
||||
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER);
|
||||
let username = dockerRegexResultArray[1];
|
||||
let password = dockerRegexResultArray[2];
|
||||
plugins.shelljs.exec("docker login -u " + username + " -p " + password);
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com') // Always also login to GitLab Registry
|
||||
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER)
|
||||
let username = dockerRegexResultArray[1]
|
||||
let password = dockerRegexResultArray[2]
|
||||
plugins.shelljs.exec('docker login -u ' + username + ' -p ' + password)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare docker for gitlab registry
|
||||
*/
|
||||
let dockerGitlab = function(){
|
||||
let done = plugins.q.defer();
|
||||
env.setDockerRegistry("registry.gitlab.com");
|
||||
plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + process.env.CI_BUILD_TOKEN + " " + "registry.gitlab.com");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
let done = plugins.q.defer()
|
||||
env.setDockerRegistry('registry.gitlab.com')
|
||||
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com')
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare ssh
|
||||
*/
|
||||
let ssh = function(){
|
||||
let done = plugins.q.defer();
|
||||
let done = plugins.q.defer()
|
||||
sshModule.ssh()
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
.then(done.resolve)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* the main exported prepare function
|
||||
* @param servieArg describes the service to prepare
|
||||
*/
|
||||
export let prepare = function(serviceArg:TPrepService){
|
||||
export let prepare = function(serviceArg: TPrepService){
|
||||
switch (serviceArg) {
|
||||
case "npm":
|
||||
return npm();
|
||||
case "docker":
|
||||
return docker();
|
||||
case "docker-gitlab":
|
||||
return dockerGitlab();
|
||||
case "ssh":
|
||||
return ssh();
|
||||
case 'npm':
|
||||
return npm()
|
||||
case 'docker':
|
||||
return docker()
|
||||
case 'docker-gitlab':
|
||||
return dockerGitlab()
|
||||
case 'ssh':
|
||||
return ssh()
|
||||
default:
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import {prepare} from "./npmci.prepare";
|
||||
import {bash} from "./npmci.bash";
|
||||
import * as NpmciEnv from "./npmci.env";
|
||||
import * as NpmciBuildDocker from "./npmci.build.docker"
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import {prepare} from './npmci.prepare'
|
||||
import {bash} from './npmci.bash'
|
||||
import * as NpmciEnv from './npmci.env'
|
||||
import * as NpmciBuildDocker from './npmci.build.docker'
|
||||
|
||||
/**
|
||||
* type of supported services
|
||||
*/
|
||||
export type TPubService = "npm" | "docker";
|
||||
export type TPubService = 'npm' | 'docker';
|
||||
|
||||
/**
|
||||
* the main exported publish function.
|
||||
* @param pubServiceArg references targeted service to publish to
|
||||
*/
|
||||
export let publish = (pubServiceArg:TPubService = "npm") => {
|
||||
switch (pubServiceArg){
|
||||
case "npm":
|
||||
return publishNpm();
|
||||
case "docker":
|
||||
return publishDocker();
|
||||
export let publish = (pubServiceArg: TPubService = 'npm') => {
|
||||
switch (pubServiceArg) {
|
||||
case 'npm':
|
||||
return publishNpm()
|
||||
case 'docker':
|
||||
return publishDocker()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to publish current cwd to NPM registry
|
||||
*/
|
||||
let publishNpm = function(){
|
||||
let done = plugins.q.defer();
|
||||
prepare("npm")
|
||||
let done = plugins.q.defer()
|
||||
prepare('npm')
|
||||
.then(function(){
|
||||
bash("npm publish");
|
||||
plugins.beautylog.ok("Done!") ;
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
bash('npm publish')
|
||||
plugins.beautylog.ok('Done!')
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to pubish current cwd to Docker registry
|
||||
*/
|
||||
let publishDocker = function(){
|
||||
let done = plugins.q.defer();
|
||||
let done = plugins.q.defer()
|
||||
NpmciBuildDocker.readDockerfiles()
|
||||
.then(NpmciBuildDocker.pullDockerfileImages)
|
||||
.then(NpmciBuildDocker.pushDockerfiles)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
.then(done.resolve)
|
||||
return done.promise
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import * as plugins from './npmci.plugins'
|
||||
|
||||
/**
|
||||
* servezoneRegex is the regex that parses the servezone connection data
|
||||
* parses strings in the form of "servezone.example.com|3000|somepassword"
|
||||
*/
|
||||
let servezoneRegex = /^(.*)\|(.*)\|(.*)/;
|
||||
let servezoneRegex = /^(.*)\|(.*)\|(.*)/
|
||||
|
||||
/**
|
||||
* holds the results of the parsed servezone env string
|
||||
*/
|
||||
let servezoneRegexResultArray = servezoneRegex.exec(process.env.NPMCI_SERVEZONE);
|
||||
let servezoneRegexResultArray = servezoneRegex.exec(process.env.NPMCI_SERVEZONE)
|
||||
|
||||
/**
|
||||
* the data object that is used for the smartsocket client object
|
||||
*/
|
||||
let smartsocketClientConstructorOptions = {
|
||||
alias: "npmci",
|
||||
alias: 'npmci',
|
||||
password: servezoneRegexResultArray[3],
|
||||
port: parseInt(servezoneRegexResultArray[2]),
|
||||
role: "ci",
|
||||
role: 'ci',
|
||||
url: servezoneRegexResultArray[1]
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* the main run function to submit a service to a servezone
|
||||
@ -28,5 +28,5 @@ let smartsocketClientConstructorOptions = {
|
||||
export let run = (configArg) => {
|
||||
new plugins.smartsocket.SmartsocketClient(
|
||||
smartsocketClientConstructorOptions
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
@ -1,51 +1,51 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
|
||||
let sshRegex = /^(.*)\|(.*)\|(.*)/
|
||||
let sshInstance:plugins.smartssh.SshInstance;
|
||||
let sshInstance: plugins.smartssh.SshInstance
|
||||
|
||||
/**
|
||||
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
|
||||
*/
|
||||
export let ssh = () => {
|
||||
let done = plugins.q.defer();
|
||||
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
|
||||
plugins.smartparam.forEachMinimatch(process.env,"NPMCI_SSHKEY_*",evaluateSshEnv);
|
||||
if(!process.env.NPMTS_TEST){
|
||||
sshInstance.writeToDisk();
|
||||
let done = plugins.q.defer()
|
||||
sshInstance = new plugins.smartssh.SshInstance() // init ssh instance
|
||||
plugins.smartparam.forEachMinimatch(process.env,'NPMCI_SSHKEY_*',evaluateSshEnv)
|
||||
if (!process.env.NPMTS_TEST) {
|
||||
sshInstance.writeToDisk()
|
||||
} else {
|
||||
plugins.beautylog.log("In test mode, so not storing SSH keys to disk!");
|
||||
plugins.beautylog.log('In test mode, so not storing SSH keys to disk!')
|
||||
};
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* gets called for each found SSH ENV Var and deploys it
|
||||
*/
|
||||
let evaluateSshEnv = (sshkeyEnvVarArg) => {
|
||||
let resultArray = sshRegex.exec(sshkeyEnvVarArg);
|
||||
let sshKey = new plugins.smartssh.SshKey();
|
||||
plugins.beautylog.info("Found SSH identity for " + resultArray[1]);
|
||||
if(notUndefined(resultArray[1])){
|
||||
plugins.beautylog.log("---> host defined!")
|
||||
sshKey.host = resultArray[1];
|
||||
let resultArray = sshRegex.exec(sshkeyEnvVarArg)
|
||||
let sshKey = new plugins.smartssh.SshKey()
|
||||
plugins.beautylog.info('Found SSH identity for ' + resultArray[1])
|
||||
if (notUndefined(resultArray[1])) {
|
||||
plugins.beautylog.log('---> host defined!')
|
||||
sshKey.host = resultArray[1]
|
||||
}
|
||||
if(notUndefined(resultArray[2])){
|
||||
plugins.beautylog.log("---> privKey defined!")
|
||||
sshKey.privKeyBase64 = resultArray[2];
|
||||
if (notUndefined(resultArray[2])) {
|
||||
plugins.beautylog.log('---> privKey defined!')
|
||||
sshKey.privKeyBase64 = resultArray[2]
|
||||
};
|
||||
if(notUndefined(resultArray[3])){
|
||||
"---> pubKey defined!"
|
||||
sshKey.pubKeyBase64 = resultArray[3];
|
||||
if (notUndefined(resultArray[3])) {
|
||||
'---> pubKey defined!'
|
||||
sshKey.pubKeyBase64 = resultArray[3]
|
||||
};
|
||||
|
||||
sshInstance.addKey(sshKey);
|
||||
};
|
||||
|
||||
sshInstance.addKey(sshKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if not undefined
|
||||
*/
|
||||
let notUndefined = (stringArg:string) => {
|
||||
return (stringArg && stringArg != "undefined" && stringArg != "##");
|
||||
}
|
||||
let notUndefined = (stringArg: string) => {
|
||||
return (stringArg && stringArg !== 'undefined' && stringArg !== '##')
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import {bash} from "./npmci.bash";
|
||||
import {install} from "./npmci.install";
|
||||
import * as env from "./npmci.env";
|
||||
import * as NpmciBuildDocker from "./npmci.build.docker";
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import {bash} from './npmci.bash'
|
||||
import {install} from './npmci.install'
|
||||
import * as env from './npmci.env'
|
||||
import * as NpmciBuildDocker from './npmci.build.docker'
|
||||
|
||||
export let test = (versionArg) => {
|
||||
let done = plugins.q.defer();
|
||||
if(versionArg == "docker"){
|
||||
let done = plugins.q.defer()
|
||||
if (versionArg === 'docker') {
|
||||
testDocker()
|
||||
.then(()=>{
|
||||
done.resolve();
|
||||
});
|
||||
.then(() => {
|
||||
done.resolve()
|
||||
})
|
||||
} else {
|
||||
install(versionArg)
|
||||
.then(npmDependencies)
|
||||
.then(npmTest)
|
||||
.then(()=>{
|
||||
done.resolve();
|
||||
});
|
||||
.then(() => {
|
||||
done.resolve()
|
||||
})
|
||||
}
|
||||
return done.promise;
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let npmDependencies = function(){
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.info("now installing dependencies:");
|
||||
bash("npm install");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.info('now installing dependencies:')
|
||||
bash('npm install')
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let npmTest = () => {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.info("now starting tests:");
|
||||
bash("npm test");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.info('now starting tests:')
|
||||
bash('npm test')
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let testDocker = function(){
|
||||
let done = plugins.q.defer();
|
||||
let done = plugins.q.defer()
|
||||
NpmciBuildDocker.readDockerfiles()
|
||||
.then(NpmciBuildDocker.pullDockerfileImages)
|
||||
.then(NpmciBuildDocker.testDockerfiles)
|
||||
.then(done.resolve)
|
||||
return done.promise;
|
||||
return done.promise
|
||||
}
|
||||
|
||||
|
@ -1,32 +1,31 @@
|
||||
import "typings-global";
|
||||
import * as plugins from "./npmci.plugins";
|
||||
import {prepare} from "./npmci.prepare";
|
||||
import {bash} from "./npmci.bash";
|
||||
import 'typings-global'
|
||||
import * as plugins from './npmci.plugins'
|
||||
import { prepare } from './npmci.prepare'
|
||||
import { bash } from './npmci.bash'
|
||||
|
||||
|
||||
let triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/;
|
||||
let triggerValueRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)\|?([a-zA-Z0-9\.\-\/]*)/
|
||||
|
||||
export let trigger = function () {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.info("now running triggers");
|
||||
plugins.smartparam.forEachMinimatch(process.env, "NPMCI_TRIGGER_*", evaluateTrigger);
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.info('now running triggers')
|
||||
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger)
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let evaluateTrigger = (triggerEnvVarArg) => {
|
||||
let triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg);
|
||||
let regexDomain = triggerRegexResultArray[1];
|
||||
let regexProjectId = triggerRegexResultArray[2];
|
||||
let regexProjectTriggerToken = triggerRegexResultArray[3];
|
||||
let regexRefName = triggerRegexResultArray[4];
|
||||
let regexTriggerName;
|
||||
if (triggerRegexResultArray.length == 6) {
|
||||
regexTriggerName = triggerRegexResultArray[5];
|
||||
let triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg)
|
||||
let regexDomain = triggerRegexResultArray[1]
|
||||
let regexProjectId = triggerRegexResultArray[2]
|
||||
let regexProjectTriggerToken = triggerRegexResultArray[3]
|
||||
let regexRefName = triggerRegexResultArray[4]
|
||||
let regexTriggerName
|
||||
if (triggerRegexResultArray.length === 6) {
|
||||
regexTriggerName = triggerRegexResultArray[5]
|
||||
} else {
|
||||
regexTriggerName = "Unnamed Trigger";
|
||||
regexTriggerName = 'Unnamed Trigger'
|
||||
}
|
||||
plugins.beautylog.info("Found Trigger!");
|
||||
plugins.beautylog.log("triggering build for ref " + regexRefName + " of " + regexTriggerName);
|
||||
plugins.request.post("https://gitlab.com/api/v3/projects/" + regexProjectId + "/trigger/builds", { form: { token: regexProjectTriggerToken, ref: regexRefName } });
|
||||
}
|
||||
plugins.beautylog.info('Found Trigger!')
|
||||
plugins.beautylog.log('triggering build for ref ' + regexRefName + ' of ' + regexTriggerName)
|
||||
plugins.request.post('https://gitlab.com/api/v3/projects/' + regexProjectId + '/trigger/builds', { form: { token: regexProjectTriggerToken, ref: regexRefName } })
|
||||
}
|
||||
|
Reference in New Issue
Block a user