ln-docker-daemons 8.1.4 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bitcoinrpc/rpc.js CHANGED
@@ -4,6 +4,7 @@ const {returnResult} = require('asyncjs-util');
4
4
 
5
5
  const defaultTimeout = 1000 * 30;
6
6
  const {isInteger} = Number;
7
+ const isPositiveInteger = n => isInteger(n) && n > 0;
7
8
  const isSuccess = code => code >= 200 && code < 300;
8
9
  const isTimeout = err => ['AbortError', 'TimeoutError'].includes(err.name);
9
10
  const lostCodes = ['ECONNRESET', 'EPIPE', 'UND_ERR_CLOSED', 'UND_ERR_SOCKET'];
@@ -29,32 +30,32 @@ const unsentCodes = ['ECONNREFUSED', 'UND_ERR_CONNECT_TIMEOUT'];
29
30
  @returns via cbk or Promise
30
31
  <Result Object>
31
32
  */
32
- module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
33
+ module.exports = (args, cbk) => {
33
34
  return new Promise((resolve, reject) => {
34
35
  return asyncAuto({
35
36
  // Check arguments
36
37
  validate: cbk => {
37
- if (!cmd) {
38
+ if (!args.cmd) {
38
39
  return cbk([400, 'ExpectedCommandNameToExecuteRpcCall']);
39
40
  }
40
41
 
41
- if (!host) {
42
+ if (!args.host) {
42
43
  return cbk([400, 'ExpectedRpcHostToExecuteRpcCall']);
43
44
  }
44
45
 
45
- if (!params) {
46
+ if (!args.params) {
46
47
  return cbk([400, 'ExpectedCommandParametersToExecuteRpcCall']);
47
48
  }
48
49
 
49
- if (!pass) {
50
+ if (!args.pass) {
50
51
  return cbk([400, 'ExpectedRpcPasswordToExecuteRpcCall']);
51
52
  }
52
53
 
53
- if (timeout !== undefined && !(isInteger(timeout) && timeout > 0)) {
54
+ if (args.timeout !== undefined && !isPositiveInteger(args.timeout)) {
54
55
  return cbk([400, 'ExpectedPositiveTimeoutToExecuteRpcCall']);
55
56
  }
56
57
 
57
- if (!user) {
58
+ if (!args.user) {
58
59
  return cbk([400, 'ExpectedRpcUsernameToExecuteRpcCall']);
59
60
  }
60
61
 
@@ -64,17 +65,21 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
64
65
  // Send request to the server, failures are returned rather than thrown
65
66
  request: ['validate', async ({}) => {
66
67
  const controller = new AbortController();
67
- const credentials = Buffer.from(`${user}:${pass}`);
68
+ const credentials = Buffer.from(`${args.user}:${args.pass}`);
68
69
 
69
70
  // Unlike AbortSignal.timeout, this timer keeps the process alive
70
71
  const timer = setTimeout(() => {
71
72
  return controller.abort(new DOMException(timeoutMessage, timedOut));
72
73
  },
73
- timeout || defaultTimeout);
74
+ args.timeout || defaultTimeout);
74
75
 
75
76
  try {
76
- const response = await fetch(`http://${host}:${port}/`, {
77
- body: stringify({params, id: `${++requests}`, method: cmd}),
77
+ const response = await fetch(`http://${args.host}:${args.port}/`, {
78
+ body: stringify({
79
+ id: `${++requests}`,
80
+ method: args.cmd,
81
+ params: args.params,
82
+ }),
78
83
  headers: {
79
84
  'Authorization': `Basic ${credentials.toString('base64')}`,
80
85
  'Content-Type': 'application/json',
@@ -106,7 +111,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
106
111
 
107
112
  // The request timed out so the command may have been executed
108
113
  if (isTimeout(err)) {
109
- return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd}]);
114
+ return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd: args.cmd}]);
110
115
  }
111
116
 
112
117
  // Undici puts the underlying failure reason into the error cause
@@ -118,7 +123,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
118
123
  const reason = failure || cause;
119
124
 
120
125
  const details = {
121
- cmd,
126
+ cmd: args.cmd,
122
127
  code,
123
128
  err,
124
129
  message: reason.message || err.message,
@@ -139,7 +144,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
139
144
 
140
145
  // Parse the response body as a JSON-RPC response object
141
146
  parseBody: ['checkRequest', 'request', asyncify(({request}) => {
142
- const details = {cmd, status: request.statusCode};
147
+ const details = {cmd: args.cmd, status: request.statusCode};
143
148
 
144
149
  try {
145
150
  const body = parse(request.body);
@@ -164,7 +169,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
164
169
  return cbk([
165
170
  503,
166
171
  'UnexpectedErrorFromRpcCommand',
167
- {cmd, code: error.code, message: error.message},
172
+ {cmd: args.cmd, code: error.code, message: error.message},
168
173
  ]);
169
174
  }
170
175
 
@@ -173,7 +178,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
173
178
  return cbk([
174
179
  503,
175
180
  'UnexpectedRpcServiceResponse',
176
- {cmd, status: request.statusCode},
181
+ {cmd: args.cmd, status: request.statusCode},
177
182
  ]);
178
183
  }
179
184
 
@@ -10,13 +10,19 @@
10
10
  @returns
11
11
  [<Error Code Number>, <Error Message String>, <Error Details Object>]
12
12
  */
13
- module.exports = ({count, err, height, start}) => {
14
- const [, cause, details] = err;
13
+ module.exports = args => {
14
+ const [, cause, details] = args.err;
15
15
  const {code} = details || {};
16
16
 
17
17
  return [
18
18
  503,
19
19
  'UnknownIfBlocksWereGenerated',
20
- {cause, code, count, height, start},
20
+ {
21
+ cause,
22
+ code,
23
+ count: args.count,
24
+ height: args.height,
25
+ start: args.start,
26
+ },
21
27
  ];
22
28
  };
@@ -1,5 +1,6 @@
1
1
  const asyncAuto = require('async/auto');
2
2
  const asyncEach = require('async/each');
3
+ const asyncify = require('async/asyncify');
3
4
  const asyncMapSeries = require('async/mapSeries');
4
5
  const asyncRetry = require('async/retry');
5
6
  const {authenticatedLndGrpc} = require('lightning');
@@ -89,56 +90,68 @@ module.exports = (args, cbk) => {
89
90
  return stopNodes(started(spawned), () => cbk(failure.reason));
90
91
  }
91
92
 
92
- return cbk(null, started(spawned).map(lightningDocker => {
93
- const id = lightningDocker.public_key;
93
+ return cbk(null, started(spawned));
94
+ });
95
+ },
96
+ cbk);
97
+ }],
94
98
 
99
+ // Make an LND API object for each node, which throws for bad details
100
+ lnds: ['spawn', asyncify(({spawn}) => {
101
+ return spawn.map(lightningDocker => {
102
+ return authenticatedLndGrpc({
103
+ cert: lightningDocker.cert,
104
+ macaroon: lightningDocker.macaroon,
105
+ socket: lightningDocker.socket,
106
+ }).lnd;
107
+ });
108
+ })],
109
+
110
+ // Describe each node of the cluster
111
+ cluster: ['lnds', 'spawn', ({lnds, spawn}, cbk) => {
112
+ return cbk(null, spawn.map((lightningDocker, i) => {
113
+ const id = lightningDocker.public_key;
114
+ const lnd = lnds[i];
115
+
116
+ return {
117
+ id,
118
+ lnd,
119
+ chain: {
120
+ addPeer: lightningDocker.add_chain_peer,
121
+ generateToAddress: lightningDocker.generate,
122
+ getBlockInfo: lightningDocker.get_block_info,
123
+ socket: lightningDocker.chain_socket,
124
+ },
125
+ generate: (args, cbk) => {
126
+ return generateBlocks({
127
+ lnd,
128
+ address: args.address,
129
+ count: args.count,
130
+ generate: lightningDocker.generate,
131
+ },
132
+ cbk);
133
+ },
134
+ kill: lightningDocker.kill,
135
+ public_key: id,
136
+ // Making the connection throws for a macaroon that is not valid
137
+ rpc: args => {
95
138
  const {lnd} = authenticatedLndGrpc({
96
139
  cert: lightningDocker.cert,
97
- macaroon: lightningDocker.macaroon,
140
+ macaroon: args.macaroon,
98
141
  socket: lightningDocker.socket,
99
142
  });
100
143
 
101
- return {
102
- id,
103
- lnd,
104
- chain: {
105
- addPeer: lightningDocker.add_chain_peer,
106
- generateToAddress: lightningDocker.generate,
107
- getBlockInfo: lightningDocker.get_block_info,
108
- socket: lightningDocker.chain_socket,
109
- },
110
- generate: ({address, count}, cbk) => {
111
- return generateBlocks({
112
- address,
113
- count,
114
- lnd,
115
- generate: lightningDocker.generate,
116
- },
117
- cbk);
118
- },
119
- kill: lightningDocker.kill,
120
- public_key: id,
121
- rpc: ({macaroon}) => {
122
- const {lnd} = authenticatedLndGrpc({
123
- macaroon,
124
- cert: lightningDocker.cert,
125
- socket: lightningDocker.socket,
126
- });
127
-
128
- return {lnd};
129
- },
130
- socket: lightningDocker.ln_socket,
131
- tower: lightningDocker.tower_socket,
132
- };
133
- }));
134
- });
135
- },
136
- cbk);
144
+ return {lnd};
145
+ },
146
+ socket: lightningDocker.ln_socket,
147
+ tower: lightningDocker.tower_socket,
148
+ };
149
+ }));
137
150
  }],
138
151
 
139
152
  // Connect nodes in the cluster to each other
140
- connect: ['spawn', ({spawn}, cbk) => {
141
- return asyncEach(pairs(spawn), (pair, cbk) => {
153
+ connect: ['cluster', ({cluster}, cbk) => {
154
+ return asyncEach(pairs(cluster), (pair, cbk) => {
142
155
  const [a, b] = pair.map(({chain}) => chain);
143
156
 
144
157
  return a.addPeer({socket: b.socket}).then(() => cbk(), cbk);
@@ -147,18 +160,18 @@ module.exports = (args, cbk) => {
147
160
  }],
148
161
 
149
162
  // Open channels between neighboring nodes, one at a time
150
- channels: ['connect', 'spawn', ({spawn}, cbk) => {
163
+ channels: ['cluster', 'connect', ({cluster}, cbk) => {
151
164
  // Exit early when there is no channel capacity to create channels
152
165
  if (!args.capacity) {
153
166
  return cbk(null, []);
154
167
  }
155
168
 
156
- return asyncMapSeries(line(spawn), ([from, to], cbk) => {
169
+ return asyncMapSeries(line(cluster), ([from, to], cbk) => {
157
170
  return setupChannel({
158
171
  capacity: args.capacity,
159
- generate: spawn[from].generate,
160
- lnd: spawn[from].lnd,
161
- to: spawn[to],
172
+ generate: cluster[from].generate,
173
+ lnd: cluster[from].lnd,
174
+ to: cluster[to],
162
175
  },
163
176
  (err, res) => {
164
177
  if (!!err) {
@@ -178,11 +191,11 @@ module.exports = (args, cbk) => {
178
191
  }],
179
192
 
180
193
  // Final set of nodes
181
- nodes: ['channels', 'connect', 'spawn', ({channels, spawn}, cbk) => {
194
+ nodes: ['channels', 'cluster', ({channels, cluster}, cbk) => {
182
195
  return cbk(null, {
183
196
  channels,
184
- kill: ({}) => asyncEach(spawn, ({kill}, cbk) => kill({}, cbk)),
185
- nodes: spawn.map(node => ({
197
+ kill: ({}) => asyncEach(cluster, ({kill}, cbk) => kill({}, cbk)),
198
+ nodes: cluster.map(node => ({
186
199
  generate: node.generate,
187
200
  id: node.id,
188
201
  kill: node.kill,
@@ -21,11 +21,11 @@ const typeOffset = 156;
21
21
  [file]: <File Buffer Object>
22
22
  }
23
23
  */
24
- module.exports = ({tar}) => {
24
+ module.exports = args => {
25
25
  let offset = 0;
26
26
 
27
- while (offset + blockSize <= tar.length) {
28
- const header = tar.subarray(offset, offset + blockSize);
27
+ while (offset + blockSize <= args.tar.length) {
28
+ const header = args.tar.subarray(offset, offset + blockSize);
29
29
 
30
30
  // Exit early when hitting the end of archive marker
31
31
  if (header.every(isZero)) {
@@ -37,7 +37,7 @@ module.exports = ({tar}) => {
37
37
 
38
38
  // Exit early when this is a regular entry
39
39
  if (!metaTypes.includes(fromCharCode(header[typeOffset]))) {
40
- return {file: tar.subarray(start, start + size)};
40
+ return {file: args.tar.subarray(start, start + size)};
41
41
  }
42
42
 
43
43
  offset = start + ceil(size / blockSize) * blockSize;
@@ -17,16 +17,16 @@ const {concat} = Buffer;
17
17
  file: <File Buffer Object>
18
18
  }
19
19
  */
20
- module.exports = ({container, path}, cbk) => {
20
+ module.exports = (args, cbk) => {
21
21
  return new Promise((resolve, reject) => {
22
22
  return asyncAuto({
23
23
  // Check arguments
24
24
  validate: cbk => {
25
- if (!container) {
25
+ if (!args.container) {
26
26
  return cbk([400, 'ExpectedContainerToGetFileFromDockerContainer']);
27
27
  }
28
28
 
29
- if (!path) {
29
+ if (!args.path) {
30
30
  return cbk([400, 'ExpectedFilePathToGetFileFromDockerContainer']);
31
31
  }
32
32
 
@@ -35,7 +35,7 @@ module.exports = ({container, path}, cbk) => {
35
35
 
36
36
  // Get archive
37
37
  getArchive: ['validate', ({}, cbk) => {
38
- return container.getArchive({path}, (err, stream) => {
38
+ return args.container.getArchive({path: args.path}, (err, stream) => {
39
39
  // Exit early when there are no files at the path
40
40
  if (!!err && err.statusCode === 404) {
41
41
  return cbk([404, 'FailedToFindFileAtPathInContainer']);
@@ -12,12 +12,12 @@ const t = 1;
12
12
 
13
13
  @returns via cbk or Promise
14
14
  */
15
- module.exports = ({container}, cbk) => {
15
+ module.exports = (args, cbk) => {
16
16
  return new Promise((resolve, reject) => {
17
17
  return asyncAuto({
18
18
  // Check arguments
19
19
  validate: cbk => {
20
- if (!container) {
20
+ if (!args.container) {
21
21
  return cbk([400, 'ExpectedContainerToKillContainer']);
22
22
  }
23
23
 
@@ -26,7 +26,7 @@ module.exports = ({container}, cbk) => {
26
26
 
27
27
  // Stop the running image
28
28
  stop: ['validate', ({}, cbk) => {
29
- return container.stop({t}, err => {
29
+ return args.container.stop({t}, err => {
30
30
  if (!!err && err.reason === errorAlreadyStopped) {
31
31
  return cbk();
32
32
  }
@@ -45,7 +45,7 @@ module.exports = ({container}, cbk) => {
45
45
 
46
46
  // Remove the container
47
47
  remove: ['stop', ({}, cbk) => {
48
- return container.remove(err => {
48
+ return args.container.remove(err => {
49
49
  // Exit early when the container is already gone
50
50
  if (!!err && err.statusCode === 404) {
51
51
  return cbk();
@@ -14,12 +14,12 @@ const {isArray} = Array;
14
14
 
15
15
  @returns via cbk or Promise
16
16
  */
17
- module.exports = ({dockers}, cbk) => {
17
+ module.exports = (args, cbk) => {
18
18
  return new Promise((resolve, reject) => {
19
19
  return asyncAuto({
20
20
  // Check arguments
21
21
  validate: cbk => {
22
- if (!isArray(dockers)) {
22
+ if (!isArray(args.dockers)) {
23
23
  return cbk([400, 'ExpectedArrayOfDockersToKill']);
24
24
  }
25
25
 
@@ -28,7 +28,10 @@ module.exports = ({dockers}, cbk) => {
28
28
 
29
29
  // Kill the dockers
30
30
  kill: ['validate', ({}, cbk) => {
31
- return asyncEach(dockers, (docker, cbk) => docker.kill({}, cbk), cbk);
31
+ return asyncEach(args.dockers, (docker, cbk) => {
32
+ return docker.kill({}, cbk);
33
+ },
34
+ cbk);
32
35
  }],
33
36
  },
34
37
  returnResult({reject, resolve}, cbk));
@@ -0,0 +1,69 @@
1
+ const blockSize = 512;
2
+ const {byteLength} = Buffer;
3
+ const {ceil} = Math;
4
+ const checksumOffset = 148;
5
+ const {concat} = Buffer;
6
+ const fileMode = '0000644\0';
7
+ const maxPathLength = 100;
8
+ const modeOffset = 100;
9
+ const mtimeOffset = 136;
10
+ const octal = (n, digits) => `${n.toString(8).padStart(digits, '0')}\0`;
11
+ const regularFileType = '0';
12
+ const relativePath = path => path.replace(/^\/+/, '');
13
+ const sizeOffset = 124;
14
+ const typeOffset = 156;
15
+ const ustarMagic = 'ustar\x0000';
16
+ const ustarOffset = 257;
17
+
18
+ /** Make a tar archive of files, to copy them into a container
19
+
20
+ {
21
+ files: [{
22
+ data: <File Contents Buffer Object>
23
+ path: <File Path String>
24
+ }]
25
+ }
26
+
27
+ @throws
28
+ <Error>
29
+
30
+ @returns
31
+ {
32
+ tar: <Tar Archive Buffer Object>
33
+ }
34
+ */
35
+ module.exports = args => {
36
+ const entries = args.files.map(({data, path}) => {
37
+ // Paths are relative to the directory the archive is copied into
38
+ const entryPath = relativePath(path);
39
+
40
+ // Paths are written as UTF-8, so their size is counted in bytes
41
+ if (!entryPath || byteLength(entryPath) > maxPathLength) {
42
+ throw new Error('ExpectedFilePathOfAtMost100BytesForTarArchive');
43
+ }
44
+
45
+ const header = Buffer.alloc(blockSize);
46
+ const padded = Buffer.alloc(ceil(data.length / blockSize) * blockSize);
47
+
48
+ header.write(entryPath, 0, 'utf8');
49
+ header.write(fileMode, modeOffset, 'ascii');
50
+ header.write(octal(data.length, 11), sizeOffset, 'ascii');
51
+ header.write(octal(0, 11), mtimeOffset, 'ascii');
52
+ header.write(regularFileType, typeOffset, 'ascii');
53
+ header.write(ustarMagic, ustarOffset, 'ascii');
54
+
55
+ // The checksum is summed with spaces in place of the checksum
56
+ header.fill(' ', checksumOffset, checksumOffset + 8);
57
+
58
+ const checksum = header.reduce((sum, byte) => sum + byte, 0);
59
+
60
+ header.write(octal(checksum, 6), checksumOffset, 'ascii');
61
+
62
+ data.copy(padded);
63
+
64
+ return concat([header, padded]);
65
+ });
66
+
67
+ // An archive ends with two blocks of zeros
68
+ return {tar: concat(entries.concat(Buffer.alloc(blockSize * 2)))};
69
+ };
@@ -1,13 +1,19 @@
1
1
  const asyncAuto = require('async/auto');
2
+ const asyncify = require('async/asyncify');
2
3
  const asyncRetry = require('async/retry');
3
4
  const Dockerode = require('dockerode');
4
5
  const {returnResult} = require('asyncjs-util');
5
6
 
6
7
  const getFile = require('./get_file');
7
8
  const killDocker = require('./kill_docker');
9
+ const makeTar = require('./make_tar');
8
10
 
11
+ const copyPath = '/';
9
12
  const {isArray} = Array;
13
+ const isFile = n => !!n && Buffer.isBuffer(n.data) && isString(n.path);
14
+ const isString = n => typeof n === 'string';
10
15
  const {keys} = Object;
16
+ const localhostIp = '127.0.0.1';
11
17
  const stopAfterRuntimeSeconds = 60;
12
18
 
13
19
  /** Spawn a new docker image
@@ -17,6 +23,10 @@ const stopAfterRuntimeSeconds = 60;
17
23
  {
18
24
  arguments: [<Command Arguments String>]
19
25
  [expose]: [<Expose Port String>]
26
+ [files]: [{
27
+ data: <File Contents Buffer Object>
28
+ path: <Absolute Path in Container String>
29
+ }]
20
30
  image: <Image Name String>
21
31
  ports: {
22
32
  <Internal Port String>: <External Port Number>
@@ -33,24 +43,32 @@ const stopAfterRuntimeSeconds = 60;
33
43
  }
34
44
  }
35
45
  */
36
- module.exports = ({arguments, expose, image, ports}, cbk) => {
46
+ module.exports = (args, cbk) => {
37
47
  return new Promise((resolve, reject) => {
38
48
  return asyncAuto({
39
49
  // Check arguments
40
50
  validate: cbk => {
41
- if (!isArray(arguments)) {
51
+ if (!isArray(args.arguments)) {
42
52
  return cbk([400, 'ExpectedArgumentsListToSpawnDockerImage']);
43
53
  }
44
54
 
45
- if (!!expose && !isArray(expose)) {
55
+ if (!!args.expose && !isArray(args.expose)) {
46
56
  return cbk([400, 'ExpectedExposedPortsArrayToSpawnDockerImage']);
47
57
  }
48
58
 
49
- if (!image) {
59
+ if (!!args.files && !isArray(args.files)) {
60
+ return cbk([400, 'ExpectedArrayOfFilesToSpawnDockerImage']);
61
+ }
62
+
63
+ if (!!args.files && args.files.some(n => !isFile(n))) {
64
+ return cbk([400, 'ExpectedFileDataAndPathToSpawnDockerImage']);
65
+ }
66
+
67
+ if (!args.image) {
50
68
  return cbk([400, 'ExpectedImageRepoNameToSpawnDockerImage']);
51
69
  }
52
70
 
53
- if (!ports) {
71
+ if (!args.ports) {
54
72
  return cbk([400, 'ExpectedPortBindingsToSpawnDockerImage']);
55
73
  }
56
74
 
@@ -62,7 +80,7 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
62
80
 
63
81
  // Check if the image is cached
64
82
  getImage: ['docker', ({docker}, cbk) => {
65
- return docker.getImage(image).inspect((err, res) => {
83
+ return docker.getImage(args.image).inspect((err, res) => {
66
84
  // Exit early when the image is not cached
67
85
  if (!!err && err.statusCode === 404) {
68
86
  return cbk();
@@ -87,7 +105,7 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
87
105
  return cbk();
88
106
  }
89
107
 
90
- return docker.pull(image, (err, stream) => {
108
+ return docker.pull(args.image, (err, stream) => {
91
109
  if (!!err) {
92
110
  return cbk([503, 'FailedToPullImageToSpawnDockerImage', {err}]);
93
111
  }
@@ -102,11 +120,11 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
102
120
  });
103
121
  }],
104
122
 
105
- // Create the container
106
- container: ['docker', 'pull', ({docker}, cbk) => {
123
+ // Create the container after archiving, so a throw leaves no container
124
+ container: ['archive', 'docker', 'pull', ({docker}, cbk) => {
107
125
  return docker.createContainer({
108
- Cmd: arguments,
109
- ExposedPorts: (expose || []).reduce((sum, port) => {
126
+ Cmd: args.arguments,
127
+ ExposedPorts: (args.expose || []).reduce((sum, port) => {
110
128
  sum[port.toString()] = {};
111
129
 
112
130
  return sum;
@@ -114,15 +132,21 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
114
132
  {}),
115
133
  HostConfig: {
116
134
  AutoRemove: true,
117
- PortBindings: keys(ports).reduce((sum, port) => {
118
- // Docker picks a free host port when none is specified
119
- sum[port] = [{HostPort: !ports[port] ? '' : `${ports[port]}`}];
135
+ PortBindings: keys(args.ports).reduce((sum, port) => {
136
+ const hostPort = args.ports[port];
137
+
138
+ // Ports are published on localhost only, not other interfaces
139
+ sum[port] = [{
140
+ HostIp: localhostIp,
141
+ // Docker picks a free host port when none is specified
142
+ HostPort: !hostPort ? '' : `${hostPort}`,
143
+ }];
120
144
 
121
145
  return sum;
122
146
  },
123
147
  {}),
124
148
  },
125
- Image: image,
149
+ Image: args.image,
126
150
  StopTimeout: stopAfterRuntimeSeconds,
127
151
  },
128
152
  (err, container) => {
@@ -134,8 +158,40 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
134
158
  });
135
159
  }],
136
160
 
161
+ // Archive the files to copy in, which checks that their paths fit
162
+ archive: ['validate', asyncify(({}) => {
163
+ // Exit early when there are no files to copy
164
+ if (!args.files || !args.files.length) {
165
+ return;
166
+ }
167
+
168
+ return makeTar({files: args.files}).tar;
169
+ })],
170
+
171
+ // Copy files into the container before it starts
172
+ copy: ['archive', 'container', ({archive, container}, cbk) => {
173
+ // Exit early when there are no files to copy
174
+ if (!archive) {
175
+ return cbk();
176
+ }
177
+
178
+ return container.putArchive(archive, {path: copyPath}, err => {
179
+ // Exit early when the files were copied
180
+ if (!err) {
181
+ return cbk();
182
+ }
183
+
184
+ // Remove the container so a failed copy does not leave it behind
185
+ return container.remove({force: true}, () => cbk([
186
+ 503,
187
+ 'UnexpectedErrorCopyingFilesToDockerContainer',
188
+ {err},
189
+ ]));
190
+ });
191
+ }],
192
+
137
193
  // Start the image
138
- start: ['container', 'docker', ({container, docker}, cbk) => {
194
+ start: ['container', 'copy', ({container}, cbk) => {
139
195
  return asyncRetry({}, cbk => {
140
196
  return container.start(err => {
141
197
  if (!!err) {
@@ -182,9 +238,11 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
182
238
 
183
239
  return cbk(null, {
184
240
  host,
185
- getFile: ({path}, cbk) => getFile({container, path}, cbk),
241
+ getFile: (args, cbk) => {
242
+ return getFile({container, path: args.path}, cbk);
243
+ },
186
244
  kill: ({}, cbk) => killDocker({container}, cbk),
187
- ports: keys(ports).reduce((sum, port) => {
245
+ ports: keys(args.ports).reduce((sum, port) => {
188
246
  const [binding] = published[port] || [];
189
247
 
190
248
  sum[port] = !binding ? undefined : Number(binding.HostPort);
package/index.js CHANGED
@@ -3,6 +3,7 @@ const {spawnBitcoindDocker} = require('./bitcoind');
3
3
  const {spawnLightningCluster} = require('./cluster');
4
4
  const {spawnLightningDocker} = require('./lnd');
5
5
  const {spawnLndDocker} = require('./lnd');
6
+ const {spawnLoopServerDocker} = require('./loop');
6
7
 
7
8
  module.exports = {
8
9
  setupChannel,
@@ -10,4 +11,5 @@ module.exports = {
10
11
  spawnLightningCluster,
11
12
  spawnLightningDocker,
12
13
  spawnLndDocker,
14
+ spawnLoopServerDocker,
13
15
  };