presidium 0.26.5 → 0.26.7

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/Archive.test.js CHANGED
@@ -36,7 +36,7 @@ const test = new Test('Archive', Archive)
36
36
  })
37
37
 
38
38
  .case({
39
- Dockerfile: 'FROM busybox:1.32'
39
+ Dockerfile: 'FROM busybox:1.32',
40
40
  '.aws/credentials': '[claimyr]\naccessKeyId\nsecretAccessKey',
41
41
  }, async archive => {
42
42
  const pack = await archive.tar(`${pathResolve(__dirname, 'internal')}/`, {
package/Dependency.js ADDED
@@ -0,0 +1,44 @@
1
+ const DynamoTable = require('./DynamoTable')
2
+ const DynamoStream = require('./DynamoStream')
3
+ const ElasticsearchIndex = require('./ElasticsearchIndex')
4
+ const S3Bucket = require('./S3Bucket')
5
+ const KinesisStream = require('./KinesisStream')
6
+
7
+ const Dependency = {}
8
+
9
+ /**
10
+ * @name Dependency.teardown
11
+ *
12
+ * @synopsis
13
+ * ```coffeescript [specscript]
14
+ * teardown(
15
+ * dependency DynamoTable|DynamoStream
16
+ * |ElasticsearchIndex|S3Bucket
17
+ * |KinesisStream
18
+ * ) -> Promise<>
19
+ * ```
20
+ */
21
+ Dependency.teardown = async function teardown(dependency) {
22
+ if (dependency == null) {
23
+ // noop
24
+ }
25
+ else if (dependency.constructor == DynamoTable) {
26
+ await dependency.delete()
27
+ }
28
+ else if (dependency.constructor == DynamoStream) {
29
+ dependency.close()
30
+ }
31
+ else if (dependency.constructor == ElasticsearchIndex) {
32
+ await dependency.delete()
33
+ }
34
+ else if (dependency.constructor == S3Bucket) {
35
+ await dependency.deleteAllObjects()
36
+ await dependency.delete()
37
+ }
38
+ else if (dependency.constructor == KinesisStream) {
39
+ dependency.close()
40
+ await dependency.delete()
41
+ }
42
+ }
43
+
44
+ module.exports = Dependency
@@ -0,0 +1,63 @@
1
+ const Test = require('thunk-test')
2
+ const DynamoTable = require('./DynamoTable')
3
+ const DynamoStream = require('./DynamoStream')
4
+ const ElasticsearchIndex = require('./ElasticsearchIndex')
5
+ const S3Bucket = require('./S3Bucket')
6
+ const KinesisStream = require('./KinesisStream')
7
+ const Dependency = require('./Dependency')
8
+
9
+ const test = new Test('Dependency.teardown', async function () {
10
+ const myDynamoTable = new DynamoTable({
11
+ name: 'my_dynamo_table',
12
+ key: [{ a: 'string' }],
13
+ endpoint: 'http://localhost:8000',
14
+ region: 'dynamodblocal',
15
+ })
16
+ await myDynamoTable.ready
17
+
18
+ const myDynamoStream = new DynamoStream({
19
+ table: 'my_dynamo_table',
20
+ endpoint: 'http://localhost:8000',
21
+ region: 'dynamodblocal',
22
+ })
23
+ await myDynamoStream.ready
24
+
25
+ const myElasticsearchIndex = new ElasticsearchIndex({
26
+ node: 'http://localhost:9200/',
27
+ index: 'local_post',
28
+ mappings: {
29
+ a: { type: 'keyword' },
30
+ b: { type: 'keyword' },
31
+ },
32
+ })
33
+ await myElasticsearchIndex.ready
34
+
35
+ const myS3Bucket = new S3Bucket({
36
+ name: 'my-s3-bucket',
37
+ endpoint: 'http://localhost:9000',
38
+ region: 'us-west-1',
39
+ accessKeyId: 'minioadmin',
40
+ secretAccessKey: 'minioadmin',
41
+ })
42
+ await myS3Bucket.ready
43
+
44
+ const myKinesisStream = new KinesisStream({
45
+ name: 'my_kinesis_stream',
46
+ endpoint: 'http://localhost:4567',
47
+ shardIteratorType: 'TRIM_HORIZON',
48
+ })
49
+ await myKinesisStream.ready
50
+
51
+ await Dependency.teardown(null)
52
+ await Dependency.teardown(myDynamoTable)
53
+ await Dependency.teardown(myDynamoStream)
54
+ await Dependency.teardown(myElasticsearchIndex)
55
+ await Dependency.teardown(myS3Bucket)
56
+ await Dependency.teardown(myKinesisStream)
57
+ }).case()
58
+
59
+ if (process.argv[1] == __filename) {
60
+ test()
61
+ }
62
+
63
+ module.exports = test
package/Docker.js CHANGED
@@ -328,6 +328,7 @@ Docker.prototype.removeImage = function dockerRemoveImage(image, options) {
328
328
  * healthStartPeriod: >=1e6, // nanoseconds to wait on container init before starting first healthcheck
329
329
  * memory: number, // memory limit in bytes
330
330
  * cpus: number, // number of cpus
331
+ * gpus?: 'all', // expose gpus
331
332
  * mounts: Array<{
332
333
  * source: string, // name of volume
333
334
  * target: string, // mounted path inside container
@@ -468,6 +469,7 @@ Docker.prototype.createContainer = function dockerCreateContainer(
468
469
  })(options.restart.split(':')),
469
470
  },
470
471
  ...options.rm && { AutoRemove: options.rm },
472
+
471
473
  },
472
474
  }),
473
475
 
@@ -868,6 +870,15 @@ Docker.prototype.createService = function dockerCreateService(service, options)
868
870
  ...options.cpus ? {
869
871
  NanoCPUs: Number(options.cpus * 1e9),
870
872
  } : {},
873
+
874
+ ...options.gpus == 'all' ? {
875
+ GenericResources: [{
876
+ DiscreteResourceSpec: {
877
+ Kind: 'gpu',
878
+ Value: 1,
879
+ },
880
+ }],
881
+ } : {},
871
882
  }, // bytes
