add option for npm access level

This commit is contained in:
2018-04-04 22:25:13 +02:00
parent c8c17e6cba
commit 0ab1e1ab7c
70 changed files with 1977 additions and 1846 deletions

View File

@ -1,2 +1 @@
import './npmci.cli'
import './npmci.cli';

View File

@ -1,10 +1,10 @@
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
import * as plugins from './mod.plugins';
import * as paths from '../npmci.paths';
/**
* cleans npmci config files
*/
export let clean = async (): Promise<void> => {
plugins.smartfile.fs.removeSync(paths.NpmciPackageConfig)
return
}
plugins.smartfile.fs.removeSync(paths.NpmciPackageConfig);
return;
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,29 +1,31 @@
import * as plugins from './mod.plugins'
import * as plugins from './mod.plugins';
let npmciCflare = new plugins.cflare.CflareAccount()
let npmciCflare = new plugins.cflare.CflareAccount();
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
export let handleCli = async argvArg => {
if (argvArg._.length >= 2) {
let action: string = argvArg._[1]
let action: string = argvArg._[1];
switch (action) {
default:
plugins.beautylog.error(`>>npmci cloudflare ...<< action >>${action}<< not supported`)
process.exit(1)
plugins.beautylog.error(`>>npmci cloudflare ...<< action >>${action}<< not supported`);
process.exit(1);
}
} else {
plugins.beautylog.log(`>>npmci cloudflare ...<< cli arguments invalid... Please read the documentation.`)
process.exit(1)
plugins.beautylog.log(
`>>npmci cloudflare ...<< cli arguments invalid... Please read the documentation.`
);
process.exit(1);
}
}
};
export let purge = async (argvArg) => {
export let purge = async argvArg => {
npmciCflare.auth({
email: '',
key: ''
})
npmciCflare.purgeZone(argvArg._[1])
}
});
npmciCflare.purgeZone(argvArg._[1]);
};

View File

@ -1,7 +1,5 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';
import * as cflare from 'cflare'
import * as cflare from 'cflare';
export {
cflare
}
export { cflare };

View File

