Compare commits

..

No commits in common. "master" and "v1.0.1" have entirely different histories.

22 changed files with 43 additions and 28623 deletions

25
.gitignore vendored
View File

@ -1,23 +1,4 @@
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/ node_modules/
coverage/
# caches docs/
.yarn/ .nogit/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom
test

View File

@ -1,69 +1,35 @@
image: hosttoday/ht-docker-dbase:npmci image: hosttoday/ht-docker-node:npmts
services:
- docker:dind
stages: stages:
- mirror
- test - test
- release - release
- trigger
- pages
mirror: testLEGACY:
image: hosttoday/ht-docker-node:npmci
stage: mirror
script:
- npmci git mirror
tags:
- docker
test:
stage: test stage: test
script: script:
- npmci node install stable - npmci test legacy
- npmci npm install tags:
- npmci npm test - docker
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags: tags:
- docker - docker
- lossless
- priv
release: release:
stage: release stage: release
environment: npmjs-com_registry
script: script:
- npmci npm prepare - npmci publish
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- lossless
- priv
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
- lossless
- priv
pages:
image: hosttoday/ht-docker-node:npmci
stage: pages
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci command tsdoc
only:
- tags
tags:
- docker
artifacts:
expire_in: 1 week
paths:
- public

View File

@ -1,3 +0,0 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}

View File

@ -1,4 +0,0 @@
FROM hosttoday/ht-docker-node:stable
LABEL author="Lossless GmbH <office@lossless.com>"
RUN yarn global add npmci npmdocker npmts ts-node

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# npmdocker
develop npm modules cross platform with docker
## Usage
npmdocker looks for a npmextra.json at the root of your directory and looks at the npmdocker portion of it.

View File

@ -1,6 +0,0 @@
FROM hosttoday/ht-docker-node:npmci
RUN yarn global add @gitzone/tsdocker
COPY ./ /workspace
WORKDIR /workspace
ENV CI=true
CMD ["tsdocker","runinside"];

3
cli.js
View File

@ -1,3 +0,0 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
require('./dist/index');

View File

@ -1,4 +0,0 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
require('@gitzone/tsrun');
require('./ts/index');

0
dist/index.d.ts vendored Normal file
View File

1
dist/index.js vendored Normal file
View File

@ -0,0 +1 @@
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=

View File

@ -1,20 +0,0 @@
{
"npmts": {
"mode": "default",
"cli": true
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "gitzone",
"gitrepo": "npmdocker",
"shortDescription": "develop npm modules cross platform with docker",
"npmPackagename": "@gitzone/npmdocker",
"license": "MIT"
}
}
}

