-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.js
127 lines (123 loc) · 2.75 KB
/
docker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict'
var _ = require('lodash')
module.exports = function (options) {
var seneca = this
var plugin = 'docker'
seneca.depends('docker', 'unix-command')
seneca.add({
role: plugin,
required$: ['command'],
atleastone$: ['machine', 'ip'],
options: {
object$: true
},
command: {
string$: true
},
machine: {
type: {
string$: true
}
}
}, docker_command)
function docker_command (msg, done) {
var format = msg.format || 'string'
var port = msg.port ? msg.port : 2376
var machine = msg.machine
var command = 'docker ' + msg.command
var act = {
role: 'unix-command',
command: command,
args: msg.args,
extra: msg.extra,
format: format
}
var opts = {}
if (msg.ip) {
if (!options.certs_dir) return done('options.certs_dir required for ip access')
opts.env = {
DOCKER_HOST: `tcp://${msg.ip}:${port}`,
DOCKER_TLS_VERIFY: '1',
DOCKER_CERT_PATH: options.certs_dir
}
}
else {
opts.$env = {
$DOCKER_HOST: '$.machine_url',
DOCKER_TLS_VERIFY: '1',
$DOCKER_CERT_PATH: '$.machine_info.HostOptions.AuthOptions.StorePath'
}
act.$$machine_info = {
role: 'docker-machine',
cmd: 'machine-command',
command: 'inspect',
format: 'json',
machine: machine
}
act.$$machine_url = {
role: 'docker-machine',
cmd: 'info',
machine: machine,
out$: [{
_: 'get',
args: 'url'
}]
}
}
act.$options = seneca.util.deepextend(msg.options, opts)
seneca.flow_act(act, done)
}
seneca.add({
role: plugin,
command: 'run',
required$: ['image'],
args: {
object$: true
},
image: {
string$: true
}
}, docker_run)
function docker_run (msg, done) {
if (_.isArray(msg.image_options)) {
msg.image_options = msg.image_options.join(' ')
}
msg.extra = msg.image_options ? msg.image : msg.image + ' ' + msg.image_options
msg.args = seneca.util.deepextend({
detach: true
}, msg.args)
this.prior(msg, done)
}
seneca.add({
role: plugin,
command: 'login',
required$: ['username', 'password', 'provider', 'machine'],
username: {
string$: true
},
password: {
string$: true
},
provider: {
string$: true
}
}, docker_login)
function docker_login (msg, done) {
this.prior({
role: plugin,
command: 'login',
args: {
username: msg.username,
password: msg.password
},
extra: msg.provider,
machine: msg.machine
}, done)
}
return {
name: plugin,
export: {
certs_dir: options.certs_dir
}
}
}