presidium 0.16.2 → 0.16.3

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/Docker.js CHANGED
@@ -16,6 +16,7 @@ const join = require('./internal/join')
16
16
  const isArray = require('./internal/isArray')
17
17
  const pathJoin = require('./internal/pathJoin')
18
18
  const has = require('./internal/has')
19
+ const filterExists = require('./internal/filterExists')
19
20
 
20
21
  const {
21
22
  pipe, tap,
@@ -776,6 +777,8 @@ Docker.prototype.updateSwarm = async function dockerUpdateSwarm(options = {}) {
776
777
  * rollbackMonitor: 15e9|number, // ns after each task rollback to monitor for failure
777
778
  * rollbackMaxFailureRatio: 0.15|number, // failure rate to tolerate during a rollback
778
779
  *
780
+ * network?: string, // name or id of network to attach service
781
+ *
779
782
  * cmd: Array<string|number>, // CMD
780
783
  * workdir: path string, // WORKDIR
781
784
  * env: {
@@ -874,6 +877,7 @@ Docker.prototype.createService = function dockerCreateService(service, options)
874
877
  Monitor: get('updateMonitor', 15e9),
875
878
  MaxFailureRatio: get('updateMaxFailureRatio', 0.15),
876
879
  })(options),
880
+
877
881
  RollbackConfig: fork({
878
882
  Parallelism: get('rollbackParallelism', 1),
879
883
  Delay: get('rollbackDelay', 1e9),
@@ -882,6 +886,14 @@ Docker.prototype.createService = function dockerCreateService(service, options)
882
886
  MaxFailureRatio: get('rollbackMaxFailureRatio', 0.15),
883
887
  })(options),
884
888
 
889
+ ...options.network && {
890
+ Networks: [{
891
+ Target: options.network,
892
+ Aliases: [],
893
+ DriverOpts: {},
894
+ }],
895
+ },
896
+
885
897
  ...options.publish && {
886
898
  EndpointSpec: {
887
899
  Ports: Object.entries(options.publish).map(pipe([
@@ -1233,6 +1245,18 @@ Docker.prototype.listNodes = async function listNodes() {
1233
1245
  return this.http.get('/nodes')
1234
1246
  }
1235
1247
 
1248
+ /**
1249
+ * @name Docker.prototype.deleteNode
1250
+ *
1251
+ * @synopsis
1252
+ * ```coffeescript [specscript]
1253
+ * new Docker().deleteNode(id string) -> Promise<HttpResponse>
1254
+ * ```
1255
+ */
1256
+ Docker.prototype.deleteNode = function deleteNode(id) {
1257
+ return this.http.delete(`/nodes/${id}`)
1258
+ }
1259
+
1236
1260
  /**
1237
1261
  * @name Docker.prototype.pruneImages
1238
1262
  *
@@ -1269,6 +1293,30 @@ Docker.prototype.pruneVolumes = function dockerPruneVolumes() {
1269
1293
  return this.http.post('/volumes/prune')
1270
1294
  }
1271
1295
 
1296
+ /**
1297
+ * @name Docker.prototype.createNetwork
1298
+ *
1299
+ * @synopsis
1300
+ * ```coffeescript [specscript]
1301
+ * new Docker().createNetwork(options {
1302
+ * name: string, // name of the network
1303
+ * driver?: 'bridge'|'host'|'overlay'|'ipvlan'|'macvlan', // default 'bridge'
1304
+ * }) -> Promise<HttpResponse>
1305
+ * ```
1306
+ */
1307
+ Docker.prototype.createNetwork = function createNetwork(options) {
1308
+ return this.http.post('/networks/create', {
1309
+ headers: {
1310
+ 'Content-Type': 'application/json',
1311
+ },
1312
+ body: JSON.stringify(filterExists({
1313
+ Name: options.name,
1314
+ Driver: options.driver,
1315
+ CheckDuplicate: true,
1316
+ })),
1317
+ })
1318
+ }
1319
+
1272
1320
  /**
1273
1321
  * @name Docker.prototype.pruneNetworks
1274
1322
  *
package/Docker.test.js CHANGED
@@ -284,6 +284,13 @@ EXPOSE 8888`,
284
284
  assert.equal(response.status, 200)
285
285
  const nodes = await response.json()
286
286
  assert.equal(nodes.length, 1) // just this computer
287
+ this.nodeId = nodes[0].ID
288
+ }
289
+
290
+ { // attempt deleteNode
291
+ const response = await docker.deleteNode(this.nodeId)
292
+ assert.equal(response.status, 400)
293
+ console.log(await response.text())
287
294
  }
288
295
 
289
296
  { // inspectSwarm
@@ -295,6 +302,14 @@ EXPOSE 8888`,
295
302
  this.workerJoinToken = body.JoinTokens.Worker
296
303
  }
297
304
 
305
+ { // create a network
306
+ const response = await docker.createNetwork({
307
+ name: 'my-network',
308
+ driver: 'overlay',
309
+ })
310
+ assert.equal(response.status, 201)
311
+ }
312
+
298
313
  { // create a service
299
314
  const response = await docker.createService('hey1', {
300
315
  image: 'node:15-alpine',
@@ -326,6 +341,7 @@ EXPOSE 8888`,
326
341
  'max-file': '10',
327
342
  'max-size': '100m',
328
343
  },
344
+ network: 'my-network',
329
345
  })
330
346
  assert.equal(response.status, 201)
331
347
  const body = await response.json()
package/DockerService.js CHANGED
@@ -36,6 +36,7 @@ const dockerServiceOptions = [
36
36
  'rollbackParallelism', 'rollbackDelay',
37
37
  'rollbackFailureAction', 'rollbackMonitor', 'rollbackMaxFailureRatio',
38
38
  'username', 'password', 'email', 'serveraddress', 'identitytoken',
39
+ 'network',
39
40
  ]
40
41
 
41
42
  /**
@@ -75,6 +76,8 @@ const dockerServiceOptions = [
75
76
  * rollbackMonitor: 15e9|number, // ns after each task rollback to monitor for failure
76
77
  * rollbackMaxFailureRatio: 0.15|number, // failure rate to tolerate during a rollback
77
78
  *
79
+ * network?: string, // name or id of network to attach service
80
+ *
78
81
  * cmd: Array<string|number>, // CMD
79
82
  * workdir: path string, // WORKDIR
80
83
  * env: {
@@ -108,6 +111,8 @@ const DockerService = function (options) {
108
111
  this.docker = new Docker()
109
112
  this.version = null
110
113
  this.spec = null
114
+ this.replicas = options.replicas
115
+
111
116
  this.ready = this.docker.inspectService(this.name).then(pipe([
112
117
  switchCase([
113
118
  eq(404, get('status')),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",