presidium 0.17.0 → 0.18.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/DockerSwarm.js CHANGED
@@ -1,81 +1,63 @@
1
- const assert = require('assert')
2
- const rubico = require('rubico')
1
+ require('rubico/global')
3
2
  const Docker = require('./Docker')
4
3
 
5
- const {
6
- pipe, tap,
7
- switchCase, tryCatch,
8
- fork, assign, get, pick, omit,
9
- map, filter, reduce, transform, flatMap,
10
- and, or, not, any, all,
11
- eq, gt, lt, gte, lte,
12
- thunkify, always,
13
- curry, __,
14
- } = rubico
15
-
16
4
  /**
17
5
  * @name DockerSwarm
18
6
  *
19
7
  * @synopsis
20
8
  * ```coffeescript [specscript]
21
- * new DockerSwarm(
22
- * advertiseAddr string, // url advertised to other nodes, e.g. 'eth0:2377'
23
- * options {
24
- * joinToken: string, // worker or manager join token
25
- * remoteAddrs: Array<string>, // urls of manager nodes already participating in the swarm
26
- * },
27
- * ) -> DockerSwarm
9
+ * new DockerSwarm(advertiseAddr string) -> DockerSwarm
28
10
  * ```
11
+ *
12
+ * @description
13
+ * DockerSwarm interface
14
+ *
15
+ * ## Resources
16
+ * https://boxboat.com/2016/08/17/whats-docker-swarm-advertise-addr/
29
17
  */
30
- const DockerSwarm = function (advertiseAddr, options = {}) {
31
- if (this == null || this.constructor != DockerSwarm) {
32
- return new DockerSwarm(advertiseAddr, options)
33
- }
18
+ const DockerSwarm = function (advertiseAddr) {
19
+ this.advertiseAddr = advertiseAddr
34
20
  this.docker = new Docker()
35
- this.ready = this.docker.inspectSwarm().then(switchCase([
36
- or([
37
- eq(404, get('status')),
38
- eq(503, get('status')),
39
- ]),
40
- options.joinToken == null ? async () => {
41
- await this.docker.initSwarm(advertiseAddr)
42
- await this.synchronize()
43
- } : async () => {
44
- const response = await this.docker.joinSwarm(advertiseAddr, options.joinToken, {
45
- remoteAddrs: options.remoteAddrs,
46
- })
47
- if (!response.ok) {
48
- throw new Error(await response.text())
49
- }
50
- },
51
- async response => {
52
- const data = await response.json()
53
- this.version = data.Version.Index
54
- this.spec = data.Spec
55
- this.swarmData = data
56
- },
57
- ]))
58
- this.version = null
59
- this.spec = null
60
- this.swarmData = null
61
21
  return this
62
22
  }
63
23
 
64
- // new DockerSwarm().synchronize() -> Promise<>
65
- DockerSwarm.prototype.synchronize = function dockerServiceSynchronize() {
66
- return this.docker.inspectSwarm().then(pipe([
67
- tap(async response => {
68
- if (!response.ok) {
69
- throw new Error(await response.text())
70
- }
71
- }),
72
- response => response.json(),
73
- data => {
74
- this.version = data.Version.Index
75
- this.spec = data.Spec
76
- this.swarmData = data
77
- },
78
- ]))
24
+ /**
25
+ * @name DockerSwarm.prototype.init
26
+ *
27
+ * @synopsis
28
+ * ```coffeescript [specscript]
29
+ * new DockerSwarm(...).init() -> Promise<>
30
+ * ```
31
+ */
32
+ DockerSwarm.prototype.init = async function init() {
33
+ await this.docker.initSwarm(this.advertiseAddr).then(async response => {
34
+ if (!response.ok) {
35
+ throw new Error(await response.text())
36
+ }
37
+ })
38
+ }
39
+
40
+ /**
41
+ * @name DockerSwarm.prototype.join
42
+ *
43
+ * @synopsis
44
+ * ```coffeescript [specscript]
45
+ * new DockerSwarm(...).join(options {
46
+ * joinToken: string, // worker or manager join token
47
+ * remoteAddrs: Array<string>, // urls of manager nodes already participating in the swarm
48
+ * }) -> Promise<>
49
+ * ```
50
+ */
51
+
52
+ DockerSwarm.prototype.join = async function join(options) {
53
+ const { joinToken, remoteAddrs } = options
54
+ await this.docker.joinSwarm(this.advertiseAddr, joinToken, {
55
+ remoteAddrs,
56
+ }).then(async response => {
57
+ if (!response.ok) {
58
+ throw new Error(await response.text())
59
+ }
60
+ })
79
61
  }
80
62
 
81
63
  // DockerSwarm(address).inspect() -> Promise<Object>
@@ -113,19 +95,15 @@ DockerSwarm.prototype.leave = function dockerSwarmLeave(options) {
113
95
  * @description
114
96
  * https://docs.docker.com/engine/api/v1.40/#operation/SwarmUpdate
115
97
  * https://docs.docker.com/engine/reference/commandline/swarm_update/
116
- */
98
+ *
99
+ * @deprecated
117
100
  DockerSwarm.prototype.update = async function dockerSwarmUpdate(options) {
118
101
  await this.ready
119
102
  return this.docker.updateSwarm({
120
103
  version: this.version,
121
104
  spec: this.spec,
122
105
  ...options,
123
- }).then(pipe.sync([
124
- tap.sync(() => {
125
- this.ready = this.synchronize()
126
- }),
127
- always(this.spec),
128
- ]))
129
- }
106
+ })
107
+ } */
130
108
 
