@toa.io/operations 0.4.0-dev.6 → 0.4.0-dev.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/operations",
3
- "version": "0.4.0-dev.6",
3
+ "version": "0.4.0-dev.9",
4
4
  "description": "Toa Deployment",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -26,9 +26,9 @@
26
26
  "test": "echo \"Error: run tests from root\" && exit 1"
27
27
  },
28
28
  "dependencies": {
29
- "@toa.io/filesystem": "0.4.0-dev.6",
30
- "@toa.io/generic": "0.4.0-dev.6",
31
- "@toa.io/yaml": "0.4.0-dev.6",
29
+ "@toa.io/filesystem": "0.4.0-dev.9",
30
+ "@toa.io/generic": "0.4.0-dev.9",
31
+ "@toa.io/yaml": "0.4.0-dev.9",
32
32
  "execa": "5.1.1"
33
33
  },
34
34
  "gitHead": "2be07592325b2e4dc823e81d882a4e50bf50de24"
@@ -11,7 +11,7 @@ const variables = (context, variables) => {
11
11
  if (context.environment !== undefined) {
12
12
  const variable = format('TOA_ENV', context.environment)
13
13
 
14
- variables.global.push(variable)
14
+ variables.global.unshift(variable)
15
15
  }
16
16
 
17
17
  return variables
@@ -13,10 +13,13 @@ const { merge, declare, describe } = require('./.deployment')
13
13
  class Deployment {
14
14
  /** @type {toa.deployment.Declaration} */
15
15
  #declaration
16
+
16
17
  /** @type {toa.deployment.Contents} */
17
18
  #contents
19
+
18
20
  /** @type {toa.operations.Process} */
19
21
  #process
22
+
20
23
  /** @type {string} */
21
24
  #target
22
25
 
@@ -29,8 +32,6 @@ class Deployment {
29
32
  constructor (context, compositions, dependencies, process) {
30
33
  const dependency = merge(dependencies)
31
34
 
32
- if (context.environment === 'local') throw new Error('Deployment environment name \'local\' is not allowed.')
33
-
34
35
  this.#declaration = declare(context, dependency)
35
36
  this.#contents = describe(context, compositions, dependency)
36
37
  this.#process = process
@@ -75,6 +76,10 @@ class Deployment {
75
76
  ['template', this.#declaration.name, ...args, this.#target],
76
77
  { silently: true })
77
78
  }
79
+
80
+ variables () {
81
+ return this.#contents.variables
82
+ }
78
83
  }
79
84
 
80
85
  const TEMPLATES = join(__dirname, 'chart/templates')
@@ -64,6 +64,10 @@ class Operator {
64
64
  return output
65
65
  }
66
66
 
67
+ variables () {
68
+ return this.#deployment.variables()
69
+ }
70
+
67
71
  /**
68
72
  * @param type {string}
69
73
  * @param [path] {string}
@@ -4,8 +4,30 @@ const { generate } = require('randomstring')
4
4
 
5
5
  const context = /** @type {toa.norm.Context} */ { name: generate() }
6
6
  const compositions = []
7
- const dependencies = []
7
+ /** @type {toa.deployment.Dependency[]} */
8
+
9
+ /** @type {toa.deployment.dependency.Variable} */
10
+ const bindingVariable = {
11
+ name: 'TOA_BINDINGS_AMQP_POINTER',
12
+ value: 'eyJkZWZhdWx0IjoiYW1xcDovL3doYXRldmVyIiwic3lzdGVtIjoiYW1xcDovL2hvc3QwIn0='
13
+ }
14
+
15
+ /** @type {toa.deployment.dependency.Variable} */
16
+ const secretVariable = {
17
+ name: 'TOA_BINDINGS_AMQP_DEFAULT_USERNAME',
18
+ secret: {
19
+ name: 'toa-bindings-amqp-default',
20
+ key: 'username'
21
+ }
22
+ }
23
+
24
+ /** @type {toa.deployment.Dependency[]} */
25
+ const dependencies = [{
26
+ variables: { global: [bindingVariable, secretVariable] }
27
+ }]
28
+
8
29
  const process = /** @type {toa.operations.Process} */ { execute: jest.fn() }
30
+
9
31
  const options = /** @type {toa.deployment.installation.Options} */ {
10
32
  namespace: generate(),
11
33
  target: generate()
@@ -16,3 +38,5 @@ exports.compositions = compositions
16
38
  exports.dependencies = dependencies
17
39
  exports.process = process
18
40
  exports.options = options
41
+ exports.bindingVariable = bindingVariable
42
+ exports.secretVariable = secretVariable
@@ -30,12 +30,49 @@ it('should pass -n argument if options.namespace is set', async () => {
30
30
  expect(namespace).toStrictEqual(fixtures.options.namespace)
31
31
  })
32
32
 
33
- it('should forbid local deployment environment', () => {
34
- const context = clone(fixtures.context)
33
+ describe('variables', () => {
34
+ let deployment /** @type {toa.deployment.Deployment} */
35
35
 
36
- context.environment = 'local'
36
+ it('should be define', () => {
37
+ const context = clone(fixtures.context)
37
38
 
38
- const create = () => new Deployment(context, fixtures.compositions, fixtures.dependencies, fixtures.process)
39
+ deployment = new Deployment(context, fixtures.compositions, fixtures.dependencies, fixtures.process)
39
40
 
40
- expect(create).toThrow(/name 'local' is not allowed/)
41
+ expect(typeof deployment.variables).toBe('function')
42
+ })
43
+
44
+ it('should return variables', () => {
45
+ const context = clone(fixtures.context)
46
+ const [{ variables }] = fixtures.dependencies
47
+
48
+ deployment = new Deployment(context, fixtures.compositions, fixtures.dependencies, fixtures.process)
49
+ expect(deployment.variables()).toEqual(variables)
50
+ })
51
+
52
+ it('should return variables', () => {
53
+ const context = clone(fixtures.context)
54
+ const [{ variables }] = fixtures.dependencies
55
+
56
+ deployment = new Deployment(context, fixtures.compositions, fixtures.dependencies, fixtures.process)
57
+
58
+ expect(deployment.variables()).toEqual(variables)
59
+ })
60
+
61
+ it('should merge all variables', () => {
62
+ const context = clone(fixtures.context)
63
+
64
+ /** @type {toa.deployment.Dependency} */
65
+ const dep1 = { variables: { global: [fixtures.secretVariable] } }
66
+
67
+ /** @type {toa.deployment.Dependency} */
68
+ const dep2 = { variables: { global: [fixtures.bindingVariable] } }
69
+
70
+ deployment = new Deployment(context, fixtures.compositions, [dep1, dep2], fixtures.process)
71
+
72
+ const result = deployment.variables()
73
+ const expectedVariables = [fixtures.bindingVariable, fixtures.secretVariable]
74
+
75
+ expect(result.global.length).toBe(expectedVariables.length)
76
+ expect(result.global).toStrictEqual(expect.arrayContaining(expectedVariables))
77
+ })
41
78
  })
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+
3
+ const { Operator } = require('../../src/deployment/operator')
4
+ const { generate } = require('randomstring')
5
+
6
+ it('should be', async () => {
7
+ expect(Operator).toBeInstanceOf(Function)
8
+ })
9
+
10
+ /** @type {toa.deployment.Operator} */
11
+ let operator
12
+
13
+ describe('env', () => {
14
+ /** @type {toa.deployment.Deployment} */
15
+ let deployment
16
+
17
+ /** @type {toa.deployment.images.Registry} */
18
+ let registry
19
+
20
+ beforeEach(() => {
21
+ deployment = /** @type {toa.deployment.Deployment} */ {}
22
+ registry = /** @type {toa.deployment.images.Registry} */ {}
23
+ })
24
+
25
+ it('should be', async () => {
26
+ operator = new Operator(deployment, registry)
27
+
28
+ expect(operator.variables).toBeInstanceOf(Function)
29
+ })
30
+
31
+ it('should return variables', async () => {
32
+ const variables = { [generate()]: { name: generate(), value: generate() } }
33
+
34
+ deployment.variables = jest.fn(() => variables)
35
+ operator = new Operator(deployment, registry)
36
+
37
+ const output = operator.variables()
38
+
39
+ expect(output).toStrictEqual(variables)
40
+ })
41
+ })
@@ -6,62 +6,65 @@ import type { dependency } from './dependency'
6
6
 
7
7
  declare namespace toa.deployment {
8
8
 
9
- interface Declaration {
10
- apiVersion: string
11
- type: string
12
- name: string
13
- description?: string
14
- version: string
15
- appVersion: string
16
- dependencies: dependency.Reference[]
9
+ interface Declaration {
10
+ apiVersion: string
11
+ type: string
12
+ name: string
13
+ description?: string
14
+ version: string
15
+ appVersion: string
16
+ dependencies: dependency.Reference[]
17
+ }
18
+
19
+ interface Contents {
20
+ compositions?: Composition[]
21
+ components?: string[]
22
+ services?: Service[]
23
+ proxies?: dependency.Proxy[]
24
+ variables?: dependency.Variables
25
+
26
+ [key: string]: Object
27
+ }
28
+
29
+ namespace installation {
30
+
31
+ interface Options {
32
+ wait?: boolean
33
+ target?: string
34
+ namespace?: string
17
35
  }
18
36
 
19
- interface Contents {
20
- compositions?: Composition[]
21
- components?: string[]
22
- services?: Service[]
23
- proxies?: dependency.Proxy[]
24
- variables?: dependency.Variables
25
- [key: string]: Object
26
- }
27
-
28
- namespace installation {
29
-
30
- interface Options {
31
- wait?: boolean
32
- target?: string
33
- namespace?: string
34
- }
37
+ }
35
38
 
39
+ namespace template {
40
+ interface Options {
41
+ namespace: string
36
42
  }
43
+ }
37
44
 
38
- namespace template {
39
- interface Options {
40
- namespace: string
41
- }
42
- }
45
+ interface Deployable {
46
+ name: string
47
+ image: string
48
+ }
43
49
 
44
- interface Deployable {
45
- name: string
46
- image: string
47
- }
50
+ interface Deployment {
51
+ export(target: string): Promise<void>
48
52
 
49
- interface Deployment {
50
- export(target: string): Promise<void>
53
+ install(options: installation.Options): Promise<void>
51
54
 
52
- install(options: installation.Options): Promise<void>
55
+ template(options: template.Options): Promise<string>
53
56
 
54
- template(options: template.Options): Promise<string>
55
- }
57
+ variables(): dependency.Variables
58
+ }
56
59
 
57
60
  }
58
61
 
59
62
  export namespace installation {
60
- export type Options = toa.deployment.installation.Options
63
+ export type Options = toa.deployment.installation.Options
61
64
  }
62
65
 
63
66
  export namespace template {
64
- export type Options = toa.deployment.template.Options
67
+ export type Options = toa.deployment.template.Options
65
68
  }
66
69
 
67
70
  export type Deployable = toa.deployment.Deployable
@@ -1,20 +1,23 @@
1
1
  // noinspection ES6UnusedImports
2
2
 
3
- import { installation, template } from './deployment'
3
+ import * as _deployment from './deployment'
4
+ import * as _dependency from './dependency'
4
5
 
5
6
  declare namespace toa.deployment {
6
7
 
7
- interface Operator {
8
- export(path?: string): Promise<string>
8
+ interface Operator {
9
+ export(path?: string): Promise<string>
9
10
 
10
- prepare(path?: string): Promise<string>
11
+ prepare(path?: string): Promise<string>
11
12
 
12
- build(): Promise<void>
13
+ build(): Promise<void>
13
14
 
14
- install(options?: installation.Options): Promise<void>
15
+ install(options?: _deployment.installation.Options): Promise<void>
15
16
 
16
- template(options?: template.Options): Promise<string>
17
- }
17
+ template(options?: _deployment.template.Options): Promise<string>
18
+
19
+ variables(): _dependency.dependency.Variables
20
+ }
18
21
 
19
22
  }
20
23