28061
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,17 @@
{ {
"name": "@gitzone/tsdocker", "name": "npmdocker",
"version": "1.2.40", "version": "1.0.1",
"private": false,
"description": "develop npm modules cross platform with docker", "description": "develop npm modules cross platform with docker",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "directories": {
"bin": { "test": "test"
"tsdocker": "cli.js"
}, },
"scripts": { "scripts": {
"test": "(npm run clean && npm run setupCheck && npm run testStandard && npm run testSpeed)", "test": "(npmts)"
"build": "(tsbuild)",
"testStandard": "(cd test/ && node ../cli.ts.js)",
"testSpeed": "(cd test/ && node ../cli.ts.js speedtest)",
"testClean": "(cd test/ && node ../cli.ts.js clean --all)",
"testVscode": "(cd test/ && node ../cli.ts.js vscode)",
"clean": "(rm -rf test/)",
"compile": "(npmts --notest)",
"setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/gitzone/npmdocker.git" "url": "git+ssh://git@gitlab.com/pushrocks/npmdocker.git"
}, },
"keywords": [ "keywords": [
"docker" "docker"
@ -29,32 +19,19 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://gitlab.com/gitzone/npmdocker/issues" "url": "https://gitlab.com/pushrocks/npmdocker/issues"
}, },
"homepage": "https://gitlab.com/gitzone/npmdocker#README", "homepage": "https://gitlab.com/pushrocks/npmdocker#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.27", "npmts-g": "^5.2.6",
"@gitzone/tsrun": "^1.2.17", "should": "^9.0.2",
"@gitzone/tstest": "^1.0.57", "typings-test": "^1.0.1"
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^16.10.1",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/npmextra": "^3.0.9", "beautylog": "^5.0.13",
"@pushrocks/projectinfo": "^4.0.5", "q": "^1.4.1",
"@pushrocks/qenv": "^4.0.10", "rxjs": "^5.0.0-beta.10",
"@pushrocks/smartanalytics": "^2.0.15", "smartfile": "^4.0.10",
"@pushrocks/smartcli": "^3.0.14", "typings-global": "^1.0.6"
"@pushrocks/smartfile": "^8.0.10",
"@pushrocks/smartlog": "^2.0.44",
"@pushrocks/smartlog-destination-local": "^8.0.8",
"@pushrocks/smartlog-source-ora": "^1.0.9",
"@pushrocks/smartopen": "^1.0.22",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartshell": "^2.0.28",
"@pushrocks/smartstring": "^3.0.24",
"@types/shelljs": "^0.8.9"
} }
} }

View File

@ -1,4 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as cli from './tsdocker.cli';
cli.run();

View File