131
109
  module.exports = DockerSwarm
@@ -4,59 +4,27 @@ const Docker = require('./Docker')
4
4
  const DockerSwarm = require('./DockerSwarm')
5
5
  const inspect = require('util').inspect
6
6
 
7
- module.exports = Test('DockerSwarm', DockerSwarm)
8
- .before(async function () {
9
- this.docker = new Docker()
10
- await this.docker.leaveSwarm({ force: true })
11
- })
12
- .case('[::1]:2377', async function (localSwarm) {
13
- assert(localSwarm.spec == null)
14
- assert(localSwarm.version == null)
15
- await localSwarm.ready
16
- assert(localSwarm.spec != null)
17
- assert(localSwarm.version != null)
7
+ const test = Test('DockerSwarm', async function () {
8
+ this.docker = new Docker()
9
+ await this.docker.leaveSwarm({ force: true })
18
10
 
19
- {
20
- const prevTokens = (await localSwarm.inspect()).JoinTokens
21
- const result = await localSwarm.update({
22
- rotateWorkerToken: true,
23
- rotateManagerToken: true,
24
- rotateManagerUnlockKey: true,
25
- autolock: true,
26
- })
11
+ const advertiseAddr = '[::1]:2377'
12
+ const localSwarm = new DockerSwarm(advertiseAddr)
27
13
 
28
- assert.strictEqual(localSwarm.spec.EncryptionConfig.AutoLockManagers, false)
29
- await localSwarm.ready
30
- assert.strictEqual(localSwarm.spec.EncryptionConfig.AutoLockManagers, true)
31
- const newTokens = (await localSwarm.inspect()).JoinTokens
32
- assert(prevTokens.Worker != newTokens.Worker)
33
- assert(prevTokens.Manager != newTokens.Manager)
34
- }
14
+ console.log('initializing swarm')
15
+ await localSwarm.init()
35
16
 
36
- {
37
- const result = await localSwarm.update({
38
- snapshotInterval: 20000,
39
- keepOldSnapshots: 3,
40
- logEntriesForSlowFollowers: 1000,
41
- electionTick: 20,
42
- heartbeatTick: 2,
43
- })
17
+ await localSwarm.inspect().then(console.log)
44
18
 
45
- assert.strictEqual(localSwarm.spec.Raft.SnapshotInterval, 10000)
46
- assert.strictEqual(localSwarm.spec.Raft.KeepOldSnapshots, 0)
47
- assert.strictEqual(localSwarm.spec.Raft.LogEntriesForSlowFollowers, 500)
48
- assert.strictEqual(localSwarm.spec.Raft.ElectionTick, 10)
49
- assert.strictEqual(localSwarm.spec.Raft.HeartbeatTick, 1)
50
- await localSwarm.ready
51
- assert.strictEqual(localSwarm.spec.Raft.SnapshotInterval, 20000)
52
- assert.strictEqual(localSwarm.spec.Raft.KeepOldSnapshots, 3)
53
- assert.strictEqual(localSwarm.spec.Raft.LogEntriesForSlowFollowers, 1000)
54
- assert.strictEqual(localSwarm.spec.Raft.ElectionTick, 20)
55
- assert.strictEqual(localSwarm.spec.Raft.HeartbeatTick, 2)
56
- }
19
+ {
20
+ console.log('leaving swarm')
21
+ const result = await localSwarm.leave({ force: true })
22
+ assert.deepEqual(result, { message: '' })
23
+ }
24
+ }).case()
57
25
 
58
- {
59
- const result = await localSwarm.leave({ force: true })
60
- assert.deepEqual(result, { message: '' })
61
- }
62
- })
26
+ if (process.argv[1] == __filename) {
27
+ test()
28
+ }
29
+
30
+ module.exports = test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",