fix(package): include npmdocker with npm @gitzone scope
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import * as plugins from './npmdocker.plugins'
|
||||
import * as cli from './npmdocker.cli'
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as cli from './npmdocker.cli';
|
||||
|
||||
cli.run()
|
||||
cli.run();
|
||||
|
@ -1,10 +1,9 @@
|
||||
import * as plugins from './npmdocker.plugins'
|
||||
import * as paths from './npmdocker.paths'
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as paths from './npmdocker.paths';
|
||||
|
||||
// modules
|
||||
import * as ConfigModule from './npmdocker.config'
|
||||
import * as DockerModule from './npmdocker.docker'
|
||||
|
||||
import * as ConfigModule from './npmdocker.config';
|
||||
import * as DockerModule from './npmdocker.docker';
|
||||
|
||||
/**
|
||||
* smartanalytics
|
||||
@ -20,67 +19,68 @@ let npmdockerAnalytics = new plugins.smartanalytics.Analytics({
|
||||
apiEndPoint: 'https://pubapi.lossless.one',
|
||||
appName: 'npmdocker',
|
||||
projectId: 'gitzone'
|
||||
})
|
||||
});
|
||||
npmdockerAnalytics.recordEvent('npmtoolexecution', {
|
||||
somedata: 'somedata'
|
||||
})
|
||||
});
|
||||
|
||||
let npmdockerCli = new plugins.smartcli.Smartcli()
|
||||
let npmdockerCli = new plugins.smartcli.Smartcli();
|
||||
|
||||
export let run = () => {
|
||||
npmdockerCli.standardTask().then(async (argvArg) => {
|
||||
plugins.beautylog.figletSync('npmdocker')
|
||||
let configArg = await ConfigModule.run()
|
||||
.then(DockerModule.run)
|
||||
npmdockerCli.standardTask().then(async argvArg => {
|
||||
plugins.beautylog.figletSync('npmdocker');
|
||||
let configArg = await ConfigModule.run().then(DockerModule.run);
|
||||
if (configArg.exitCode === 0) {
|
||||
plugins.beautylog.success('container ended all right!')
|
||||
plugins.beautylog.success('container ended all right!');
|
||||
} else {
|
||||
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`)
|
||||
process.exit(1)
|
||||
plugins.beautylog.error(`container ended with error! Exit Code is ${configArg.exitCode}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
/**
|
||||
* this command is executed inside docker and meant for use from outside docker
|
||||
*/
|
||||
npmdockerCli.addCommand('runinside').then(async (argvArg) => {
|
||||
plugins.beautylog.ok('Allright. We are now in Docker!')
|
||||
plugins.beautylog.log('now trying to run your specified command')
|
||||
let configArg = await ConfigModule.run()
|
||||
npmdockerCli.addCommand('runinside').then(async argvArg => {
|
||||
plugins.beautylog.ok('Allright. We are now in Docker!');
|
||||
plugins.beautylog.log('now trying to run your specified command');
|
||||
let configArg = await ConfigModule.run();
|
||||
await plugins.smartshell.exec(configArg.command).then(response => {
|
||||
if (response.exitCode !== 0) {
|
||||
process.exit(1)
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
npmdockerCli.addCommand('clean').then(async (argvArg) => {
|
||||
plugins.beautylog.ora.start()
|
||||
plugins.beautylog.ora.text('cleaning up docker env...')
|
||||
npmdockerCli.addCommand('clean').then(async argvArg => {
|
||||
plugins.beautylog.ora.start();
|
||||
plugins.beautylog.ora.text('cleaning up docker env...');
|
||||
if (argvArg.all) {
|
||||
plugins.beautylog.ora.text('killing any running docker containers...')
|
||||
await plugins.smartshell.exec(`docker kill $(docker ps -q)`)
|
||||
plugins.beautylog.ora.text('killing any running docker containers...');
|
||||
await plugins.smartshell.exec(`docker kill $(docker ps -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing stopped containers...')
|
||||
await plugins.smartshell.exec(`docker rm $(docker ps -a -q)`)
|
||||
plugins.beautylog.ora.text('removing stopped containers...');
|
||||
await plugins.smartshell.exec(`docker rm $(docker ps -a -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing images...')
|
||||
await plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`)
|
||||
plugins.beautylog.ora.text('removing images...');
|
||||
await plugins.smartshell.exec(`docker rmi $(docker images -q -f dangling=true)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing all other images...')
|
||||
await plugins.smartshell.exec(`docker rmi $(docker images -a -q)`)
|
||||
plugins.beautylog.ora.text('removing all other images...');
|
||||
await plugins.smartshell.exec(`docker rmi $(docker images -a -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing all volumes...')
|
||||
await plugins.smartshell.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`)
|
||||
plugins.beautylog.ora.text('removing all volumes...');
|
||||
await plugins.smartshell.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
|
||||
}
|
||||
plugins.beautylog.ora.endOk('docker environment now is clean!')
|
||||
})
|
||||
plugins.beautylog.ora.endOk('docker environment now is clean!');
|
||||
});
|
||||
|
||||
npmdockerCli.addCommand('speedtest').then(async (argvArg) => {
|
||||
plugins.beautylog.figletSync('npmdocker')
|
||||
plugins.beautylog.ok('Starting speedtest')
|
||||
await plugins.smartshell.exec(`docker pull tianon/speedtest && docker run --rm tianon/speedtest`)
|
||||
})
|
||||
npmdockerCli.addCommand('speedtest').then(async argvArg => {
|
||||
plugins.beautylog.figletSync('npmdocker');
|
||||
plugins.beautylog.ok('Starting speedtest');
|
||||
await plugins.smartshell.exec(
|
||||
`docker pull tianon/speedtest && docker run --rm tianon/speedtest`
|
||||
);
|
||||
});
|
||||
|
||||
npmdockerCli.startParse()
|
||||
}
|
||||
npmdockerCli.startParse();
|
||||
};
|
||||
|
@ -1,43 +1,40 @@
|
||||
import * as plugins from './npmdocker.plugins'
|
||||
import * as paths from "./npmdocker.paths"
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as paths from './npmdocker.paths';
|
||||
|
||||
// interfaces
|
||||
import { IKeyValueObject } from 'qenv'
|
||||
import { IKeyValueObject } from 'qenv';
|
||||
|
||||
export interface IConfig {
|
||||
baseImage: string
|
||||
command: string
|
||||
dockerSock: boolean
|
||||
exitCode?: number
|
||||
keyValueObjectArray: IKeyValueObject[]
|
||||
};
|
||||
baseImage: string;
|
||||
command: string;
|
||||
dockerSock: boolean;
|
||||
exitCode?: number;
|
||||
keyValueObjectArray: IKeyValueObject[];
|
||||
}
|
||||
|
||||
let getQenvKeyValueObject = async () => {
|
||||
let qenvKeyValueObjectArray: IKeyValueObject[]
|
||||
let qenvKeyValueObjectArray: IKeyValueObject[];
|
||||
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
|
||||
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray
|
||||
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray;
|
||||
} else {
|
||||
qenvKeyValueObjectArray = []
|
||||
qenvKeyValueObjectArray = [];
|
||||
}
|
||||
return qenvKeyValueObjectArray
|
||||
}
|
||||
return qenvKeyValueObjectArray;
|
||||
};
|
||||
|
||||
let buildConfig = async (qenvKeyValueObjectArrayArg: IKeyValueObject[]) => {
|
||||
let npmextra = new plugins.npmextra.Npmextra(paths.cwd)
|
||||
let config = npmextra.dataFor<IConfig>(
|
||||
'npmdocker',
|
||||
{
|
||||
baseImage: 'hosttoday/ht-docker-node:npmdocker',
|
||||
init: 'rm -rf node_nodules/ && yarn install',
|
||||
command: 'npmci npm test',
|
||||
dockerSock: false,
|
||||
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||
}
|
||||
)
|
||||
return config
|
||||
}
|
||||
let npmextra = new plugins.npmextra.Npmextra(paths.cwd);
|
||||
let config = npmextra.dataFor<IConfig>('npmdocker', {
|
||||
baseImage: 'hosttoday/ht-docker-node:npmdocker',
|
||||
init: 'rm -rf node_nodules/ && yarn install',
|
||||
command: 'npmci npm test',
|
||||
dockerSock: false,
|
||||
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||
});
|
||||
return config;
|
||||
};
|
||||
|
||||
export let run = async (): Promise<IConfig> => {
|
||||
let config = await getQenvKeyValueObject().then(buildConfig)
|
||||
return config
|
||||
}
|
||||
let config = await getQenvKeyValueObject().then(buildConfig);
|
||||
return config;
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import * as plugins from './npmdocker.plugins'
|
||||
import * as paths from './npmdocker.paths'
|
||||
import * as snippets from './npmdocker.snippets'
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as paths from './npmdocker.paths';
|
||||
import * as snippets from './npmdocker.snippets';
|
||||
|
||||
// interfaces
|
||||
import { IConfig } from './npmdocker.config'
|
||||
import { IConfig } from './npmdocker.config';
|
||||
|
||||
let config: IConfig
|
||||
let config: IConfig;
|
||||
|
||||
/**
|
||||
* the docker data used to build the internal testing container
|
||||
@ -16,134 +16,137 @@ let dockerData = {
|
||||
dockerProjectMountString: '',
|
||||
dockerSockString: '',
|
||||
dockerEnvString: ''
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* check if docker is available
|
||||
*/
|
||||
let checkDocker = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('checking docker...')
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.ora.text('checking docker...');
|
||||
if (plugins.smartshell.which('docker')) {
|
||||
plugins.beautylog.ok('Docker found!')
|
||||
done.resolve()
|
||||
plugins.beautylog.ok('Docker found!');
|
||||
done.resolve();
|
||||
} else {
|
||||
done.reject(new Error('docker not found on this machine'))
|
||||
done.reject(new Error('docker not found on this machine'));
|
||||
}
|
||||
return done.promise
|
||||
}
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* builds the Dockerfile according to the config in the project
|
||||
*/
|
||||
let buildDockerFile = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('building Dockerfile...')
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.ora.text('building Dockerfile...');
|
||||
let dockerfile: string = snippets.dockerfileSnippet({
|
||||
baseImage: config.baseImage,
|
||||
command: config.command
|
||||
})
|
||||
plugins.beautylog.info(`Base image is: ${config.baseImage}`)
|
||||
plugins.beautylog.info(`Command is: ${config.command}`)
|
||||
plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker'))
|
||||
plugins.beautylog.ok('Dockerfile created!')
|
||||
plugins.beautylog.ora.stop()
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
});
|
||||
plugins.beautylog.info(`Base image is: ${config.baseImage}`);
|
||||
plugins.beautylog.info(`Command is: ${config.command}`);
|
||||
plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker'));
|
||||
plugins.beautylog.ok('Dockerfile created!');
|
||||
plugins.beautylog.ora.stop();
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* builds the Dockerimage from the built Dockerfile
|
||||
*/
|
||||
let buildDockerImage = async () => {
|
||||
plugins.beautylog.info('pulling latest base image from registry...')
|
||||
await plugins.smartshell.exec(
|
||||
`docker pull ${config.baseImage}`
|
||||
)
|
||||
plugins.beautylog.ora.text('building Dockerimage...')
|
||||
plugins.beautylog.info('pulling latest base image from registry...');
|
||||
await plugins.smartshell.exec(`docker pull ${config.baseImage}`);
|
||||
plugins.beautylog.ora.text('building Dockerimage...');
|
||||
let execResult = await plugins.smartshell.execSilent(
|
||||
`docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}`
|
||||
)
|
||||
);
|
||||
if (execResult.exitCode !== 0) {
|
||||
console.log(execResult.stdout)
|
||||
process.exit(1)
|
||||
console.log(execResult.stdout);
|
||||
process.exit(1);
|
||||
}
|
||||
plugins.beautylog.ok('Dockerimage built!')
|
||||
}
|
||||
plugins.beautylog.ok('Dockerimage built!');
|
||||
};
|
||||
|
||||
let buildDockerProjectMountString = async () => {
|
||||
if (process.env.CI !== 'true') {
|
||||
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`
|
||||
};
|
||||
}
|
||||
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* builds an environment string that docker cli understands
|
||||
*/
|
||||
let buildDockerEnvString = async () => {
|
||||
for (let keyValueObjectArg of config.keyValueObjectArray) {
|
||||
let envString = dockerData.dockerEnvString = dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `
|
||||
let envString = (dockerData.dockerEnvString =
|
||||
dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* creates string to mount the docker.sock inside the testcontainer
|
||||
*/
|
||||
let buildDockerSockString = async () => {
|
||||
if (config.dockerSock) {
|
||||
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
|
||||
};
|
||||
}
|
||||
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a container by running the built Dockerimage
|
||||
*/
|
||||
let runDockerImage = async () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('starting Container...')
|
||||
plugins.beautylog.ora.end()
|
||||
plugins.beautylog.log('now running Dockerimage')
|
||||
config.exitCode = (await plugins.smartshell.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --name ${dockerData.containerName} ${dockerData.imageTag}`)).exitCode
|
||||
}
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.ora.text('starting Container...');
|
||||
plugins.beautylog.ora.end();
|
||||
plugins.beautylog.log('now running Dockerimage');
|
||||
config.exitCode = (await plugins.smartshell.exec(
|
||||
`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${
|
||||
dockerData.dockerEnvString
|
||||
} --name ${dockerData.containerName} ${dockerData.imageTag}`
|
||||
)).exitCode;
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans up: deletes the test container
|
||||
*/
|
||||
let deleteDockerContainer = async () => {
|
||||
await plugins.smartshell.execSilent(`docker rm -f ${dockerData.containerName}`)
|
||||
}
|
||||
await plugins.smartshell.execSilent(`docker rm -f ${dockerData.containerName}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans up deletes the test image
|
||||
*/
|
||||
let deleteDockerImage = async () => {
|
||||
await plugins.smartshell.execSilent(`docker rmi ${dockerData.imageTag}`).then(async (response) => {
|
||||
await plugins.smartshell.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => {
|
||||
if (response.exitCode !== 0) {
|
||||
console.log(response.stdout)
|
||||
console.log(response.stdout);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let preClean = async () => {
|
||||
await deleteDockerImage()
|
||||
.then(deleteDockerContainer)
|
||||
.then(async () => {
|
||||
plugins.beautylog.ok('ensured clean Docker environment!')
|
||||
})
|
||||
}
|
||||
plugins.beautylog.ok('ensured clean Docker environment!');
|
||||
});
|
||||
};
|
||||
|
||||
let postClean = async () => {
|
||||
await deleteDockerContainer()
|
||||
.then(deleteDockerImage)
|
||||
.then(async () => {
|
||||
plugins.beautylog.ok('cleaned up!')
|
||||
})
|
||||
plugins.smartfile.fs.removeSync(paths.npmdockerFile)
|
||||
}
|
||||
plugins.beautylog.ok('cleaned up!');
|
||||
});
|
||||
plugins.smartfile.fs.removeSync(paths.npmdockerFile);
|
||||
};
|
||||
|
||||
export let run = async (configArg: IConfig): Promise<IConfig> => {
|
||||
plugins.beautylog.ora.start()
|
||||
config = configArg
|
||||
plugins.beautylog.ora.start();
|
||||
config = configArg;
|
||||
let resultConfig = await checkDocker()
|
||||
.then(preClean)
|
||||
.then(buildDockerFile)
|
||||
@ -153,6 +156,8 @@ export let run = async (configArg: IConfig): Promise<IConfig> => {
|
||||
.then(buildDockerSockString)
|
||||
.then(runDockerImage)
|
||||
.then(postClean)
|
||||
.catch(err => { console.log(err) })
|
||||
return config
|
||||
}
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
return config;
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
import * as plugins from "./npmdocker.plugins"
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
|
||||
// directories
|
||||
export let cwd = process.cwd()
|
||||
export let packageBase = plugins.path.join(__dirname, '../')
|
||||
export let assets = plugins.path.join(packageBase, 'assets/')
|
||||
plugins.smartfile.fs.ensureDirSync(assets)
|
||||
export let npmdockerFile = plugins.path.join(cwd, 'npmdocker')
|
||||
export let cwd = process.cwd();
|
||||
export let packageBase = plugins.path.join(__dirname, '../');
|
||||
export let assets = plugins.path.join(packageBase, 'assets/');
|
||||
plugins.smartfile.fs.ensureDirSync(assets);
|
||||
export let npmdockerFile = plugins.path.join(cwd, 'npmdocker');
|
||||
|
@ -1,15 +1,14 @@
|
||||
import 'typings-global'
|
||||
import * as beautylog from 'beautylog'
|
||||
import * as npmextra from 'npmextra'
|
||||
import * as path from 'path'
|
||||
import * as projectinfo from 'projectinfo'
|
||||
import * as q from 'smartq'
|
||||
import * as qenv from 'qenv'
|
||||
import * as smartanalytics from 'smartanalytics'
|
||||
import * as smartcli from 'smartcli'
|
||||
import * as smartfile from 'smartfile'
|
||||
import * as smartshell from 'smartshell'
|
||||
import * as smartstring from 'smartstring'
|
||||
import * as beautylog from 'beautylog';
|
||||
import * as npmextra from 'npmextra';
|
||||
import * as path from 'path';
|
||||
import * as projectinfo from 'projectinfo';
|
||||
import * as q from 'smartq';
|
||||
import * as qenv from 'qenv';
|
||||
import * as smartanalytics from 'smartanalytics';
|
||||
import * as smartcli from 'smartcli';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartshell from 'smartshell';
|
||||
import * as smartstring from 'smartstring';
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
@ -23,4 +22,4 @@ export {
|
||||
smartfile,
|
||||
smartshell,
|
||||
smartstring
|
||||
}
|
||||
};
|
||||
|
@ -1,25 +1,25 @@
|
||||
import * as plugins from "./npmdocker.plugins";
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
|
||||
export interface IDockerfileSnippet {
|
||||
baseImage: string
|
||||
command: string
|
||||
baseImage: string;
|
||||
command: string;
|
||||
}
|
||||
|
||||
let getMountSolutionString = (optionsArg: IDockerfileSnippet) => {
|
||||
if (process.env.CI) {
|
||||
return 'COPY ./ /workspace'
|
||||
return 'COPY ./ /workspace';
|
||||
} else {
|
||||
return '# not copying workspcae since not in CI'
|
||||
return '# not copying workspcae since not in CI';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let getGlobalPreparationString = (optionsArg: IDockerfileSnippet) => {
|
||||
if (optionsArg.baseImage !== 'hosttoday/ht-docker-node:npmdocker') {
|
||||
return 'RUN yarn global add npmdocker'
|
||||
return 'RUN yarn global add npmdocker';
|
||||
} else {
|
||||
return '# not installing npmdocker since it is included in the base image'
|
||||
return '# not installing npmdocker since it is included in the base image';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export let dockerfileSnippet = (optionsArg: IDockerfileSnippet): string => {
|
||||
return plugins.smartstring.indent.normalize(
|
||||
@ -33,5 +33,5 @@ ENV CI=true
|
||||
ENTRYPOINT ["npmdocker"]
|
||||
CMD ["runinside"]
|
||||
`
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user