872
883
  },
873
884
 
package/Docker.test.js CHANGED
@@ -335,6 +335,7 @@ EXPOSE 8888`,
335
335
  }],
336
336
  memory: 512e6, // bytes
337
337
  cpus: 2,
338
+ gpus: 'all',
338
339
  restart: 'on-failure:5',
339
340
 
340
341
  healthCmd: ['wget', '--no-verbose', '--tries=1', '--spider', 'localhost:3000'],
@@ -364,6 +365,10 @@ EXPOSE 8888`,
364
365
  assert.equal(data.Spec.Labels.foo, 'bar')
365
366
  assert.equal(data.Spec.TaskTemplate.Resources.Reservations.NanoCPUs, 2000000000)
366
367
  assert.equal(data.Spec.TaskTemplate.Resources.Reservations.MemoryBytes, 512000000)
368
+ assert.equal(
369
+ data.Spec.TaskTemplate.Resources.Reservations.GenericResources[0].DiscreteResourceSpec.Kind,
370
+ 'gpu',
371
+ )
367
372
  })
368
373
 
369
374
  this.serviceId1 = serviceId
package/DockerService.js CHANGED
@@ -26,7 +26,7 @@ const dockerServiceOptions = [
26
26
  'rollbackParallelism', 'rollbackDelay',
27
27
  'rollbackFailureAction', 'rollbackMonitor', 'rollbackMaxFailureRatio',
28
28
  'username', 'password', 'email', 'serveraddress', 'identitytoken',
29
- 'network', 'memory', 'cpus',
29
+ 'network', 'memory', 'cpus', 'gpus',
30
30
  'force',
31
31
  ]
32
32
 
package/S3Bucket.js CHANGED
@@ -357,7 +357,12 @@ S3Bucket.prototype.getObjectStream = async function getObjectStream(
357
357
  */
358
358
  S3Bucket.prototype.listObjects = async function s3BucketListObjectsV2(options) {
359
359
  await this.ready
360
- return this.s3.listObjectsV2(this.name, options)
360
+ return this.s3.listObjectsV2(this.name, options).catch(error => {
361
+ if (error.retryable) {
362
+ return this.listObjects(options)
363
+ }
364
+ throw error
365
+ })
361
366
  }
362
367
 
363
368
  module.exports = S3Bucket
@@ -130,7 +130,7 @@ const createUpdateServiceSpec = function (options) {
130
130
  if (options.restartDelay != null) {
131
131
  result.TaskTemplate.RestartPolicy.Delay = Number(options.restartDelay)
132
132
  }
133
- if (or([has('memory'), has('cpus')])(options)) {
133
+ if (or(options, [has('memory'), has('cpus'), has('gpus')])) {
134
134
  result.TaskTemplate.Resources = {}
135
135
  result.TaskTemplate.Resources.Reservations = {}
136
136
  result.TaskTemplate.Resources.Limits = {}
@@ -147,6 +147,15 @@ const createUpdateServiceSpec = function (options) {
147
147
  result.TaskTemplate.Resources.Limits.NanoCPUs =
148
148
  Number(options.cpus * 1e9)
149
149
  }
150
+ if (options.gpus != null) {
151
+ result.TaskTemplate.Resources.Reservations.GenericResources = []
152
+ result.TaskTemplate.Resources.Reservations.GenericResources.push({
153
+ DiscreteResourceSpec: {
154
+ Kind: 'gpu',
155
+ Value: 1,
156
+ },
157
+ })
158
+ }
150
159
  if (or([has('logDriver'), has('logDriverOptions')])(options)) {
151
160
  result.TaskTemplate.LogDriver = {}
152
161
  }
@@ -241,6 +241,29 @@ const test = new Test('createUpdateServiceSpec', createUpdateServiceSpec)
241
241
  },
242
242
  })
243
243
 
244
+ .case({
245
+ serviceName: 'my-service',
246
+ spec: {
247
+ TaskTemplate: {},
248
+ },
249
+ gpus: 'all',
250
+ }, {
251
+ Name: 'my-service',
252
+ TaskTemplate: {
253
+ Resources: {
254
+ Limits: {},
255
+ Reservations: {
256
+ GenericResources: [{
257
+ DiscreteResourceSpec: {
258
+ Kind: 'gpu',
259
+ Value: 1,
260
+ },
261
+ }],
262
+ },
263
+ },
264
+ },
265
+ })
266
+
244
267
  .case({
245
268
  serviceName: 'my-service',
246
269
  spec: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.26.5",
3
+ "version": "0.26.7",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/teardown.test.js CHANGED
@@ -60,4 +60,4 @@ if (process.argv[1] == __filename) {
60
60
  test()
61
61
  }
62
62
 
63
- module.exports = teardown
63
+ module.exports = test