update structure
This commit is contained in:
parent
95608704e4
commit
1def03d840
@ -1 +1,3 @@
|
|||||||
FROM hosttoday/ht-docker-node:lts
|
FROM hosttoday/ht-docker-node:lts
|
||||||
|
COPY ./node_modules /app-node/node_modules
|
||||||
|
COPY ./dist /app-node/dist
|
28
README.md
Normal file
28
README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# dockersock
|
||||||
|
easy communication with docker from node, TypeScript ready
|
||||||
|
|
||||||
|
## Status
|
||||||
|
[![build status](https://gitlab.com/pushrocks/dockersock/badges/master/build.svg)](https://gitlab.com/pushrocks/dockersock/commits/master)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
We recommend the use of TypeScript for best Intellisense.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
import {Dockersock} from "dockersock"; // require Dockersock class
|
||||||
|
|
||||||
|
let myDockersock = new Dockersock(); // optional: you can pass a domain to the contructor, defaults to /var/run/docker.sock
|
||||||
|
|
||||||
|
myDockersock.listContainers() // promise, resolve gets container data
|
||||||
|
myDockersock.listContainersDetailed() // promise, resolve gets more detailed container data (by combining several requests internally)
|
||||||
|
myDockersock.listContainersRunning() // promise, resolve gets container data for currently running containers
|
||||||
|
myDockersock.listContainersStopped() // promise, resolve gets container data for stopped containers
|
||||||
|
|
||||||
|
myDockersock.startContainer({ // starts a already present container
|
||||||
|
name: "somecontainername"
|
||||||
|
})
|
||||||
|
|
||||||
|
myDockersock.newContainer({ // start new Container, equals "docker run" shell command
|
||||||
|
image: "someimagetag"
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
6
dist/dockersock.class.dockersock.d.ts
vendored
Normal file
6
dist/dockersock.class.dockersock.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export declare class dockersock {
|
||||||
|
sockPath: string;
|
||||||
|
constructor(pathArg: string);
|
||||||
|
request(methodArg: string, routeArg: string, dataArg?: {}): any;
|
||||||
|
}
|
38
dist/dockersock.class.dockersock.js
vendored
Normal file
38
dist/dockersock.class.dockersock.js
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
var plugins = require("./dockersock.plugins");
|
||||||
|
var dockersock = (function () {
|
||||||
|
function dockersock(pathArg) {
|
||||||
|
this.sockPath = pathArg;
|
||||||
|
}
|
||||||
|
dockersock.prototype.request = function (methodArg, routeArg, dataArg) {
|
||||||
|
if (dataArg === void 0) { dataArg = {}; }
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
var jsonArg = JSON.stringify(dataArg);
|
||||||
|
var options = {
|
||||||
|
method: methodArg,
|
||||||
|
url: "http://unix:/var/run/docker.sock:" + routeArg + "/json",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: jsonArg
|
||||||
|
};
|
||||||
|
plugins.request(options, function (err, res, body) {
|
||||||
|
if (!err && res.statusCode == 200) {
|
||||||
|
var responseObj = JSON.parse(body);
|
||||||
|
done.resolve(responseObj);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(err);
|
||||||
|
console.log(res);
|
||||||
|
done.reject(err);
|
||||||
|
}
|
||||||
|
;
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
return dockersock;
|
||||||
|
}());
|
||||||
|
exports.dockersock = dockersock;
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2suY2xhc3MuZG9ja2Vyc29jay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ3ZCLElBQVksT0FBTyxXQUFNLHNCQUFzQixDQUFDLENBQUE7QUFFaEQ7SUFFSSxvQkFBWSxPQUFjO1FBQ3RCLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDO0lBQzVCLENBQUM7S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9keSl7XG4gICAgICAgICAgICBpZiAoIWVyciAmJiByZXMuc3RhdHVzQ29kZSA9PSAyMDApIHtcbiAgICAgICAgICAgICAgICB2YXIgcmVzcG9uc2VPYmogPSBKU09OLnBhcnNlKGJvZHkpO1xuICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZShyZXNwb25zZU9iaik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycik7XG4gICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKTtcbiAgICAgICAgICAgICAgICBkb25lLnJlamVjdChlcnIpO1xuICAgICAgICAgICAgfTtcbiAgICAgICAgfSk7XG4gICAgICAgIHJldHVybiBkb25lLnByb21pc2U7XG4gICAgfVxufSJdfQ==
|
4
dist/dockersock.plugins.d.ts
vendored
Normal file
4
dist/dockersock.plugins.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import "typings-global";
|
||||||
|
export import beautylog = require("beautylog");
|
||||||
|
export declare let q: any;
|
||||||
|
export declare let request: any;
|
7
dist/dockersock.plugins.js
vendored
Normal file
7
dist/dockersock.plugins.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-global");
|
||||||
|
exports.beautylog = require("beautylog");
|
||||||
|
exports.q = require("q");
|
||||||
|
exports.request = require("request");
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRvY2tlcnNvY2sucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ1YsaUJBQVMsV0FBVyxXQUFXLENBQUMsQ0FBQztBQUNwQyxTQUFDLEdBQUcsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ2pCLGVBQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUMiLCJmaWxlIjoiZG9ja2Vyc29jay5wbHVnaW5zLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIjtcbmV4cG9ydCBpbXBvcnQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcSA9IHJlcXVpcmUoXCJxXCIpO1xuZXhwb3J0IGxldCByZXF1ZXN0ID0gcmVxdWlyZShcInJlcXVlc3RcIik7Il19
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "dockersock",
|
"name": "dockersock",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "communicate with docker sock from node",
|
"description": "easy communication with docker from node, TypeScript ready",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npmts"
|
"test": "npmts",
|
||||||
|
"testindocker":"npmts && docker-machine start default; eval \"$(docker-machine env default)\" && docker build -t test-image . && docker run test-image"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -6,7 +6,28 @@ export class dockersock {
|
|||||||
constructor(pathArg:string){
|
constructor(pathArg:string){
|
||||||
this.sockPath = pathArg;
|
this.sockPath = pathArg;
|
||||||
}
|
}
|
||||||
request(){
|
|
||||||
|
|
||||||
|
request(methodArg:string,routeArg:string,dataArg = {}){
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let jsonArg:string = JSON.stringify(dataArg);
|
||||||
|
let options = {
|
||||||
|
method:methodArg,
|
||||||
|
url:"http://unix:/var/run/docker.sock:" + routeArg + "/json",
|
||||||
|
headers:{
|
||||||
|
"Content-Type":"application/json"
|
||||||
|
},
|
||||||
|
body:jsonArg
|
||||||
|
};
|
||||||
|
plugins.request(options,function(err, res, body){
|
||||||
|
if (!err && res.statusCode == 200) {
|
||||||
|
var responseObj = JSON.parse(body);
|
||||||
|
done.resolve(responseObj);
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
console.log(res);
|
||||||
|
done.reject(err);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user