Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
d1fd76e8d0 | |||
b71fa1bc36 | |||
068d28b95d | |||
ecb458f5cd | |||
9f6fb8aedd | |||
f21df13b7c | |||
9c56942739 | |||
5f4ab33069 | |||
14761a442e | |||
c4ee967ca9 | |||
551b8d0cde | |||
4f23b61e14 | |||
799320492a | |||
d2cd294b36 | |||
d3d3363e1b | |||
ccd2cb6cbd | |||
0b0642f9e3 | |||
34753a4ae0 | |||
977ecabb41 | |||
6d9d040a8d | |||
b2c08b7221 | |||
73b1a73719 | |||
449512e156 | |||
758e677bab | |||
42ffb4a8dd | |||
9176b56035 | |||
b3d78f8ce5 | |||
b6a6aac8e5 | |||
32f5ead4f4 | |||
c29a261cb6 | |||
de57d45947 | |||
00bf1532ca | |||
38fc672bf6 | |||
83771df11d | |||
822e480bdf | |||
77c6ef99c1 | |||
8e3991c121 | |||
77477587b8 | |||
c7e32d6990 | |||
da1c2167d3 | |||
d55f7ef7f2 | |||
82f4fcceac | |||
aa3b85314d | |||
b5145294bd | |||
d25decd15d | |||
abf5cd1e24 |
@ -1,28 +1,40 @@
|
||||
image: hosttoday/ht-docker-dbase:npmts
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:dind
|
||||
|
||||
stages:
|
||||
- mirror
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
|
||||
mirror:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: mirror
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script:
|
||||
- npm install
|
||||
- npm test
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
tags:
|
||||
- docker
|
||||
- lossless
|
||||
- priv
|
||||
|
||||
release:
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
stage: release
|
||||
environment: npmjs-com_registry
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci npm prepare
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
@ -31,7 +43,6 @@ release:
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
stage: trigger
|
||||
script:
|
||||
- npmci trigger
|
||||
@ -41,3 +52,18 @@ trigger:
|
||||
- docker
|
||||
- lossless
|
||||
- priv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: pages
|
||||
script:
|
||||
- npmci command yarn global add npmpage
|
||||
- npmci command npmpage
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
|
4
Dockerfile
Normal file
4
Dockerfile
Normal file
@ -0,0 +1,4 @@
|
||||
FROM hosttoday/ht-docker-node:stable
|
||||
LABEL author="Lossless GmbH <office@lossless.com>"
|
||||
|
||||
RUN yarn global add npmci npmdocker npmts ts-node
|
28
README.md
28
README.md
@ -1,13 +1,16 @@
|
||||
# npmdocker
|
||||
|
||||
develop npm modules cross platform with docker
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/npmdocker)
|
||||
[](https://GitLab.com/gitzone/npmdocker)
|
||||
[](https://github.com/gitzone/npmdocker)
|
||||
[](https://gitzone.gitlab.io/npmdocker/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/gitzone/npmdocker/commits/master)
|
||||
[](https://GitLab.com/gitzone/npmdocker/commits/master)
|
||||
[](https://www.npmjs.com/package/npmdocker)
|
||||
@ -19,21 +22,25 @@ develop npm modules cross platform with docker
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Why does this package exist?
|
||||
|
||||
Sometimes you want a clean and fresh linux environment everytime you test your package.
|
||||
Usually this is the default i CI, but locally behaviour tends to defer.
|
||||
|
||||
### Where does it work
|
||||
|
||||
The npmdocker package works in everywhere where the docker cli is available. e.g.:
|
||||
|
||||
* docker toolbox
|
||||
* native docker application
|
||||
* docker in docker
|
||||
* mounted docker.sock
|
||||
* docker toolbox
|
||||
* native docker application
|
||||
* docker in docker
|
||||
* mounted docker.sock
|
||||
|
||||
### How do I use it?
|
||||
|
||||
create a npmextra.json in the project's root directory
|
||||
|
||||
```json
|
||||
@ -46,14 +53,15 @@ create a npmextra.json in the project's root directory
|
||||
}
|
||||
```
|
||||
|
||||
option | description
|
||||
--- | ---
|
||||
baseImage | the base image that is the context for your project
|
||||
command | the cli command to run within the the project's directory inside the docker container
|
||||
dockersSock | wether or not the testcontainer will have access to the docker.sock of the host
|
||||
| option | description |
|
||||
| ----------- | ------------------------------------------------------------------------------------- |
|
||||
| baseImage | the base image that is the context for your project |
|
||||
| command | the cli command to run within the the project's directory inside the docker container |
|
||||
| dockersSock | wether or not the testcontainer will have access to the docker.sock of the host |
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://git.zone)
|
||||
[](https://git.zone)
|
||||
|
@ -1,5 +1,6 @@
|
||||
FROM hosttoday/ht-docker-node:npmts
|
||||
COPY ./buildContextDir /workspace
|
||||
FROM hosttoday/ht-docker-node:npmci
|
||||
RUN yarn global add npmdocker
|
||||
COPY ./ /workspace
|
||||
WORKDIR /workspace
|
||||
ENV CI=true
|
||||
CMD ["npmci","test","stable"];
|
||||
CMD ["npmdocker","runinside"];
|
||||
|
3
cli.js
Normal file
3
cli.js
Normal file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
process.env.CLI_CALL = 'true';
|
||||
require('./dist/index');
|
4
cli.ts.js
Normal file
4
cli.ts.js
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
process.env.CLI_CALL = 'true';
|
||||
require('@gitzone/tsrun');
|
||||
require('./ts/index');
|
2
dist/cli.js
vendored
2
dist/cli.js
vendored
@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
var index = require("../dist/index.js");
|
0
dist/index.d.ts
vendored
0
dist/index.d.ts
vendored
14
dist/index.js
vendored
14
dist/index.js
vendored
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./npmdocker.plugins");
|
||||
const promisechain = require("./npmdocker.promisechain");
|
||||
promisechain.run()
|
||||
.then((configArg) => {
|
||||
if (configArg.exitCode == 0) {
|
||||
plugins.beautylog.success("container ended all right!");
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.error("container ended with error!");
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsK0NBQStDO0FBQy9DLHlEQUF5RDtBQUl6RCxZQUFZLENBQUMsR0FBRyxFQUFFO0tBQ2IsSUFBSSxDQUFDLENBQUMsU0FBOEI7SUFDakMsRUFBRSxDQUFBLENBQUMsU0FBUyxDQUFDLFFBQVEsSUFBSSxDQUFDLENBQUMsQ0FBQSxDQUFDO1FBQ3hCLE9BQU8sQ0FBQyxTQUFTLENBQUMsT0FBTyxDQUFDLDRCQUE0QixDQUFDLENBQUM7SUFDNUQsQ0FBQztJQUFDLElBQUksQ0FBQyxDQUFDO1FBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsNkJBQTZCLENBQUMsQ0FBQztRQUN2RCxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3BCLENBQUM7QUFDTCxDQUFDLENBQUMsQ0FBQyJ9
|
9
dist/npmdocker.config.d.ts
vendored
9
dist/npmdocker.config.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
import { IKeyValueObject } from 'qenv';
|
||||
export interface IConfig {
|
||||
baseImage: string;
|
||||
command: string;
|
||||
dockerSock: boolean;
|
||||
exitCode?: number;
|
||||
keyValueObjectArray: IKeyValueObject[];
|
||||
}
|
||||
export declare let run: () => Promise<{}>;
|
37
dist/npmdocker.config.js
vendored
37
dist/npmdocker.config.js
vendored
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./npmdocker.plugins");
|
||||
const paths = require("./npmdocker.paths");
|
||||
;
|
||||
let getQenvKeyValueObject = () => {
|
||||
let done = plugins.q.defer();
|
||||
let qenvKeyValueObjectArray;
|
||||
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
|
||||
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray;
|
||||
}
|
||||
else {
|
||||
qenvKeyValueObjectArray = [];
|
||||
}
|
||||
;
|
||||
done.resolve(qenvKeyValueObjectArray);
|
||||
return done.promise;
|
||||
};
|
||||
let buildConfig = (qenvKeyValueObjectArrayArg) => {
|
||||
let done = plugins.q.defer();
|
||||
let npmextra = new plugins.npmextra.Npmextra(paths.cwd);
|
||||
let config = npmextra.dataFor('npmdocker', {
|
||||
baseImage: 'hosttoday/ht-docker-node:npmts',
|
||||
command: 'npm test',
|
||||
dockerSock: false,
|
||||
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||
});
|
||||
done.resolve(config);
|
||||
return done.promise;
|
||||
};
|
||||
exports.run = () => {
|
||||
let done = plugins.q.defer();
|
||||
getQenvKeyValueObject()
|
||||
.then(buildConfig)
|
||||
.then(done.resolve);
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLmNvbmZpZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUE4QztBQUM5QywyQ0FBMEM7QUFXekMsQ0FBQztBQUVGLElBQUkscUJBQXFCLEdBQUc7SUFDMUIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLHVCQUEwQyxDQUFBO0lBQzlDLEVBQUUsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGNBQWMsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFFLFVBQVUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2xGLHVCQUF1QixHQUFHLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLEdBQUcsRUFBRSxTQUFTLENBQUMsQ0FBQyxtQkFBbUIsQ0FBQTtJQUMzRixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTix1QkFBdUIsR0FBRyxFQUFFLENBQUE7SUFDOUIsQ0FBQztJQUFBLENBQUM7SUFDRixJQUFJLENBQUMsT0FBTyxDQUFDLHVCQUF1QixDQUFDLENBQUE7SUFDckMsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBO0FBRUQsSUFBSSxXQUFXLEdBQUcsQ0FBQywwQkFBMkM7SUFDNUQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLFFBQVEsR0FBRyxJQUFJLE9BQU8sQ0FBQyxRQUFRLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQTtJQUN2RCxJQUFJLE1BQU0sR0FBRyxRQUFRLENBQUMsT0FBTyxDQUMzQixXQUFXLEVBQ1g7UUFDRSxTQUFTLEVBQUUsZ0NBQWdDO1FBQzNDLE9BQU8sRUFBRSxVQUFVO1FBQ25CLFVBQVUsRUFBRSxLQUFLO1FBQ2pCLG1CQUFtQixFQUFFLDBCQUEwQjtLQUNoRCxDQUNGLENBQUE7SUFDRCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQ3BCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQTtBQUVVLFFBQUEsR0FBRyxHQUFHO0lBQ2YsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixxQkFBcUIsRUFBRTtTQUNwQixJQUFJLENBQUMsV0FBVyxDQUFDO1NBQ2pCLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDckIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7QUFDckIsQ0FBQyxDQUFBIn0=
|
1
dist/npmdocker.docker.d.ts
vendored
1
dist/npmdocker.docker.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare let run: (configArg: any) => Promise<{}>;
|
171
dist/npmdocker.docker.js
vendored
171
dist/npmdocker.docker.js
vendored
File diff suppressed because one or more lines are too long
5
dist/npmdocker.paths.d.ts
vendored
5
dist/npmdocker.paths.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export declare let cwd: string;
|
||||
export declare let packageBase: string;
|
||||
export declare let assets: string;
|
||||
export declare let buildContextDir: string;
|
||||
export declare let dockerfile: string;
|
12
dist/npmdocker.paths.js
vendored
12
dist/npmdocker.paths.js
vendored
@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./npmdocker.plugins");
|
||||
// directories
|
||||
exports.cwd = process.cwd();
|
||||
exports.packageBase = plugins.path.join(__dirname, "../");
|
||||
exports.assets = plugins.path.join(exports.packageBase, "assets/");
|
||||
plugins.smartfile.fs.ensureDirSync(exports.assets);
|
||||
exports.buildContextDir = plugins.path.join(exports.assets, "buildContextDir");
|
||||
plugins.smartfile.fs.ensureDirSync(exports.buildContextDir);
|
||||
// files
|
||||
exports.dockerfile = plugins.path.join(exports.assets, "Dockerfile");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBK0M7QUFFL0MsY0FBYztBQUNILFFBQUEsR0FBRyxHQUFHLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQztBQUNwQixRQUFBLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsS0FBSyxDQUFDLENBQUM7QUFDbEQsUUFBQSxNQUFNLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBRSxTQUFTLENBQUMsQ0FBQztBQUM5RCxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxhQUFhLENBQUMsY0FBTSxDQUFDLENBQUM7QUFFaEMsUUFBQSxlQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDekUsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsYUFBYSxDQUFDLHVCQUFlLENBQUMsQ0FBQztBQUVwRCxRQUFRO0FBQ0csUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLFlBQVksQ0FBQyxDQUFDIn0=
|
10
dist/npmdocker.plugins.d.ts
vendored
10
dist/npmdocker.plugins.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import npmextra = require("npmextra");
|
||||
export import path = require("path");
|
||||
export import projectinfo = require("projectinfo");
|
||||
export import q = require("smartq");
|
||||
export import qenv = require("qenv");
|
||||
export import shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
12
dist/npmdocker.plugins.js
vendored
12
dist/npmdocker.plugins.js
vendored
@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.npmextra = require("npmextra");
|
||||
exports.path = require("path");
|
||||
exports.projectinfo = require("projectinfo");
|
||||
exports.q = require("smartq");
|
||||
exports.qenv = require("qenv");
|
||||
exports.shelljs = require("shelljs");
|
||||
exports.smartfile = require("smartfile");
|
||||
exports.smartstring = require("smartstring");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1kb2NrZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLHlDQUErQztBQUMvQyx1Q0FBNkM7QUFDN0MsK0JBQXFDO0FBQ3JDLDZDQUFtRDtBQUNuRCw4QkFBb0M7QUFDcEMsK0JBQXFDO0FBQ3JDLHFDQUEyQztBQUMzQyx5Q0FBK0M7QUFDL0MsNkNBQW1EIn0=
|
1
dist/npmdocker.promisechain.d.ts
vendored
1
dist/npmdocker.promisechain.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare let run: () => Promise<{}>;
|
16
dist/npmdocker.promisechain.js
vendored
16
dist/npmdocker.promisechain.js
vendored
@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./npmdocker.plugins");
|
||||
//modules
|
||||
const ConfigModule = require("./npmdocker.config");
|
||||
const DockerModule = require("./npmdocker.docker");
|
||||
plugins.beautylog.ora.start();
|
||||
exports.run = () => {
|
||||
let done = plugins.q.defer();
|
||||
ConfigModule.run()
|
||||
.then(DockerModule.run)
|
||||
.then((configArg) => {
|
||||
done.resolve(configArg);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnByb21pc2VjaGFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWRvY2tlci5wcm9taXNlY2hhaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLCtDQUErQztBQUcvQyxTQUFTO0FBQ1QsbURBQW1EO0FBQ25ELG1EQUFtRDtBQUVuRCxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxLQUFLLEVBQUUsQ0FBQztBQUNuQixRQUFBLEdBQUcsR0FBRztJQUNiLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsWUFBWSxDQUFDLEdBQUcsRUFBRTtTQUNiLElBQUksQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDO1NBQ3RCLElBQUksQ0FBQyxDQUFDLFNBQVM7UUFDWixJQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0lBQzVCLENBQUMsQ0FBQyxDQUFBO0lBQ04sTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFBIn0=
|
5
dist/npmdocker.snippets.d.ts
vendored
5
dist/npmdocker.snippets.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export interface IDockerfileSnippet {
|
||||
baseImage: string;
|
||||
command: string;
|
||||
}
|
||||
export declare let dockerfileSnippet: (optionsArg: IDockerfileSnippet) => string;
|
21
dist/npmdocker.snippets.js
vendored
21
dist/npmdocker.snippets.js
vendored
@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./npmdocker.plugins");
|
||||
exports.dockerfileSnippet = (optionsArg) => {
|
||||
let commandArray = optionsArg.command.split(/\s/);
|
||||
let commandString = "";
|
||||
for (let stringItem of commandArray) {
|
||||
if (!(commandString == "")) {
|
||||
commandString = commandString + ",";
|
||||
}
|
||||
commandString = commandString + '"' + stringItem + '"';
|
||||
}
|
||||
;
|
||||
return plugins.smartstring.indent.normalize(`
|
||||
FROM ${optionsArg.baseImage}
|
||||
COPY ./buildContextDir /workspace
|
||||
WORKDIR /workspace
|
||||
ENV CI=true
|
||||
CMD [${commandString}];
|
||||
`);
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZG9ja2VyLnNuaXBwZXRzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZG9ja2VyLnNuaXBwZXRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBK0M7QUFPcEMsUUFBQSxpQkFBaUIsR0FBRyxDQUFDLFVBQTZCO0lBQ3pELElBQUksWUFBWSxHQUFHLFVBQVUsQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2xELElBQUksYUFBYSxHQUFVLEVBQUUsQ0FBQztJQUM5QixHQUFHLENBQUEsQ0FBQyxJQUFJLFVBQVUsSUFBSSxZQUFZLENBQUMsQ0FBQSxDQUFDO1FBQ2hDLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxhQUFhLElBQUksRUFBRSxDQUFDLENBQUMsQ0FBQSxDQUFDO1lBQ3ZCLGFBQWEsR0FBRyxhQUFhLEdBQUcsR0FBRyxDQUFDO1FBQ3hDLENBQUM7UUFDRCxhQUFhLEdBQUcsYUFBYSxHQUFHLEdBQUcsR0FBRyxVQUFVLEdBQUcsR0FBRyxDQUFDO0lBQzNELENBQUM7SUFBQSxDQUFDO0lBQ0YsTUFBTSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQztlQUNqQyxVQUFVLENBQUMsU0FBUzs7OztlQUlwQixhQUFhO0tBQ3ZCLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQSJ9
|
1
docs/index.md
Normal file
1
docs/index.md
Normal file
@ -0,0 +1 @@
|
||||
Docs for npmpage coming soon.
|
@ -1,7 +1,13 @@
|
||||
{
|
||||
"npmts":{
|
||||
"mode":"default",
|
||||
"cli":true,
|
||||
"dockerSock":true
|
||||
}
|
||||
"npmts": {
|
||||
"mode": "default",
|
||||
"cli": true
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"@gitzone/npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
1908
package-lock.json
generated
Normal file
1908
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@ -1,22 +1,22 @@
|
||||
{
|
||||
"name": "npmdocker",
|
||||
"version": "1.2.2",
|
||||
"name": "@gitzone/npmdocker",
|
||||
"version": "1.2.24",
|
||||
"private": false,
|
||||
"description": "develop npm modules cross platform with docker",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"bin": {
|
||||
"npmdocker": "dist/cli.js"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
"npmdocker": "cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "(npm run clean && npm run compile && npm run setupCheck && npm run check)",
|
||||
"testDev": "(npm run compile && npm run check)",
|
||||
"test": "(npm run clean && npm run setupCheck && npm run testStandard && npm run testSpeed)",
|
||||
"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)",
|
||||
"clean": "(rm -rf test/)",
|
||||
"compile": "(npmts --notest)",
|
||||
"setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)",
|
||||
"check": "(cd test/ && node ../dist/index.js)"
|
||||
"setupCheck": "(git clone https://gitlab.com/sandboxzone/sandbox-npmts.git test/)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -32,18 +32,23 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/gitzone/npmdocker#README",
|
||||
"devDependencies": {
|
||||
"npmts-g": "^6.0.0"
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.1.12",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.9.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/shelljs": "0.x.x",
|
||||
"beautylog": "^6.1.1",
|
||||
"npmextra": "^2.0.3",
|
||||
"projectinfo": "^3.0.1",
|
||||
"qenv": "^1.1.3",
|
||||
"shelljs": "^0.7.6",
|
||||
"smartfile": "^4.1.5",
|
||||
"smartq": "^1.1.0",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/npmextra": "^3.0.1",
|
||||
"@pushrocks/projectinfo": "^4.0.2",
|
||||
"@pushrocks/qenv": "^2.0.2",
|
||||
"@pushrocks/smartcli": "^3.0.4",
|
||||
"@pushrocks/smartfile": "^6.0.8",
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@pushrocks/smartshell": "^2.0.6",
|
||||
"@pushrocks/smartstring": "^3.0.4",
|
||||
"@types/shelljs": "^0.8.0",
|
||||
"beautylog": "^6.1.10",
|
||||
"smartanalytics": "^2.0.9"
|
||||
}
|
||||
}
|
||||
|
20
ts/analytics.ts
Normal file
20
ts/analytics.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* smartanalytics:
|
||||
* We count executions of this tool to keep track which of our tools are really used.
|
||||
* This insight is used to plan spending our limited resources for improving them.
|
||||
* Any submitted analytics data is fully anonymized (no Ips or any other personal information is tracked).
|
||||
* Feel free to dig into the smartanalytics package, if you are interested in how it works.
|
||||
* Our privacy policy can be found here: https://lossless.gmbh/privacy.html
|
||||
* The privacy policy is also linked in the readme, so we hope this behaviour does not come as a surprise to you.
|
||||
* Have a nice day and regards
|
||||
* Your Open Source team at Lossless GmbH :)
|
||||
*/
|
||||
import * as smartanalytics from 'smartanalytics';
|
||||
let npmdockerAnalytics = new smartanalytics.Analytics({
|
||||
apiEndPoint: 'https://pubapi.lossless.one',
|
||||
appName: 'npmdocker',
|
||||
projectId: 'gitzone'
|
||||
});
|
||||
npmdockerAnalytics.recordEvent('npmtoolexecution', {
|
||||
somedata: 'somedata'
|
||||
});
|
18
ts/index.ts
18
ts/index.ts
@ -1,15 +1,5 @@
|
||||
import * as plugins from "./npmdocker.plugins";
|
||||
import * as promisechain from "./npmdocker.promisechain";
|
||||
import * as ConfigModule from "./npmdocker.config";
|
||||
|
||||
|
||||
promisechain.run()
|
||||
.then((configArg:ConfigModule.IConfig) => {
|
||||
if(configArg.exitCode == 0){
|
||||
plugins.beautylog.success("container ended all right!");
|
||||
} else {
|
||||
plugins.beautylog.error("container ended with error!");
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
import './analytics';
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as cli from './npmdocker.cli';
|
||||
|
||||
cli.run();
|
||||
|
76
ts/npmdocker.cli.ts
Normal file
76
ts/npmdocker.cli.ts
Normal file
@ -0,0 +1,76 @@
|
||||
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';
|
||||
|
||||
let npmdockerCli = new plugins.smartcli.Smartcli();
|
||||
|
||||
export let run = () => {
|
||||
npmdockerCli.standardTask().subscribe(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!');
|
||||
} else {
|
||||
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').subscribe(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();
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
})
|
||||
await smartshellInstance.exec(configArg.command).then(response => {
|
||||
if (response.exitCode !== 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
npmdockerCli.addCommand('clean').subscribe(async argvArg => {
|
||||
plugins.beautylog.ora.start();
|
||||
plugins.beautylog.ora.text('cleaning up docker env...');
|
||||
if (argvArg.all) {
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
})
|
||||
plugins.beautylog.ora.text('killing any running docker containers...');
|
||||
await smartshellInstance.exec(`docker kill $(docker ps -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing stopped containers...');
|
||||
await smartshellInstance.exec(`docker rm $(docker ps -a -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing images...');
|
||||
await smartshellInstance.exec(`docker rmi $(docker images -q -f dangling=true)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing all other images...');
|
||||
await smartshellInstance.exec(`docker rmi $(docker images -a -q)`);
|
||||
|
||||
plugins.beautylog.ora.text('removing all volumes...');
|
||||
await smartshellInstance.exec(`docker volume rm $(docker volume ls -f dangling=true -q)`);
|
||||
}
|
||||
plugins.beautylog.ora.endOk('docker environment now is clean!');
|
||||
});
|
||||
|
||||
npmdockerCli.addCommand('speedtest').subscribe(async argvArg => {
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
})
|
||||
plugins.beautylog.figletSync('npmdocker');
|
||||
plugins.beautylog.ok('Starting speedtest');
|
||||
await smartshellInstance.exec(
|
||||
`docker pull tianon/speedtest && docker run --rm tianon/speedtest`
|
||||
);
|
||||
});
|
||||
|
||||
npmdockerCli.startParse();
|
||||
};
|
@ -1,49 +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 '@pushrocks/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[];
|
||||
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
|
||||
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray;
|
||||
} else {
|
||||
qenvKeyValueObjectArray = [];
|
||||
}
|
||||
return qenvKeyValueObjectArray;
|
||||
};
|
||||
|
||||
let getQenvKeyValueObject = () => {
|
||||
let done = plugins.q.defer()
|
||||
let qenvKeyValueObjectArray: IKeyValueObject[]
|
||||
if (plugins.smartfile.fs.fileExistsSync(plugins.path.join(paths.cwd, 'qenv.yml'))) {
|
||||
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray
|
||||
} else {
|
||||
qenvKeyValueObjectArray = []
|
||||
};
|
||||
done.resolve(qenvKeyValueObjectArray)
|
||||
return done.promise
|
||||
}
|
||||
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 buildConfig = (qenvKeyValueObjectArrayArg: IKeyValueObject) => {
|
||||
let done = plugins.q.defer()
|
||||
let npmextra = new plugins.npmextra.Npmextra(paths.cwd)
|
||||
let config = npmextra.dataFor<IConfig>(
|
||||
'npmdocker',
|
||||
{
|
||||
baseImage: 'hosttoday/ht-docker-node:npmts',
|
||||
command: 'npm test',
|
||||
dockerSock: false,
|
||||
keyValueObjectArray: qenvKeyValueObjectArrayArg
|
||||
}
|
||||
)
|
||||
done.resolve(config)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
export let run = () => {
|
||||
let done = plugins.q.defer()
|
||||
getQenvKeyValueObject()
|
||||
.then(buildConfig)
|
||||
.then(done.resolve)
|
||||
return done.promise
|
||||
}
|
||||
export let run = async (): Promise<IConfig> => {
|
||||
let config = await getQenvKeyValueObject().then(buildConfig);
|
||||
return config;
|
||||
};
|
||||
|
@ -1,11 +1,15 @@
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
import * as paths from './npmdocker.paths';
|
||||
import * as snippets from './npmdocker.snippets'
|
||||
import * as snippets from './npmdocker.snippets';
|
||||
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
})
|
||||
|
||||
// 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,183 +20,139 @@ let dockerData = {
|
||||
dockerProjectMountString: '',
|
||||
dockerSockString: '',
|
||||
dockerEnvString: ''
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* check if docker is available
|
||||
*/
|
||||
let checkDocker = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('checking docker...')
|
||||
if (plugins.shelljs.which('docker')) {
|
||||
plugins.beautylog.ok('Docker found!')
|
||||
done.resolve()
|
||||
let done = plugins.smartpromise.defer();
|
||||
plugins.beautylog.ora.text('checking docker...');
|
||||
|
||||
if (smartshellInstance.exec('which docker')) {
|
||||
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.smartpromise.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, paths.dockerfile)
|
||||
plugins.beautylog.ok('Dockerfile created!')
|
||||
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 = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('pulling latest base image from registry...')
|
||||
plugins.shelljs.exec(
|
||||
`docker pull ${config.baseImage}`,
|
||||
{
|
||||
silent: true
|
||||
},
|
||||
() => {
|
||||
plugins.beautylog.ora.text('building Dockerimage...')
|
||||
// are we creating a build context form project ?
|
||||
if (process.env.CI === 'true') {
|
||||
plugins.beautylog.ora.text('creating build context...')
|
||||
plugins.smartfile.fs.copySync(paths.cwd, paths.buildContextDir)
|
||||
}
|
||||
plugins.shelljs.exec(
|
||||
`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`,
|
||||
{
|
||||
silent: true
|
||||
},
|
||||
() => {
|
||||
plugins.beautylog.ok('Dockerimage built!')
|
||||
done.resolve()
|
||||
}
|
||||
)
|
||||
}
|
||||
) // first pull latest version of baseImage
|
||||
return done.promise
|
||||
}
|
||||
let buildDockerImage = async () => {
|
||||
plugins.beautylog.info('pulling latest base image from registry...');
|
||||
await smartshellInstance.exec(`docker pull ${config.baseImage}`);
|
||||
plugins.beautylog.ora.text('building Dockerimage...');
|
||||
let execResult = await smartshellInstance.execSilent(
|
||||
`docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}`
|
||||
);
|
||||
if (execResult.exitCode !== 0) {
|
||||
console.log(execResult.stdout);
|
||||
process.exit(1);
|
||||
}
|
||||
plugins.beautylog.ok('Dockerimage built!');
|
||||
};
|
||||
|
||||
let buildDockerProjectMountString = () => {
|
||||
let done = plugins.q.defer()
|
||||
let buildDockerProjectMountString = async () => {
|
||||
if (process.env.CI !== 'true') {
|
||||
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`
|
||||
};
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
dockerData.dockerProjectMountString = `-v ${paths.cwd}:/workspace`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* builds an environment string that docker cli understands
|
||||
*/
|
||||
let buildDockerEnvString = () => {
|
||||
let done = plugins.q.defer()
|
||||
let buildDockerEnvString = async () => {
|
||||
for (let keyValueObjectArg of config.keyValueObjectArray) {
|
||||
let envString = dockerData.dockerEnvString = dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `
|
||||
};
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
let envString = (dockerData.dockerEnvString =
|
||||
dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* creates string to mount the docker.sock inside the testcontainer
|
||||
*/
|
||||
let buildDockerSockString = () => {
|
||||
let done = plugins.q.defer()
|
||||
let buildDockerSockString = async () => {
|
||||
if (config.dockerSock) {
|
||||
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`
|
||||
};
|
||||
done.resolve()
|
||||
return done
|
||||
}
|
||||
dockerData.dockerSockString = `-v /var/run/docker.sock:/var/run/docker.sock`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a container by running the built Dockerimage
|
||||
*/
|
||||
let runDockerImage = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.beautylog.ora.text('starting Container...')
|
||||
plugins.beautylog.ora.end()
|
||||
plugins.beautylog.log('now running Dockerimage')
|
||||
config.exitCode = plugins.shelljs.exec(`docker run ${dockerData.dockerProjectMountString} ${dockerData.dockerSockString} ${dockerData.dockerEnvString} --name ${dockerData.containerName} ${dockerData.imageTag}`).code
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
let runDockerImage = async () => {
|
||||
let done = plugins.smartpromise.defer();
|
||||
plugins.beautylog.ora.text('starting Container...');
|
||||
plugins.beautylog.ora.end();
|
||||
plugins.beautylog.log('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
|
||||
*/
|
||||
let deleteDockerContainer = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.shelljs.exec(`docker rm -f ${dockerData.containerName}`, {
|
||||
silent: true
|
||||
})
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
let deleteDockerContainer = async () => {
|
||||
await smartshellInstance.execSilent(`docker rm -f ${dockerData.containerName}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans up deletes the test image
|
||||
*/
|
||||
let deleteDockerImage = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.shelljs.exec(`docker rmi ${dockerData.imageTag}`, {
|
||||
silent: true
|
||||
})
|
||||
done.resolve()
|
||||
return done.promise
|
||||
}
|
||||
let deleteDockerImage = async () => {
|
||||
await smartshellInstance.execSilent(`docker rmi ${dockerData.imageTag}`).then(async response => {
|
||||
if (response.exitCode !== 0) {
|
||||
console.log(response.stdout);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans up, deletes the build context
|
||||
*/
|
||||
let deleteBuildContext = () => {
|
||||
let done = plugins.q.defer()
|
||||
plugins.smartfile.fs.remove(paths.buildContextDir)
|
||||
.then(() => {
|
||||
done.resolve()
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let preClean = () => {
|
||||
let done = plugins.q.defer()
|
||||
deleteDockerImage()
|
||||
let preClean = async () => {
|
||||
await deleteDockerImage()
|
||||
.then(deleteDockerContainer)
|
||||
.then(() => {
|
||||
plugins.beautylog.ok('ensured clean Docker environment!')
|
||||
done.resolve()
|
||||
})
|
||||
}
|
||||
.then(async () => {
|
||||
plugins.beautylog.ok('ensured clean Docker environment!');
|
||||
});
|
||||
};
|
||||
|
||||
let postClean = () => {
|
||||
let done = plugins.q.defer()
|
||||
deleteDockerContainer()
|
||||
let postClean = async () => {
|
||||
await deleteDockerContainer()
|
||||
.then(deleteDockerImage)
|
||||
.then(deleteBuildContext)
|
||||
.then(() => {
|
||||
plugins.beautylog.ok('cleaned up!')
|
||||
done.resolve()
|
||||
})
|
||||
}
|
||||
.then(async () => {
|
||||
plugins.beautylog.ok('cleaned up!');
|
||||
});
|
||||
plugins.smartfile.fs.removeSync(paths.npmdockerFile);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export let run = (configArg) => {
|
||||
let done = plugins.q.defer()
|
||||
config = configArg
|
||||
checkDocker()
|
||||
export let run = async (configArg: IConfig): Promise<IConfig> => {
|
||||
plugins.beautylog.ora.start();
|
||||
config = configArg;
|
||||
let resultConfig = await checkDocker()
|
||||
.then(preClean)
|
||||
.then(buildDockerFile)
|
||||
.then(buildDockerImage)
|
||||
@ -201,8 +161,8 @@ export let run = (configArg) => {
|
||||
.then(buildDockerSockString)
|
||||
.then(runDockerImage)
|
||||
.then(postClean)
|
||||
.then(() => {
|
||||
done.resolve(config);
|
||||
}).catch(err => { console.log(err) })
|
||||
return done.promise
|
||||
}
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
return config;
|
||||
};
|
||||
|
@ -1,13 +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/");
|
||||
export let packageBase = plugins.path.join(__dirname, '../');
|
||||
export let assets = plugins.path.join(packageBase, 'assets/');
|
||||
plugins.smartfile.fs.ensureDirSync(assets);
|
||||
|
||||
export let buildContextDir = plugins.path.join(assets,"buildContextDir");
|
||||
plugins.smartfile.fs.ensureDirSync(buildContextDir);
|
||||
|
||||
// files
|
||||
export let dockerfile = plugins.path.join(assets, "Dockerfile");
|
||||
export let npmdockerFile = plugins.path.join(cwd, 'npmdocker');
|
||||
|
@ -1,10 +1,23 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import npmextra = require("npmextra");
|
||||
export import path = require("path");
|
||||
export import projectinfo = require("projectinfo");
|
||||
export import q = require("smartq");
|
||||
export import qenv = require("qenv");
|
||||
export import shelljs = require("shelljs");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
import * as beautylog from 'beautylog';
|
||||
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 smartshell from '@pushrocks/smartshell';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
npmextra,
|
||||
path,
|
||||
projectinfo,
|
||||
smartpromise,
|
||||
qenv,
|
||||
smartcli,
|
||||
smartfile,
|
||||
smartshell,
|
||||
smartstring
|
||||
};
|
||||
|
@ -1,17 +0,0 @@
|
||||
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";
|
||||
|
||||
plugins.beautylog.ora.start();
|
||||
export let run = () => {
|
||||
let done = plugins.q.defer();
|
||||
ConfigModule.run()
|
||||
.then(DockerModule.run)
|
||||
.then((configArg) => {
|
||||
done.resolve(configArg);
|
||||
})
|
||||
return done.promise;
|
||||
}
|
@ -1,24 +1,37 @@
|
||||
import * as plugins from "./npmdocker.plugins";
|
||||
import * as plugins from './npmdocker.plugins';
|
||||
|
||||
export interface IDockerfileSnippet {
|
||||
baseImage:string;
|
||||
command:string;
|
||||
baseImage: string;
|
||||
command: string;
|
||||
}
|
||||
|
||||
export let dockerfileSnippet = (optionsArg:IDockerfileSnippet):string => {
|
||||
let commandArray = optionsArg.command.split(/\s/);
|
||||
let commandString:string = "";
|
||||
for(let stringItem of commandArray){
|
||||
if(!(commandString == "")){
|
||||
commandString = commandString + ",";
|
||||
}
|
||||
commandString = commandString + '"' + stringItem + '"';
|
||||
};
|
||||
return plugins.smartstring.indent.normalize(`
|
||||
FROM ${optionsArg.baseImage}
|
||||
COPY ./buildContextDir /workspace
|
||||
WORKDIR /workspace
|
||||
ENV CI=true
|
||||
CMD [${commandString}];
|
||||
`);
|
||||
}
|
||||
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"]
|
||||
`
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user