@ -1,90 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as paths from './tsdocker.paths';
// modules
import * as ConfigModule from './tsdocker.config';
import * as DockerModule from './tsdocker.docker';
import { logger, ora } from './tsdocker.logging';
const tsdockerCli = new plugins.smartcli.Smartcli();
export let run = () => {
tsdockerCli.standardTask().subscribe(async argvArg => {
const configArg = await ConfigModule.run().then(DockerModule.run);
if (configArg.exitCode === 0) {
logger.log('success', 'container ended all right!');
} else {
logger.log('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
*/
tsdockerCli.addCommand('runinside').subscribe(async argvArg => {
logger.log('ok', 'Allright. We are now in Docker!');
ora.text('now trying to run your specified command');
const configArg = await ConfigModule.run();
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
ora.stop();
await smartshellInstance.exec(configArg.command).then(response => {
if (response.exitCode !== 0) {
process.exit(1);
}
});
});
tsdockerCli.addCommand('clean').subscribe(async argvArg => {
ora.text('cleaning up docker env...');
if (argvArg.all) {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
ora.text('killing any running docker containers...');
await smartshellInstance.exec(`docker kill $(docker ps -q)`);
ora.text('removing stopped containers...');
await smartshellInstance.exec(`docker rm $(docker ps -a -q)`);
ora.text('removing images...');
await smartshellInstance.exec(`docker rmi -f $(docker images -q -f dangling=true)`);
ora.text('removing all other images...');
await smartshellInstance.exec(`docker rmi $(docker images -a -q)`);
ora.text('removing all volumes...');
await smartshellInstance.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
}
ora.finishSuccess('docker environment now is clean!');
});
tsdockerCli.addCommand('speedtest').subscribe(async argvArg => {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
logger.log('ok', 'Starting speedtest');
await smartshellInstance.exec(
`docker pull tianon/speedtest && docker run --rm tianon/speedtest --accept-license --accept-gdpr`
);
});
tsdockerCli.addCommand('vscode').subscribe(async argvArg => {
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
logger.log('ok', `Starting vscode in cwd ${paths.cwd}`);
await smartshellInstance.execAndWaitForLine(
`docker run -p 127.0.0.1:8443:8443 -v "${
paths.cwd
}:/home/coder/project" registry.gitlab.com/hosttoday/ht-docker-vscode --allow-http --no-auth`,
/Connected to shared process/
);
await plugins.smartopen.openUrl('testing-vscode.git.zone:8443');
});
tsdockerCli.startParse();
};

View File

@ -1,37 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as paths from './tsdocker.paths';
export interface IConfig {
baseImage: string;
command: string;
dockerSock: boolean;
exitCode?: number;
keyValueObject: {[key: string]: any};
}
const getQenvKeyValueObject = async () => {
let qenvKeyValueObjectArray: { [key: string]: string | number };
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObject;
} else {
qenvKeyValueObjectArray = {};
}
return qenvKeyValueObjectArray;
};
const buildConfig = async (qenvKeyValueObjectArg: { [key: string]: string | number }) => {
const npmextra = new plugins.npmextra.Npmextra(paths.cwd);
const config = npmextra.dataFor<IConfig>('npmdocker', {
baseImage: 'hosttoday/ht-docker-node:npmdocker',
init: 'rm -rf node_nodules/ && yarn install',
command: 'npmci npm test',
dockerSock: false,
keyValueObject: qenvKeyValueObjectArg
});
return config;
};
export let run = async (): Promise<IConfig> => {
const config = await getQenvKeyValueObject().then(buildConfig);
return config;
};

View File

@ -1,169 +0,0 @@
import * as plugins from './tsdocker.plugins';
import * as paths from './tsdocker.paths';
import * as snippets from './tsdocker.snippets';
import { logger, ora } from './tsdocker.logging';
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
// interfaces
import { IConfig } from './tsdocker.config';
let config: IConfig;
/**
* the docker data used to build the internal testing container
*/
const dockerData = {
imageTag: 'npmdocker-temp-image:latest',
containerName: 'npmdocker-temp-container',
dockerProjectMountString: '',
dockerSockString: '',
dockerEnvString: ''
};
/**
* check if docker is available
*/
const checkDocker = () => {
const done = plugins.smartpromise.defer();
ora.text('checking docker...');
if (smartshellInstance.exec('which docker')) {
logger.log('ok', 'Docker found!');
done.resolve();
} else {
done.reject(new Error('docker not found on this machine'));
}
return done.promise;
};
/**
* builds the Dockerfile according to the config in the project
*/
const buildDockerFile = () => {
const done = plugins.smartpromise.defer();
ora.text('building Dockerfile...');
const dockerfile: string = snippets.dockerfileSnippet({
baseImage: config.baseImage,
command: config.command
});
logger.log('info', `Base image is: ${config.baseImage}`);
logger.log('info', `Command is: ${config.command}`);
plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker'));
logger.log('ok', 'Dockerfile created!');
ora.stop();
done.resolve();
return done.promise;
};
/**
* builds the Dockerimage from the built Dockerfile
*/
const buildDockerImage = async () => {
logger.log('info', 'pulling latest base image from registry...');
await smartshellInstance.exec(`docker pull ${config.baseImage}`);
ora.text('building Dockerimage...');
const execResult = await smartshellInstance.execSilent(
`docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}`
);
if (execResult.exitCode !== 0) {
console.log(execResult.stdout);
process.exit(1);
}
logger.log('ok', 'Dockerimage built!');
};
const buildDockerProjectMountString = async () => {
if (process.env.CI !== 'true') {
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`;
}
};
/**
* builds an environment string that docker cli understands
*/
const buildDockerEnvString = async () => {
for (const key of Object.keys(config.keyValueObject)) {
const envString = (dockerData.dockerEnvString =
dockerData.dockerEnvString + `-e ${key}=${config.keyValueObject[key]} `);
}
};
/**
* creates string to mount the docker.sock inside the testcontainer
*/
const buildDockerSockString = async () => {
if (config.dockerSock) {
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`;
}
};
/**
* creates a container by running the built Dockerimage
*/
const runDockerImage = async () => {
const done = plugins.smartpromise.defer();
ora.text('starting Container...');
ora.stop();
logger.log('info', 'now running Dockerimage');
config.exitCode = (await smartshellInstance.exec(
`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${
dockerData.dockerEnvString
} --name ${dockerData.containerName} ${dockerData.imageTag}`
)).exitCode;
};
/**
* cleans up: deletes the test container
*/
const deleteDockerContainer = async () => {
await smartshellInstance.execSilent(`docker rm -f ${dockerData.containerName}`);
};
/**
* cleans up deletes the test image
*/
const deleteDockerImage = async () => {
await smartshellInstance.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => {
if (response.exitCode !== 0) {
console.log(response.stdout);
}
});
};
const preClean = async () => {
await deleteDockerImage()
.then(deleteDockerContainer)
.then(async () => {
logger.log('ok', 'ensured clean Docker environment!');
});
};
const postClean = async () => {
await deleteDockerContainer()
.then(deleteDockerImage)
.then(async () => {
logger.log('ok', 'cleaned up!');
});
plugins.smartfile.fs.removeSync(paths.npmdockerFile);
};
export let run = async (configArg: IConfig): Promise<IConfig> => {
config = configArg;
const resultConfig = await checkDocker()
.then(preClean)
.then(buildDockerFile)
.then(buildDockerImage)
.then(buildDockerProjectMountString)
.then(buildDockerEnvString)
.then(buildDockerSockString)
.then(runDockerImage)
.then(postClean)
.catch(err => {
console.log(err);
});
return config;
};

View File

@ -1,17 +0,0 @@
import * as plugins from './tsdocker.plugins';
export const logger = new plugins.smartlog.Smartlog({
logContext: {
company: 'Some Company',
companyunit: 'Some CompanyUnit',
containerName: 'Some Containername',
environment: 'local',
runtime: 'node',
zone: 'gitzone'
},
minimumLogLevel: 'silly'
});
logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());
export const ora = new plugins.smartlogSouceOra.SmartlogSourceOra();

View File

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

View File

@ -1,30 +0,0 @@
// pushrocks scope
import * as npmextra from '@pushrocks/npmextra';
import * as path from 'path';
import * as projectinfo from '@pushrocks/projectinfo';
import * as smartpromise from '@pushrocks/smartpromise';
import * as qenv from '@pushrocks/qenv';
import * as smartcli from '@pushrocks/smartcli';
import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
import * as smartlogSouceOra from '@pushrocks/smartlog-source-ora';
import * as smartopen from '@pushrocks/smartopen';
import * as smartshell from '@pushrocks/smartshell';
import * as smartstring from '@pushrocks/smartstring';
export {
npmextra,
path,
projectinfo,
smartpromise,
qenv,
smartcli,
smartfile,
smartlog,
smartlogDestinationLocal,
smartlogSouceOra,
smartopen,
smartshell,
smartstring
};

View File

@ -1,37 +0,0 @@
import * as plugins from './tsdocker.plugins';
export interface IDockerfileSnippet {
baseImage: string;
command: string;
}
let getMountSolutionString = (optionsArg: IDockerfileSnippet) => {
if (process.env.CI) {
return 'COPY ./ /workspace';
} else {
return '# not copying workspcae since not in CI';
}
};
let getGlobalPreparationString = (optionsArg: IDockerfileSnippet) => {
if (optionsArg.baseImage !== 'hosttoday/ht-docker-node:npmdocker') {
return 'RUN npm install -g npmdocker';
} else {
return '# not installing npmdocker since it is included in the base image';
}
};
export let dockerfileSnippet = (optionsArg: IDockerfileSnippet): string => {
return plugins.smartstring.indent.normalize(
`
FROM ${optionsArg.baseImage}
# For info about what npmdocker does read the docs at https://gitzone.github.io/npmdocker
${getGlobalPreparationString(optionsArg)}
${getMountSolutionString(optionsArg)}
WORKDIR /workspace
ENV CI=true
ENTRYPOINT ["npmdocker"]
CMD ["runinside"]
`
);
};

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}