@ -1,13 +1,15 @@
import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import * as plugins from './mod.plugins';
import { bash } from '../npmci.bash';
export let command = async () => {
let wrappedCommand: string = ''
let argvArray = process.argv
let wrappedCommand: string = '';
let argvArray = process.argv;
for (let i = 3; i < argvArray.length; i++) {
wrappedCommand = wrappedCommand + argvArray[i]
if (i + 1 !== argvArray.length) { wrappedCommand = wrappedCommand + ' ' }
wrappedCommand = wrappedCommand + argvArray[i];
if (i + 1 !== argvArray.length) {
wrappedCommand = wrappedCommand + ' ';
}
}
await bash(wrappedCommand)
return
}
await bash(wrappedCommand);
return;
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,76 +1,76 @@
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
import { bash } from '../npmci.bash'
import * as plugins from './mod.plugins';
import * as paths from '../npmci.paths';
import { bash } from '../npmci.bash';
import * as helpers from './mod.helpers'
import * as helpers from './mod.helpers';
// classes
import { Dockerfile } from './mod.classes.dockerfile'
import { DockerRegistry } from './mod.classes.dockerregistry'
import { RegistryStorage } from './mod.classes.registrystorage'
import { Dockerfile } from './mod.classes.dockerfile';
import { DockerRegistry } from './mod.classes.dockerregistry';
import { RegistryStorage } from './mod.classes.registrystorage';
// instances
let npmciRegistryStorage = new RegistryStorage()
let npmciRegistryStorage = new RegistryStorage();
export {
Dockerfile,
helpers
}
export { Dockerfile, helpers };
export let modArgvArg // will be set through the build command
export let modArgvArg; // will be set through the build command
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
modArgvArg = argvArg
export let handleCli = async argvArg => {
modArgvArg = argvArg;
if (argvArg._.length >= 2) {
let action: string = argvArg._[ 1 ]
let action: string = argvArg._[1];
switch (action) {
case 'build':
await build()
break
await build();
break;
case 'login':
case 'prepare':
await login()
break
await login();
break;
case 'test':
await test()
break
await test();
break;
case 'push':
await push(argvArg)
break
await push(argvArg);
break;
case 'pull':
await pull(argvArg)
break
await pull(argvArg);
break;
default:
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`)
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`);
}
} else {
plugins.beautylog.log(`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`)
plugins.beautylog.log(
`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`
);
}
}
};
/**
* builds a cwd of Dockerfiles by triggering a promisechain
*/
export let build = async () => {
await prepare()
plugins.beautylog.log('now building Dockerfiles...')
await helpers.readDockerfiles()
await prepare();
plugins.beautylog.log('now building Dockerfiles...');
await helpers
.readDockerfiles()
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles)
.then(helpers.buildDockerfiles)
}
.then(helpers.buildDockerfiles);
};
/**
* login to the DockerRegistries
*/
export let login = async () => {
await prepare()
await npmciRegistryStorage.loginAll()
}
await prepare();
await npmciRegistryStorage.loginAll();
};
/**
* logs in docker
@ -78,62 +78,65 @@ export let login = async () => {
export let prepare = async () => {
// Always login to GitLab Registry
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
plugins.beautylog.error('No registry token specified by gitlab!')
process.exit(1)
plugins.beautylog.error('No registry token specified by gitlab!');
process.exit(1);
}
npmciRegistryStorage.addRegistry(new DockerRegistry({
registryUrl: 'registry.gitlab.com',
username: 'gitlab-ci-token',
password: process.env.CI_BUILD_TOKEN
}))
npmciRegistryStorage.addRegistry(
new DockerRegistry({
registryUrl: 'registry.gitlab.com',
username: 'gitlab-ci-token',
password: process.env.CI_BUILD_TOKEN
})
);
// handle registries
await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_LOGIN_DOCKER*', async (envString) => {
npmciRegistryStorage.addRegistry(
DockerRegistry.fromEnvString(envString)
)
})
return
}
await plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_LOGIN_DOCKER*', async envString => {
npmciRegistryStorage.addRegistry(DockerRegistry.fromEnvString(envString));
});
return;
};
export let push = async (argvArg) => {
await prepare()
let registryUrlArg = argvArg._[ 2 ]
let suffix = null
export let push = async argvArg => {
await prepare();
let registryUrlArg = argvArg._[2];
let suffix = null;
if (argvArg._.length >= 4) {
suffix = argvArg._[ 3 ]
suffix = argvArg._[3];
}
let dockerfileArray = await helpers.readDockerfiles()
let dockerfileArray = await helpers
.readDockerfiles()
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles)
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg)
.then(helpers.mapDockerfiles);
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
if (!localDockerRegistry) {
plugins.beautylog.error(`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.`)
process.exit(1)
plugins.beautylog.error(
`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.`
);
process.exit(1);
}
for (let dockerfile of dockerfileArray) {
await dockerfile.push(localDockerRegistry, suffix)
await dockerfile.push(localDockerRegistry, suffix);
}
}
};
export let pull = async (argvArg) => {
await prepare()
let registryUrlArg = argvArg._[ 2 ]
let suffix = null
export let pull = async argvArg => {
await prepare();
let registryUrlArg = argvArg._[2];
let suffix = null;
if (argvArg._.length >= 4) {
suffix = argvArg._[ 3 ]
suffix = argvArg._[3];
}
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg)
let dockerfileArray = await helpers.readDockerfiles()
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg);
let dockerfileArray = await helpers
.readDockerfiles()
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles)
.then(helpers.mapDockerfiles);
for (let dockerfile of dockerfileArray) {
await dockerfile.pull(localDockerRegistry, suffix)
await dockerfile.pull(localDockerRegistry, suffix);
}
}
};
export let test = async () => {
await prepare()
return await helpers.readDockerfiles()
.then(helpers.testDockerfiles)
}
await prepare();
return await helpers.readDockerfiles().then(helpers.testDockerfiles);
};

View File

@ -1,93 +1,109 @@
import * as plugins from './mod.plugins'
import * as NpmciEnv from '../npmci.env'
import { bash } from '../npmci.bash'
import * as paths from '../npmci.paths'
import * as plugins from './mod.plugins';
import * as NpmciEnv from '../npmci.env';
import { bash } from '../npmci.bash';
import * as paths from '../npmci.paths';
import { DockerRegistry } from './mod.classes.dockerregistry'
import * as helpers from './mod.helpers'
import { DockerRegistry } from './mod.classes.dockerregistry';
import * as helpers from './mod.helpers';
/**
* class Dockerfile represents a Dockerfile on disk in npmci
*/
export class Dockerfile {
filePath: string
repo: string
version: string
cleanTag: string
buildTag: 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 = helpers.dockerFileVersion(plugins.path.parse(options.filePath).base)
this.cleanTag = this.repo + ':' + this.version
this.buildTag = this.cleanTag
filePath: string;
repo: string;
version: string;
cleanTag: string;
buildTag: 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 = helpers.dockerFileVersion(plugins.path.parse(options.filePath).base);
this.cleanTag = this.repo + ':' + this.version;
this.buildTag = this.cleanTag;
this.containerName = 'dockerfile-' + this.version
this.containerName = 'dockerfile-' + this.version;
if (options.filePath && options.read) {
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath))
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath));
}
this.baseImage = helpers.dockerBaseImage(this.content)
this.localBaseImageDependent = false
this.baseImage = helpers.dockerBaseImage(this.content);
this.localBaseImageDependent = false;
}
/**
* builds the Dockerfile
*/
async build () {
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag)
let buildArgsString = await helpers.getDockerBuildArgs()
let buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`
await bash(buildCommand)
return
async build() {
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag);
let buildArgsString = await helpers.getDockerBuildArgs();
let buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`;
await bash(buildCommand);
return;
}
/**
* pushes the Dockerfile to a registry
*/
async push (dockerRegistryArg: DockerRegistry, versionSuffix: string = null) {
let pushTag = helpers.getDockerTagString(dockerRegistryArg.registryUrl, this.repo, this.version, versionSuffix)
await bash(`docker tag ${this.buildTag} ${pushTag}`)
await bash(`docker push ${pushTag}`)
async push(dockerRegistryArg: DockerRegistry, versionSuffix: string = null) {
let pushTag = helpers.getDockerTagString(
dockerRegistryArg.registryUrl,
this.repo,
this.version,
versionSuffix
);
await bash(`docker tag ${this.buildTag} ${pushTag}`);
await bash(`docker push ${pushTag}`);
}
/**
* pulls the Dockerfile from a registry
*/
async pull (registryArg: DockerRegistry, versionSuffixArg: string = null) {
let pullTag = helpers.getDockerTagString(registryArg.registryUrl,this.repo, this.version, versionSuffixArg)
await bash(`docker pull ${pullTag}`)
await bash(`docker tag ${pullTag} ${this.buildTag}`)
async pull(registryArg: DockerRegistry, versionSuffixArg: string = null) {
let pullTag = helpers.getDockerTagString(
registryArg.registryUrl,
this.repo,
this.version,
versionSuffixArg
);
await bash(`docker pull ${pullTag}`);
await bash(`docker tag ${pullTag} ${this.buildTag}`);
}
/**
* tests the Dockerfile;
*/
async test () {
let testFile: string = plugins.path.join(paths.NpmciTestDir, 'test_' + this.version + '.sh')
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile)
async test() {
let testFile: string = plugins.path.join(paths.NpmciTestDir, 'test_' + this.version + '.sh');
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile);
if (testFileExists) {
// run tests
await bash(`docker run --name npmci_test_container --entrypoint="bash" ${this.buildTag} -c "mkdir /npmci_test"`)
await bash(`docker cp ${testFile} npmci_test_container:/npmci_test/test.sh`)
await bash(`docker commit npmci_test_container npmci_test_image`)
await bash(`docker run --entrypoint="bash" npmci_test_image -x /npmci_test/test.sh`)
await bash(`docker rm npmci_test_container`)
await bash(`docker rmi --force npmci_test_image`)
await bash(
`docker run --name npmci_test_container --entrypoint="bash" ${
this.buildTag
} -c "mkdir /npmci_test"`
);
await bash(`docker cp ${testFile} npmci_test_container:/npmci_test/test.sh`);
await bash(`docker commit npmci_test_container npmci_test_image`);
await bash(`docker run --entrypoint="bash" npmci_test_image -x /npmci_test/test.sh`);
await bash(`docker rm npmci_test_container`);
await bash(`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
*/
async getId () {
let containerId = await bash('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
return containerId
async getId() {
let containerId = await bash('docker inspect --type=image --format="{{.Id}}" ' + this.buildTag);
return containerId;
}
}

View File

@ -1,47 +1,47 @@
import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import * as plugins from './mod.plugins';
import { bash } from '../npmci.bash';
export interface IDockerRegistryConstructorOptions {
registryUrl: string,
username: string,
password: string
registryUrl: string;
username: string;
password: string;
}
export class DockerRegistry {
registryUrl: string
username: string
password: string
constructor (optionsArg: IDockerRegistryConstructorOptions) {
this.registryUrl = optionsArg.registryUrl
this.username = optionsArg.username
this.password = optionsArg.password
plugins.beautylog.info(`created DockerRegistry for ${this.registryUrl}`)
registryUrl: string;
username: string;
password: string;
constructor(optionsArg: IDockerRegistryConstructorOptions) {
this.registryUrl = optionsArg.registryUrl;
this.username = optionsArg.username;
this.password = optionsArg.password;
plugins.beautylog.info(`created DockerRegistry for ${this.registryUrl}`);
}
static fromEnvString (envString: string): DockerRegistry {
let dockerRegexResultArray = envString.split('|')
static fromEnvString(envString: string): DockerRegistry {
let dockerRegexResultArray = envString.split('|');
if (dockerRegexResultArray.length !== 3) {
plugins.beautylog.error('malformed docker env var...')
process.exit(1)
return
plugins.beautylog.error('malformed docker env var...');
process.exit(1);
return;
}
let registryUrl = dockerRegexResultArray[0]
let username = dockerRegexResultArray[1]
let password = dockerRegexResultArray[2]
let registryUrl = dockerRegexResultArray[0];
let username = dockerRegexResultArray[1];
let password = dockerRegexResultArray[2];
return new DockerRegistry({
registryUrl: registryUrl,
username: username,
password: password
})
});
}
async login () {
async login() {
if (this.registryUrl === 'docker.io') {
await bash(`docker login -u ${this.username} -p ${this.password}`)
plugins.beautylog.info('Logged in to standard docker hub')
await bash(`docker login -u ${this.username} -p ${this.password}`);
plugins.beautylog.info('Logged in to standard docker hub');
} else {
await bash(`docker login -u ${this.username} -p ${this.password} ${this.registryUrl}`)
await bash(`docker login -u ${this.username} -p ${this.password} ${this.registryUrl}`);
}
plugins.beautylog.ok(`docker authenticated for ${this.registryUrl}!`)
plugins.beautylog.ok(`docker authenticated for ${this.registryUrl}!`);
}
}

View File

@ -1,28 +1,28 @@
import * as plugins from './mod.plugins'
import { Objectmap } from 'lik'
import * as plugins from './mod.plugins';
import { Objectmap } from 'lik';
import { DockerRegistry } from './mod.classes.dockerregistry'
import { DockerRegistry } from './mod.classes.dockerregistry';
export class RegistryStorage {
objectMap = new Objectmap<DockerRegistry>()
constructor () {
objectMap = new Objectmap<DockerRegistry>();
constructor() {
// Nothing here
}
addRegistry (registryArg: DockerRegistry) {
this.objectMap.add(registryArg)
addRegistry(registryArg: DockerRegistry) {
this.objectMap.add(registryArg);
}
getRegistryByUrl (registryUrlArg: string) {
getRegistryByUrl(registryUrlArg: string) {
return this.objectMap.find(registryArg => {
return registryArg.registryUrl === registryUrlArg
})
return registryArg.registryUrl === registryUrlArg;
});
}
async loginAll () {
async loginAll() {
await this.objectMap.forEach(async registryArg => {
await registryArg.login()
})
plugins.beautylog.success('logged in successfully into all available DockerRegistries!')
await registryArg.login();
});
plugins.beautylog.success('logged in successfully into all available DockerRegistries!');
}
}

View File

@ -1,33 +1,32 @@
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
import * as NpmciEnv from '../npmci.env'
import * as NpmciConfig from '../npmci.config'
import { bash } from '../npmci.bash'
import * as plugins from './mod.plugins';
import * as paths from '../npmci.paths';
import * as NpmciEnv from '../npmci.env';
import * as NpmciConfig from '../npmci.config';
import { bash } from '../npmci.bash';
import { Dockerfile } from './mod.classes.dockerfile'
import { Dockerfile } from './mod.classes.dockerfile';
/**
* creates instance of class Dockerfile for all Dockerfiles in cwd
* @returns Promise<Dockerfile[]>
*/
export let readDockerfiles = async (): Promise<Dockerfile[]> => {
let fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*')
let fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, 'Dockerfile*');
// create the Dockerfile array
let readDockerfilesArray: Dockerfile[] = []
plugins.beautylog.info(`found ${fileTree.length} Dockerfiles:`)
console.log(fileTree)
let readDockerfilesArray: Dockerfile[] = [];
plugins.beautylog.info(`found ${fileTree.length} Dockerfiles:`);
console.log(fileTree);
for (let dockerfilePath of fileTree) {
let myDockerfile = new Dockerfile({
filePath: dockerfilePath,
read: true
})
readDockerfilesArray.push(myDockerfile)
});
readDockerfilesArray.push(myDockerfile);
}
return readDockerfilesArray
}
return readDockerfilesArray;
};
/**
* sorts Dockerfiles into a dependency chain
@ -35,62 +34,65 @@ export let readDockerfiles = async (): Promise<Dockerfile[]> => {
* @returns Promise<Dockerfile[]>
*/
export let sortDockerfiles = (sortableArrayArg: Dockerfile[]): Promise<Dockerfile[]> => {
let done = plugins.q.defer<Dockerfile[]>()
plugins.beautylog.info('sorting Dockerfiles:')
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)
let done = plugins.q.defer<Dockerfile[]>();
plugins.beautylog.info('sorting Dockerfiles:');
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);
}
if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) {
dockerfileArg.localBaseImageDependent = true
dockerfileArg.localBaseImageDependent = true;
}
})
});
if (sortableArrayArg.length === sortedArray.length) {
let counter = 1
let counter = 1;
for (let dockerfile of sortedArray) {
plugins.beautylog.log(`tag ${counter}: -> ${dockerfile.cleanTag}`)
counter++
plugins.beautylog.log(`tag ${counter}: -> ${dockerfile.cleanTag}`);
counter++;
}
done.resolve(sortedArray)
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 = async (sortedArray: Dockerfile[]): Promise<Dockerfile[]> => {
sortedArray.forEach((dockerfileArg) => {
sortedArray.forEach(dockerfileArg => {
if (dockerfileArg.localBaseImageDependent) {
sortedArray.forEach((dockfile2: Dockerfile) => {
if (dockfile2.cleanTag === dockerfileArg.baseImage) {
dockerfileArg.localBaseDockerfile = dockfile2
dockerfileArg.localBaseDockerfile = dockfile2;
}
})
});
}
})
return sortedArray
}
});
return sortedArray;
};
/**
* builds the correspoding real docker image for each Dockerfile class instance
*/
export let buildDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
for (let dockerfileArg of sortedArrayArg) {
await dockerfileArg.build()
await dockerfileArg.build();
}
return sortedArrayArg
}
return sortedArrayArg;
};
/**
* tests all Dockerfiles in by calling class Dockerfile.test();
@ -98,80 +100,87 @@ export let buildDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
*/
export let testDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
for (let dockerfileArg of sortedArrayArg) {
await dockerfileArg.test()
await dockerfileArg.test();
}
return sortedArrayArg
}
return sortedArrayArg;
};
/**
* returns a version for a docker file
* @execution SYNC
*/
export let dockerFileVersion = (dockerfileNameArg: string): string => {
let versionString: string
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/
let regexResultArray = versionRegex.exec(dockerfileNameArg)
let versionString: string;
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/;
let regexResultArray = versionRegex.exec(dockerfileNameArg);
if (regexResultArray && regexResultArray.length === 2) {
versionString = regexResultArray[ 1 ]
versionString = regexResultArray[1];
} else {
versionString = 'latest'
versionString = 'latest';
}
return versionString
}
return versionString;
};
/**
* returns the docker base image for a Dockerfile
*/
export let dockerBaseImage = function (dockerfileContentArg: string) {
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
return regexResultArray[ 1 ]
}
export let dockerBaseImage = function(dockerfileContentArg: string) {
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/;
let regexResultArray = baseImageRegex.exec(dockerfileContentArg);
return regexResultArray[1];
};
/**
* returns the docker tag
*/
export let getDockerTagString = (registryArg: string, repoArg: string, versionArg: string, suffixArg?: string): string => {
export let getDockerTagString = (
registryArg: string,
repoArg: string,
versionArg: string,
suffixArg?: string
): string => {
// determine wether the repo should be mapped accordingly to the registry
let mappedRepo = NpmciConfig.configObject.dockerRegistryRepoMap[registryArg]
let mappedRepo = NpmciConfig.configObject.dockerRegistryRepoMap[registryArg];
let repo = (() => {
if (mappedRepo) {
return mappedRepo
return mappedRepo;
} else {
return repoArg
return repoArg;
}
})()
})();
// determine wether the version contais a suffix
let version = versionArg
let version = versionArg;
if (suffixArg) {
version = versionArg + '_' + suffixArg
version = versionArg + '_' + suffixArg;
}
let tagString = `${registryArg}/${repo}:${version}`
return tagString
}
let tagString = `${registryArg}/${repo}:${version}`;
return tagString;
};
export let getDockerBuildArgs = async (): Promise<string> => {
plugins.beautylog.info('checking for env vars to be supplied to the docker build')
let buildArgsString: string = ''
plugins.beautylog.info('checking for env vars to be supplied to the docker build');
let buildArgsString: string = '';
for (let key in NpmciConfig.configObject.dockerBuildargEnvMap) {
let targetValue = process.env[NpmciConfig.configObject.dockerBuildargEnvMap[key]]
buildArgsString = `${buildArgsString} --build-arg ${key}=${targetValue}`
let targetValue = process.env[NpmciConfig.configObject.dockerBuildargEnvMap[key]];
buildArgsString = `${buildArgsString} --build-arg ${key}=${targetValue}`;
}
return buildArgsString
}
return buildArgsString;
};
/**
*
*
*/
export let cleanTagsArrayFunction = function (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]): string[] {
let cleanTagsArray: string[] = []
dockerfileArrayArg.forEach(function (dockerfileArg) {
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)
cleanTagsArray.push(dockerfileArg.cleanTag);
}
})
return cleanTagsArray
}
});
return cleanTagsArray;
};

View File

@ -1,3 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,41 +1,45 @@
import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import { repo } from '../npmci.env'
import * as plugins from './mod.plugins';
import { bash } from '../npmci.bash';
import { repo } from '../npmci.env';
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
export let handleCli = async argvArg => {
if (argvArg._.length >= 2) {
let action: string = argvArg._[ 1 ]
let action: string = argvArg._[1];
switch (action) {
case 'mirror':
await mirror()
break
await mirror();
break;
default:
plugins.beautylog.error(`>>npmci git ...<< action >>${action}<< not supported`)
plugins.beautylog.error(`>>npmci git ...<< action >>${action}<< not supported`);
}
} else {
plugins.beautylog.log(`>>npmci git ...<< cli arguments invalid... Please read the documentation.`)
plugins.beautylog.log(
`>>npmci git ...<< cli arguments invalid... Please read the documentation.`
);
}
}
};
export let mirror = async () => {
let githubToken = process.env.NPMCI_GIT_GITHUBTOKEN
let githubUser = process.env.NPMCI_GIT_GITHUBGROUP || repo.user
let githubRepo = process.env.NPMCI_GIT_GITHUB || repo.repo
let githubToken = process.env.NPMCI_GIT_GITHUBTOKEN;
let githubUser = process.env.NPMCI_GIT_GITHUBGROUP || repo.user;
let githubRepo = process.env.NPMCI_GIT_GITHUB || repo.repo;
if (githubToken) {
plugins.beautylog.info('found github token.')
plugins.beautylog.log('attempting the mirror the repository to GitHub')
plugins.beautylog.info('found github token.');
plugins.beautylog.log('attempting the mirror the repository to GitHub');
// add the mirror
await bash(`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`)
await bash(`git push mirror --all`)
plugins.beautylog.ok('pushed all branches to mirror!')
await bash(`git push mirror --tags`)
plugins.beautylog.ok('pushed all tags to mirror!')
await bash(
`git remote add mirror https://${githubToken}@github.com/${githubUser}/${githubRepo}.git`
);
await bash(`git push mirror --all`);
plugins.beautylog.ok('pushed all branches to mirror!');
await bash(`git push mirror --tags`);
plugins.beautylog.ok('pushed all tags to mirror!');
} else {
plugins.beautylog.error(`cannot find NPMCI_GIT_GITHUBTOKEN env var!`)
process.exit(1)
plugins.beautylog.error(`cannot find NPMCI_GIT_GITHUBTOKEN env var!`);
process.exit(1);
}
}
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,77 +1,72 @@
import * as plugins from '../npmci.plugins'
import * as npmciConfig from '../npmci.config'
import {
bash,
bashNoError,
nvmAvailable,
yarnAvailable
} from '../npmci.bash'
import * as plugins from '../npmci.plugins';
import * as npmciConfig from '../npmci.config';
import { bash, bashNoError, nvmAvailable, yarnAvailable } from '../npmci.bash';
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
export let handleCli = async argvArg => {
if (argvArg._.length >= 3) {
let action: string = argvArg._[1]
let action: string = argvArg._[1];
switch (action) {
case 'install':
await install(argvArg._[2])
break
await install(argvArg._[2]);
break;
default:
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`)
process.exit(1)
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`);
process.exit(1);
}
} else {
plugins.beautylog.error(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`)
process.exit(1)
plugins.beautylog.error(
`>>npmci node ...<< cli arguments invalid... Please read the documentation.`
);
process.exit(1);
}
}
};
/**
* Install a specific version of node
* @param versionArg
*/
export let install = async (versionArg) => {
plugins.beautylog.log(`now installing node version ${versionArg}`)
let version: string
export let install = async versionArg => {
plugins.beautylog.log(`now installing node version ${versionArg}`);
let version: string;
if (versionArg === 'stable') {
version = 'stable'
version = 'stable';
} else if (versionArg === 'lts') {
version = '8'
version = '8';
} else if (versionArg === 'legacy') {
version = '8'
version = '8';
} else {
version = versionArg
version = versionArg;
}
if (await nvmAvailable.promise) {
await bash(`nvm install ${version} && nvm alias default ${version}`)
plugins.beautylog.success(`Node version ${version} successfully installed!`)
await bash(`nvm install ${version} && nvm alias default ${version}`);
plugins.beautylog.success(`Node version ${version} successfully installed!`);
} else {
plugins.beautylog.warn('Nvm not in path so staying at installed node version!')
plugins.beautylog.warn('Nvm not in path so staying at installed node version!');
}
await bash('node -v')
await bash('npm -v')
await bash('node -v');
await bash('npm -v');
// lets look for further config
await npmciConfig.getConfig()
.then(async configArg => {
plugins.beautylog.log('Now checking for needed global npm tools...')
for (let npmTool of configArg.npmGlobalTools) {
plugins.beautylog.info(`Checking for global "${npmTool}"`)
let whichOutput: string = await bashNoError(`which ${npmTool}`)
let toolAvailable: boolean = !((/not\sfound/.test(whichOutput)) || whichOutput === '')
if (toolAvailable) {
plugins.beautylog.log(`Tool ${npmTool} is available`)
await npmciConfig.getConfig().then(async configArg => {
plugins.beautylog.log('Now checking for needed global npm tools...');
for (let npmTool of configArg.npmGlobalTools) {
plugins.beautylog.info(`Checking for global "${npmTool}"`);
let whichOutput: string = await bashNoError(`which ${npmTool}`);
let toolAvailable: boolean = !(/not\sfound/.test(whichOutput) || whichOutput === '');
if (toolAvailable) {
plugins.beautylog.log(`Tool ${npmTool} is available`);
} else {
plugins.beautylog.info(`globally installing ${npmTool} from npm`);
if (await yarnAvailable.promise) {
await bash(`yarn global add ${npmTool}`);
} else {
plugins.beautylog.info(`globally installing ${npmTool} from npm`)
if (await yarnAvailable.promise) {
await bash(`yarn global add ${npmTool}`)
} else {
await bash(`npm install ${npmTool} -q -g`)
}
await bash(`npm install ${npmTool} -q -g`);
}
}
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!')
})
}
}
plugins.beautylog.success('all global npm tools specified in npmextra.json are now available!');
});
};

View File

@ -1,73 +1,78 @@
import * as plugins from './mod.plugins'
import * as configModule from '../npmci.config'
import {
bash,
bashNoError,
nvmAvailable,
yarnAvailable
} from '../npmci.bash'
import * as plugins from './mod.plugins';
import * as configModule from '../npmci.config';
import { bash, bashNoError, nvmAvailable, yarnAvailable } from '../npmci.bash';
/**
* handle cli input
* @param argvArg
*/
export let handleCli = async (argvArg) => {
export let handleCli = async argvArg => {
if (argvArg._.length >= 2) {
let action: string = argvArg._[1]
let action: string = argvArg._[1];
switch (action) {
case 'install':
await install()
break
await install();
break;
case 'prepare':
await prepare()
break
await prepare();
break;
case 'test':
await test()
break
await test();
break;
case 'publish':
await publish()
break
await publish();
break;
default:
plugins.beautylog.error(`>>npmci npm ...<< action >>${action}<< not supported`)
process.exit(1)
plugins.beautylog.error(`>>npmci npm ...<< action >>${action}<< not supported`);
process.exit(1);
}
} else {
plugins.beautylog.log(`>>npmci npm ...<< cli arguments invalid... Please read the documentation.`)
process.exit(1)
plugins.beautylog.log(
`>>npmci npm ...<< cli arguments invalid... Please read the documentation.`
);
process.exit(1);
}
}
};
/**
* authenticates npm with token from env var
*/
let prepare = async () => {
let npmrcPrefix: string = '//registry.npmjs.org/:_authToken='
let npmToken: string = process.env.NPMCI_TOKEN_NPM
let npmrcFileString: string = npmrcPrefix + npmToken
let npmrcPrefix: string = '//registry.npmjs.org/:_authToken=';
let npmToken: string = process.env.NPMCI_TOKEN_NPM;
let npmrcFileString: string = npmrcPrefix + npmToken;
if (npmToken) {
plugins.beautylog.info('found access token')
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')
return
}
plugins.smartfile.memory.toFsSync(npmrcFileString, '/root/.npmrc');
return;
};
let publish = async () => {
await bash('npm publish')
}
let npmAccessCliString = ``;
const config = await configModule.getConfig();
if (
config.npmAccessLevel &&
(config.npmAccessLevel === 'public' || config.npmAccessLevel === 'private')
) {
npmAccessCliString = `--access=${config.npmAccessLevel}`;
}
await bash(`npm publish ${npmAccessCliString}`);
};
let install = async (): Promise<void> => {
plugins.beautylog.info('now installing dependencies:')
plugins.beautylog.info('now installing dependencies:');
if (await yarnAvailable.promise) {
await bash('yarn install')
await bash('yarn install');
} else {
await bash('npm install')
await bash('npm install');
}
}
};
export let test = async (): Promise<void> => {
plugins.beautylog.info('now starting tests:')
await bash('yarn test')
}
plugins.beautylog.info('now starting tests:');
await bash('yarn test');
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,63 +1,63 @@
import * as plugins from './mod.plugins'
let sshInstance: plugins.smartssh.SshInstance
import * as plugins from './mod.plugins';
let sshInstance: plugins.smartssh.SshInstance;
export let handleCli = async (argvArg) => {
export let handleCli = async argvArg => {
if (argvArg._.length >= 2) {
let action: string = argvArg._[1]
let action: string = argvArg._[1];
switch (action) {
case 'prepare':
await prepare()
break
await prepare();
break;
default:
plugins.beautylog.error(`action >>${action}<< not supported`)
process.exit(1)
plugins.beautylog.error(`action >>${action}<< not supported`);
process.exit(1);
}
} else {
plugins.beautylog.error(`>>npmci ssh ...<< please specify an action!`)
process.exit(1)
plugins.beautylog.error(`>>npmci ssh ...<< please specify an action!`);
process.exit(1);
}
}
};
/**
* checks if not undefined
*/
let notUndefined = (stringArg: string) => {
return (stringArg && stringArg !== 'undefined' && stringArg !== '##')
}
return stringArg && stringArg !== 'undefined' && stringArg !== '##';
};
/**
* checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones
*/
export let prepare = async () => {
sshInstance = new plugins.smartssh.SshInstance() // init ssh instance
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_SSHKEY_*', evaluateSshEnv)
sshInstance = new plugins.smartssh.SshInstance(); // init ssh instance
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_SSHKEY_*', evaluateSshEnv);
if (!process.env.NPMTS_TEST) {
sshInstance.writeToDisk()
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!');
}
}
};
/**
* gets called for each found SSH ENV Var and deploys it
*/
let evaluateSshEnv = async (sshkeyEnvVarArg: string) => {
let sshEnvArray = sshkeyEnvVarArg.split('|')
let sshKey = new plugins.smartssh.SshKey()
plugins.beautylog.info('Found SSH identity for ' + sshEnvArray[1])
let sshEnvArray = sshkeyEnvVarArg.split('|');
let sshKey = new plugins.smartssh.SshKey();
plugins.beautylog.info('Found SSH identity for ' + sshEnvArray[1]);
if (notUndefined(sshEnvArray[0])) {
plugins.beautylog.log('---> host defined!')
sshKey.host = sshEnvArray[0]
plugins.beautylog.log('---> host defined!');
sshKey.host = sshEnvArray[0];
}
if (notUndefined(sshEnvArray[1])) {
plugins.beautylog.log('---> privKey defined!')
sshKey.privKeyBase64 = sshEnvArray[1]
plugins.beautylog.log('---> privKey defined!');
sshKey.privKeyBase64 = sshEnvArray[1];
}
if (notUndefined(sshEnvArray[2])) {
plugins.beautylog.log('---> pubKey defined!')
sshKey.pubKeyBase64 = sshEnvArray[2]
plugins.beautylog.log('---> pubKey defined!');
sshKey.pubKeyBase64 = sshEnvArray[2];
}
sshInstance.addKey(sshKey)
return
}
sshInstance.addKey(sshKey);
return;
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,29 +1,28 @@
import * as plugins from './mod.plugins'
import { bash } from '../npmci.bash'
import * as plugins from './mod.plugins';
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 = async () => {
plugins.beautylog.info('now running triggers')
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger)
}
plugins.beautylog.info('now running triggers');
plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_TRIGGER_*', evaluateTrigger);
};
let evaluateTrigger = async (triggerEnvVarArg) => {
let triggerRegexResultArray = triggerValueRegex.exec(triggerEnvVarArg)
let regexDomain = triggerRegexResultArray[1]
let regexProjectId = triggerRegexResultArray[2]
let regexProjectTriggerToken = triggerRegexResultArray[3]
let regexRefName = triggerRegexResultArray[4]
let regexTriggerName
let evaluateTrigger = async 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]
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 }
});
};

View File

@ -1 +1 @@
export * from '../npmci.plugins'
export * from '../npmci.plugins';

View File

@ -1,20 +1,20 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as plugins from './npmci.plugins';
import * as paths from './npmci.paths';
import * as smartq from 'smartq'
import * as smartq from 'smartq';
/**
* wether nvm is available or not
*/
export let nvmAvailable = smartq.defer<boolean>()
export let yarnAvailable = smartq.defer<boolean>()
export let nvmAvailable = smartq.defer<boolean>();
export let yarnAvailable = smartq.defer<boolean>();
/**
* the smartshell instance for npmci
*/
let npmciSmartshell = new plugins.smartshell.Smartshell({
executor: 'bash',
sourceFilePaths: []
})
});
/**
* check for tools.
@ -25,31 +25,35 @@ let checkToolsAvailable = async () => {
if (
(await plugins.smartshell.execSilent(`bash -c "source /usr/local/nvm/nvm.sh"`)).exitCode === 0
) {
npmciSmartshell.addSourceFiles([ `/usr/local/nvm/nvm.sh` ])
nvmAvailable.resolve(true)
npmciSmartshell.addSourceFiles([`/usr/local/nvm/nvm.sh`]);
nvmAvailable.resolve(true);
} else if (
(await plugins.smartshell.execSilent(`bash -c "source ~/.nvm/nvm.sh"`)).exitCode === 0
) {
npmciSmartshell.addSourceFiles([ `~/.nvm/nvm.sh` ])
nvmAvailable.resolve(true)
npmciSmartshell.addSourceFiles([`~/.nvm/nvm.sh`]);
nvmAvailable.resolve(true);
} else {
nvmAvailable.resolve(false)
nvmAvailable.resolve(false);
}
// check for yarn
await plugins.smartshell.which('yarn').then(
async () => {
await plugins.smartshell.exec(`yarn config set cache-folder ${plugins.path.join(paths.cwd, '.yarn')}`)
yarnAvailable.resolve(true)
await plugins.smartshell.exec(
`yarn config set cache-folder ${plugins.path.join(paths.cwd, '.yarn')}`
);
yarnAvailable.resolve(true);
},
() => { yarnAvailable.resolve(false) }
)
() => {
yarnAvailable.resolve(false);
}
);
} else {
nvmAvailable.resolve(true)
yarnAvailable.resolve(true)
nvmAvailable.resolve(true);
yarnAvailable.resolve(true);
}
}
checkToolsAvailable()
};
checkToolsAvailable();
/**
* bash() allows using bash with nvm in path
@ -57,49 +61,54 @@ checkToolsAvailable()
* @param retryArg - The retryArg: 0 to any positive number will retry, -1 will always succeed, -2 will return undefined
*/
export let bash = async (commandArg: string, retryArg: number = 2): Promise<string> => {
await nvmAvailable.promise // make sure nvm check has run
let execResult: plugins.smartshell.IExecResult
await nvmAvailable.promise; // make sure nvm check has run
let execResult: plugins.smartshell.IExecResult;
// determine if we fail
let failOnError: boolean = true
let failOnError: boolean = true;
if (retryArg === -1) {
failOnError = false
retryArg = 0
failOnError = false;
retryArg = 0;
}
if (!process.env.NPMTS_TEST) { // NPMTS_TEST is used during testing
if (!process.env.NPMTS_TEST) {
// NPMTS_TEST is used during testing
for (let i = 0; i <= retryArg; i++) {
if (process.env.DEBUG_NPMCI === 'true') {
console.log(commandArg)
console.log(commandArg);
}
execResult = await npmciSmartshell.exec(commandArg)
execResult = await npmciSmartshell.exec(commandArg);
// determine how bash reacts to error and success
if (execResult.exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted
if (execResult.exitCode !== 0 && i === retryArg) {
// something went wrong and retries are exhausted
if (failOnError) {
plugins.beautylog.error('something went wrong and retries are exhausted')
process.exit(1)
plugins.beautylog.error('something went wrong and retries are exhausted');
process.exit(1);
}
} else if (execResult.exitCode === 0) { // everything went fine, or no error wanted
i = retryArg + 1 // retry +1 breaks for loop, if everything works out ok retrials are not wanted
} else if (execResult.exitCode === 0) {
// everything went fine, or no error wanted
i = retryArg + 1; // retry +1 breaks for loop, if everything works out ok retrials are not wanted
} else {
plugins.beautylog.warn('Something went wrong! Exit Code: ' + execResult.exitCode.toString())
plugins.beautylog.info('Retry ' + (i + 1).toString() + ' of ' + retryArg.toString())
plugins.beautylog.warn(
'Something went wrong! Exit Code: ' + execResult.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);
execResult = {
exitCode: 0,
stdout: 'testOutput'
}
};
}
return execResult.stdout
}
return execResult.stdout;
};
/**
* bashNoError allows executing stuff without throwing an error
*/
export let bashNoError = async (commandArg: string): Promise<string> => {
return await bash(commandArg, -1)
}
return await bash(commandArg, -1);
};

View File

@ -1,104 +1,122 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as npmciMonitor from './npmci.monitor'
npmciMonitor.run()
import * as plugins from './npmci.plugins';
import * as paths from './npmci.paths';
import * as npmciMonitor from './npmci.monitor';
npmciMonitor.run();
// Get Info about npmci itself
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot)
plugins.beautylog.log('npmci version: ' + npmciInfo.version)
let npmciInfo = new plugins.projectinfo.ProjectinfoNpm(paths.NpmciPackageRoot);
plugins.beautylog.log('npmci version: ' + npmciInfo.version);
import * as NpmciEnv from './npmci.env'
import * as NpmciEnv from './npmci.env';
import * as npmciMods from './npmci.mods'
import * as npmciMods from './npmci.mods';
let smartcli = new plugins.smartcli.Smartcli()
smartcli.addVersion(npmciInfo.version)
let smartcli = new plugins.smartcli.Smartcli();
smartcli.addVersion(npmciInfo.version);
// clean
smartcli.addCommand('clean')
.then(async (argv) => {
let modClean = await npmciMods.modClean.load()
await modClean.clean()
}).catch(err => {
console.log(err)
process.exit(1)
smartcli
.addCommand('clean')
.then(async argv => {
let modClean = await npmciMods.modClean.load();
await modClean.clean();
})
.catch(err => {
console.log(err);
process.exit(1);
});
// cloudflare
smartcli.addCommand('cloudflare')
.then(async (argvArg) => {
let modPurge = await npmciMods.modCloudflare.load()
await modPurge.handleCli(argvArg)
}).catch(err => {
console.log(err)
})
// command
smartcli.addCommand('command')
.then(async (argv) => {
let modCommand = await npmciMods.modCommand.load()
await modCommand.command()
}).catch(err => {
console.log(err)
process.exit(1)
smartcli
.addCommand('cloudflare')
.then(async argvArg => {
let modPurge = await npmciMods.modCloudflare.load();
await modPurge.handleCli(argvArg);
})
.catch(err => {
console.log(err);
});
// command
smartcli.addCommand('git')
.then(async (argvArg) => {
let modGit = await npmciMods.modGit.load()
await modGit.handleCli(argvArg)
}).catch(err => {
console.log(err)
process.exit(1)
})
smartcli
.addCommand('command')
.then(async argv => {
let modCommand = await npmciMods.modCommand.load();
await modCommand.command();
})
.catch(err => {
console.log(err);
process.exit(1);
});
// command
smartcli
.addCommand('git')
.then(async argvArg => {
let modGit = await npmciMods.modGit.load();
await modGit.handleCli(argvArg);
})
.catch(err => {
console.log(err);
process.exit(1);
});
// build
smartcli.addCommand('docker')
smartcli
.addCommand('docker')
.then(async argvArg => {
let modDocker = await npmciMods.modDocker.load()
await modDocker.handleCli(argvArg)
}).catch(err => {
console.log(err)
process.exit(1)
let modDocker = await npmciMods.modDocker.load();
await modDocker.handleCli(argvArg);
})
.catch(err => {
console.log(err);
process.exit(1);
});
// node
smartcli.addCommand('node')
.then(async (argvArg) => {
let modNode = await npmciMods.modNode.load()
await modNode.handleCli(argvArg)
}).catch(err => {
console.log(err)
smartcli
.addCommand('node')
.then(async argvArg => {
let modNode = await npmciMods.modNode.load();
await modNode.handleCli(argvArg);
})
.catch(err => {
console.log(err);
});
// npm
smartcli.addCommand('npm')
.then(async (argvArg) => {
let modNpm = await npmciMods.modNpm.load()
await modNpm.handleCli(argvArg)
}).catch(err => {
console.log(err)
smartcli
.addCommand('npm')
.then(async argvArg => {
let modNpm = await npmciMods.modNpm.load();
await modNpm.handleCli(argvArg);
})
.catch(err => {
console.log(err);
});
// trigger
smartcli.addCommand('ssh')
.then(async (argvArg) => {
let modSsh = await npmciMods.modSsh.load()
await modSsh.handleCli(argvArg)
}).catch(err => {
console.log(err)
process.exit(1)
smartcli
.addCommand('ssh')
.then(async argvArg => {
let modSsh = await npmciMods.modSsh.load();
await modSsh.handleCli(argvArg);
})
.catch(err => {
console.log(err);
process.exit(1);
});
// trigger
smartcli.addCommand('trigger')
.then(async (argv) => {
let modTrigger = await npmciMods.modTrigger.load()
await modTrigger.trigger()
}).catch(err => {
console.log(err)
process.exit(1)
smartcli
.addCommand('trigger')
.then(async argv => {
let modTrigger = await npmciMods.modTrigger.load();
await modTrigger.trigger();
})
.catch(err => {
console.log(err);
process.exit(1);
});
smartcli.startParse()
smartcli.startParse();

View File

@ -1,30 +1,34 @@
import * as q from 'q'
import * as q from 'q';
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import * as plugins from './npmci.plugins';
import * as paths from './npmci.paths';
import { repo } from './npmci.env'
import { repo } from './npmci.env';
import { KeyValueStore } from 'npmextra'
import { KeyValueStore } from 'npmextra';
export interface INpmciOptions {
npmGlobalTools: string[]
dockerRegistryRepoMap: any
dockerBuildargEnvMap: any
npmGlobalTools: string[];
npmAccessLevel?: 'private' | 'public';
dockerRegistryRepoMap: any;
dockerBuildargEnvMap: any;
}
// instantiate a kvStorage for the current directory
export let kvStorage = new KeyValueStore('custom', `${repo.user}_${repo.repo}`)
export let kvStorage = new KeyValueStore('custom', `${repo.user}_${repo.repo}`);
// handle config retrival
let npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd)
let npmciNpmextra = new plugins.npmextra.Npmextra(paths.cwd);
let defaultConfig: INpmciOptions = {
npmGlobalTools: [],
dockerRegistryRepoMap: {},
dockerBuildargEnvMap: {}
}
export let configObject = npmciNpmextra.dataFor<INpmciOptions>('npmci', defaultConfig)
};
export let configObject = npmciNpmextra.dataFor<INpmciOptions>('npmci', defaultConfig);
/**
* gets the npmci portion of the npmextra.json file
*/
export let getConfig = async (): Promise<INpmciOptions> => {
return configObject
}
return configObject;
};

View File

@ -1,13 +1,13 @@
import * as plugins from './npmci.plugins'
import * as paths from './npmci.paths'
import { GitRepo } from 'smartstring'
import { Dockerfile } from './mod_docker/index'
import * as plugins from './npmci.plugins';
import * as paths from './npmci.paths';
import { GitRepo } from 'smartstring';
import { Dockerfile } from './mod_docker/index';
/**
* a info instance about the git respoitory at cwd :)
*/
let repoString: string = process.env.CI_REPOSITORY_URL
let repoString: string = process.env.CI_REPOSITORY_URL;
if (!repoString) {
repoString = 'https://undefined:undefined@github.com/undefined/undefined.git'
repoString = 'https://undefined:undefined@github.com/undefined/undefined.git';
}
export let repo = new GitRepo(repoString)
export let repo = new GitRepo(repoString);

View File

@ -1,21 +1,24 @@
import * as _modClean from './mod_clean/index'
import * as _modCloudflare from './mod_cloudflare/index'
import * as _modCommand from './mod_command/index'
import * as _modDocker from './mod_docker/index'
import * as _modGit from './mod_git/index'
import * as _modNpm from './mod_npm/index'
import * as _modNode from './mod_node/index'
import * as _modSsh from './mod_ssh/index'
import * as _modTrigger from './mod_trigger/index'
import * as _modClean from './mod_clean/index';
import * as _modCloudflare from './mod_cloudflare/index';
import * as _modCommand from './mod_command/index';
import * as _modDocker from './mod_docker/index';
import * as _modGit from './mod_git/index';
import * as _modNpm from './mod_npm/index';
import * as _modNode from './mod_node/index';
import * as _modSsh from './mod_ssh/index';
import * as _modTrigger from './mod_trigger/index';
import { LazyModule } from 'smartsystem'
import { LazyModule } from 'smartsystem';
export let modClean = new LazyModule<typeof _modClean>('./mod_clean/index', __dirname)
export let modCloudflare = new LazyModule<typeof _modCloudflare>('./mod_cloudflare/index', __dirname)
export let modCommand = new LazyModule<typeof _modCommand>('./mod_command/index', __dirname)
export let modGit = new LazyModule<typeof _modGit>('./mod_git/index', __dirname)
export let modDocker = new LazyModule<typeof _modDocker>('./mod_docker/index', __dirname)
export let modNode = new LazyModule<typeof _modNode>('./mod_node/index', __dirname)
export let modNpm = new LazyModule<typeof _modNpm>('./mod_npm/index', __dirname)
export let modSsh = new LazyModule<typeof _modSsh>('./mod_ssh/index', __dirname)
export let modTrigger = new LazyModule<typeof _modTrigger>('./mod_trigger/index', __dirname)
export let modClean = new LazyModule<typeof _modClean>('./mod_clean/index', __dirname);
export let modCloudflare = new LazyModule<typeof _modCloudflare>(
'./mod_cloudflare/index',
__dirname
);
export let modCommand = new LazyModule<typeof _modCommand>('./mod_command/index', __dirname);
export let modGit = new LazyModule<typeof _modGit>('./mod_git/index', __dirname);
export let modDocker = new LazyModule<typeof _modDocker>('./mod_docker/index', __dirname);
export let modNode = new LazyModule<typeof _modNode>('./mod_node/index', __dirname);
export let modNpm = new LazyModule<typeof _modNpm>('./mod_npm/index', __dirname);
export let modSsh = new LazyModule<typeof _modSsh>('./mod_ssh/index', __dirname);
export let modTrigger = new LazyModule<typeof _modTrigger>('./mod_trigger/index', __dirname);

View File

@ -1,20 +1,22 @@
import * as plugins from './npmci.plugins'
import * as env from './npmci.env'
import * as plugins from './npmci.plugins';
import * as env from './npmci.env';
import { Analytics } from 'smartanalytics'
import { Analytics } from 'smartanalytics';
export let npmciAnalytics = new Analytics({
apiEndPoint: 'https://pubapi.lossless.one/analytics',
projectId: 'gitzone',
appName: 'npmci'
})
});
export let run = async () => {
npmciAnalytics.recordEvent('npmToolExecution', {
host: env.repo.host,
user: env.repo.user,
repo: env.repo.repo
}).catch(err => {
plugins.beautylog.warn('Lossless Analytics API not available...')
})
}
npmciAnalytics
.recordEvent('npmToolExecution', {
host: env.repo.host,
user: env.repo.user,
repo: env.repo.repo
})
.catch(err => {
plugins.beautylog.warn('Lossless Analytics API not available...');
});
};

View File

@ -1,8 +1,8 @@
import * as plugins from './npmci.plugins'
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');

View File

@ -1,22 +1,22 @@
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('smartq')
export let request = require('request')
export import smartcli = require('smartcli')
export import smartdelay = require('smartdelay')
export import smartfile = require('smartfile')
export import shelljs = require('shelljs')
export import smartparam = require('smartparam')
export import smartq = require('smartq')
export import smartshell = require('smartshell')
export import smartsocket = require('smartsocket')
export import smartsystem = require('smartsystem')
export import smartssh = require('smartssh')
export import smartstring = require('smartstring')
export import 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('smartq');
export let request = require('request');
export import smartcli = require('smartcli');
export import smartdelay = require('smartdelay');
export import smartfile = require('smartfile');
export import shelljs = require('shelljs');
export import smartparam = require('smartparam');
export import smartq = require('smartq');
export import smartshell = require('smartshell');
export import smartsocket = require('smartsocket');
export import smartsystem = require('smartsystem');
export import smartssh = require('smartssh');
export import smartstring = require('smartstring');
export import through2 = require('through2');