@toa.io/operations 1.0.0-alpha.27 → 1.0.0-alpha.272

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/image/runtime.Dockerfile +4 -0
  3. package/package.json +8 -8
  4. package/readme.md +16 -0
  5. package/src/deployment/.deployment/.describe/compositions.js +7 -2
  6. package/src/deployment/.deployment/.describe/events.js +67 -0
  7. package/src/deployment/.deployment/.describe/mounts.js +24 -0
  8. package/src/deployment/.deployment/.describe/resources.js +37 -0
  9. package/src/deployment/.deployment/.describe/services.js +28 -1
  10. package/src/deployment/.deployment/.describe/services.test.js +61 -0
  11. package/src/deployment/.deployment/.describe/variables.js +6 -5
  12. package/src/deployment/.deployment/describe.js +130 -6
  13. package/src/deployment/.deployment/merge.js +45 -1
  14. package/src/deployment/.deployment/merge.test.js +74 -0
  15. package/src/deployment/chart/templates/compositions.yaml +70 -0
  16. package/src/deployment/chart/templates/mono.yaml +177 -0
  17. package/src/deployment/chart/templates/services.yaml +71 -4
  18. package/src/deployment/chart/values.yaml +11 -1
  19. package/src/deployment/composition.js +1 -0
  20. package/src/deployment/deployment.js +6 -2
  21. package/src/deployment/factory.js +24 -8
  22. package/src/deployment/images/composition.Dockerfile +2 -2
  23. package/src/deployment/images/composition.js +16 -11
  24. package/src/deployment/images/factory.js +12 -3
  25. package/src/deployment/images/image.js +16 -7
  26. package/src/deployment/images/mono.Dockerfile +18 -0
  27. package/src/deployment/images/mono.js +71 -0
  28. package/src/deployment/images/runtime-base.test.js +90 -0
  29. package/src/deployment/images/service.Dockerfile +3 -3
  30. package/src/deployment/operator.js +4 -0
  31. package/src/deployment/registry.js +64 -16
  32. package/src/deployment/registry.test.js +175 -0
  33. package/types/_deployment/dependency.d.ts +2 -0
  34. package/types/_deployment/images/image.d.ts +4 -2
  35. package/types/_deployment/registry.d.ts +9 -7
  36. package/types/dependency.ts +71 -0
  37. package/types/dependency.d.ts +0 -39
  38. /package/types/{index.d.ts → index.ts} +0 -0
@@ -5,6 +5,7 @@ const fs = require('fs-extra')
5
5
  const { createHash } = require('node:crypto')
6
6
 
7
7
  const { Image } = require('./image')
8
+ const { undef } = require('@toa.io/concise/source/expressions/undefined')
8
9
 
9
10
  class Composition extends Image {
10
11
  dockerfile = join(__dirname, 'composition.Dockerfile')
@@ -37,23 +38,27 @@ class Composition extends Image {
37
38
  }
38
39
 
39
40
  get base () {
40
- if (this.#image !== undefined) {
41
- return this.#image
42
- }
41
+ if (this.#image !== undefined) return this.#image
43
42
 
44
- let image = null
43
+ const images = new Set(this.#components.map((component) => component.build?.image))
45
44
 
46
- for (const component of this.#components) {
47
- const value = component.build?.image
45
+ if (images.size > 1)
46
+ throw new Error(`Composition '${this.#name}' requires different base images for its components. Specify base image for the composition in the context.`)
47
+
48
+ return images.values().next().value
49
+ }
50
+
51
+ get run () {
52
+ const commands = []
48
53
 
49
- if (image !== null && image !== value) {
50
- throw new Error(`Composition '${this.#name}' requires different base images for its components. Specify base image for the composition in the context.`)
51
- }
54
+ for (const component of this.#components) {
55
+ const run = component.build?.run
52
56
 
53
- image = value
57
+ if (run !== undefined)
58
+ commands.push(run)
54
59
  }
55
60
 
56
- return image ?? undefined
61
+ return commands.join('\n')
57
62
  }
58
63
 
59
64
  async prepare (root) {
@@ -2,10 +2,8 @@
2
2
 
3
3
  const { Composition } = require('./composition')
4
4
  const { Service } = require('./service')
5
+ const { Mono } = require('./mono')
5
6
 
6
- /**
7
- * @implements {toa.deployment.images.Factory}
8
- */
9
7
  class Factory {
10
8
  /** @type {string} */
11
9
  #scope
@@ -48,6 +46,17 @@ class Factory {
48
46
 
49
47
  return instance
50
48
  }
49
+
50
+ /**
51
+ * @returns {Mono}
52
+ */
53
+ mono (composition) {
54
+ const instance = new Mono(this.#scope, this.#runtime, this.#registry, composition)
55
+
56
+ instance.tag()
57
+
58
+ return instance
59
+ }
51
60
  }
52
61
 
53
62
  exports.Factory = Factory
@@ -26,9 +26,7 @@ class Image {
26
26
  #registry
27
27
  #runtime
28
28
  #values = {
29
- build: {
30
- image: 'node:20.9.0-alpine3.18'
31
- }
29
+ build: {}
32
30
  }
33
31
 
34
32
  constructor (scope, runtime, registry) {
@@ -54,6 +52,8 @@ class Image {
54
52
 
55
53
  get base () {}
56
54
 
55
+ get run () {}
56
+
57
57
  async prepare (root) {
58
58
  if (this.dockerfile === undefined) throw new Error('Dockerfile isn\'t specified')
59
59
 
@@ -65,7 +65,7 @@ class Image {
65
65
 
66
66
  const template = await read(this.dockerfile, 'utf-8')
67
67
  const contents = template.replace(/{{(\S{1,32})}}/g, (_, key) => this.#value(key))
68
- const ignore = 'Dockerfile'
68
+ const ignore = ['Dockerfile', '**/node_modules'].join('\r\n')
69
69
 
70
70
  await write(join(path, 'Dockerfile'), contents)
71
71
  await write(join(path, '.dockerignore'), ignore)
@@ -77,13 +77,19 @@ class Image {
77
77
 
78
78
  #setValues () {
79
79
  this.#values.runtime = this.#runtime
80
- this.#values.build = overwrite(this.#values.build, this.#registry.build)
80
+ this.#values.build = overwrite({
81
+ image: `${RUNTIME_IMAGE}:${this.#runtime.version}`
82
+ }, this.#registry.build)
81
83
 
82
84
  const image = this.base
83
85
 
84
- if (image !== undefined) {
86
+ if (image !== undefined)
85
87
  this.#values.build.image = image
86
- }
88
+
89
+ const run = this.run
90
+
91
+ if (run !== undefined)
92
+ this.#values.build.run = (this.#values.build.run === undefined ? '' : this.#values.build.run + '\n') + run
87
93
 
88
94
  if (this.#values.build.arguments !== undefined) this.#values.build.arguments = createArguments(this.#values.build.arguments)
89
95
  if (this.#values.build.run !== undefined) this.#values.build.run = createRunCommands(this.#values.build.run)
@@ -121,4 +127,7 @@ function createArguments (variables) {
121
127
  return args.join('\n')
122
128
  }
123
129
 
130
+ const RUNTIME_IMAGE = 'ghcr.io/toa-io/runtime'
131
+
124
132
  exports.Image = Image
133
+ exports.RUNTIME_IMAGE = RUNTIME_IMAGE
@@ -0,0 +1,18 @@
1
+ FROM {{build.image}}
2
+
3
+ {{build.arguments}}
4
+
5
+ ENV NODE_ENV=production
6
+ RUN if [ "{{runtime.registry}}" != "" ]; then npm set registry {{runtime.registry}}; fi
7
+ RUN if [ "{{runtime.proxy}}" != "" ]; then npm set proxy {{runtime.proxy}}; fi
8
+
9
+ WORKDIR /composition
10
+ COPY --chown=node:node . /composition
11
+
12
+ {{build.run}}
13
+
14
+ RUN --mount=type=cache,target=/root/.npm \
15
+ for entry in *; do if [ -f "$entry/package.json" ]; then (cd $entry && npm i --omit=dev); fi; done
16
+
17
+ USER node
18
+ CMD toa mono *
@@ -0,0 +1,71 @@
1
+ 'use strict'
2
+
3
+ const { join } = require('node:path')
4
+ const fs = require('fs-extra')
5
+ const { createHash } = require('node:crypto')
6
+
7
+ const { Image } = require('./image')
8
+
9
+ class Mono extends Image {
10
+ dockerfile = join(__dirname, 'mono.Dockerfile')
11
+
12
+ #image
13
+ #components
14
+
15
+ constructor (scope, runtime, registry, composition) {
16
+ super(scope, runtime, registry)
17
+
18
+ this.#image = composition.image
19
+ this.#components = composition.components
20
+ }
21
+
22
+ get name () {
23
+ return 'mono'
24
+ }
25
+
26
+ get version () {
27
+ const hash = createHash('sha256')
28
+
29
+ for (const component of this.#components) {
30
+ hash.update(component.locator.id)
31
+ hash.update(component.version)
32
+ }
33
+
34
+ return hash.digest('hex').slice(0, 8)
35
+ }
36
+
37
+ get base () {
38
+ if (this.#image !== undefined) return this.#image
39
+
40
+ const images = new Set(this.#components.map((component) => component.build?.image))
41
+
42
+ if (images.size > 1)
43
+ throw new Error('Mono deployment requires different base images for its components. Specify base image for the composition in the context.')
44
+
45
+ return images.values().next().value
46
+ }
47
+
48
+ get run () {
49
+ const commands = []
50
+
51
+ for (const component of this.#components) {
52
+ const run = component.build?.run
53
+
54
+ if (run !== undefined)
55
+ commands.push(run)
56
+ }
57
+
58
+ return commands.join('\n')
59
+ }
60
+
61
+ async prepare (root) {
62
+ const context = await super.prepare(root)
63
+
64
+ for (const component of this.#components)
65
+ await fs.copy(component.path, join(context, component.locator.label))
66
+
67
+ return context
68
+ }
69
+ }
70
+
71
+ exports.Mono = Mono
@@ -0,0 +1,90 @@
1
+ 'use strict'
2
+
3
+ const { join } = require('node:path')
4
+ const { readFile } = require('node:fs/promises')
5
+ const { directory } = require('@toa.io/filesystem')
6
+
7
+ const { Image, RUNTIME_IMAGE } = require('./image')
8
+
9
+ const compositionDockerfile = join(__dirname, 'composition.Dockerfile')
10
+ const serviceDockerfile = join(__dirname, 'service.Dockerfile')
11
+
12
+ class TestImage extends Image {
13
+ dockerfile
14
+
15
+ #name
16
+ #base
17
+
18
+ constructor (runtime, registry, dockerfile, name = 'test', base) {
19
+ super('acme', runtime, registry)
20
+
21
+ this.dockerfile = dockerfile
22
+ this.#name = name
23
+ this.#base = base
24
+ }
25
+
26
+ get name () {
27
+ return this.#name
28
+ }
29
+
30
+ get version () {
31
+ return 'abcdef12'
32
+ }
33
+
34
+ get base () {
35
+ return this.#base
36
+ }
37
+ }
38
+
39
+ describe('runtime base image', () => {
40
+ /** @type {string} */
41
+ let root
42
+
43
+ beforeEach(async () => {
44
+ root = await directory.temp('toa-runtime-base-test')
45
+ })
46
+
47
+ it('should default build.image to version-pinned GHCR runtime image', async () => {
48
+ const runtime = { version: '1.0.0-alpha.232' }
49
+ const image = new TestImage(runtime, {}, compositionDockerfile)
50
+
51
+ const path = await image.prepare(root)
52
+ const dockerfile = await readFile(join(path, 'Dockerfile'), 'utf8')
53
+
54
+ expect(dockerfile).toContain(`FROM ${RUNTIME_IMAGE}:1.0.0-alpha.232`)
55
+ expect(dockerfile).not.toMatch(/npm i -g @toa\.io\/runtime/)
56
+ })
57
+
58
+ it('should not install runtime in service Dockerfile template', async () => {
59
+ const runtime = { version: '1.0.0-alpha.99' }
60
+ const image = new TestImage(runtime, {}, serviceDockerfile, 'service-test')
61
+
62
+ const path = await image.prepare(root)
63
+ const dockerfile = await readFile(join(path, 'Dockerfile'), 'utf8')
64
+
65
+ expect(dockerfile).toContain(`FROM ${RUNTIME_IMAGE}:1.0.0-alpha.99`)
66
+ expect(dockerfile).not.toMatch(/npm i -g @toa\.io\/runtime/)
67
+ })
68
+
69
+ it('should allow registry.build.image override', async () => {
70
+ const runtime = { version: '1.0.0-alpha.232' }
71
+ const registry = { build: { image: 'node:24.14.0-alpine3.22' } }
72
+ const image = new TestImage(runtime, registry, compositionDockerfile)
73
+
74
+ const path = await image.prepare(root)
75
+ const dockerfile = await readFile(join(path, 'Dockerfile'), 'utf8')
76
+
77
+ expect(dockerfile).toContain('FROM node:24.14.0-alpine3.22')
78
+ expect(dockerfile).not.toContain(RUNTIME_IMAGE)
79
+ })
80
+
81
+ it('should allow composition.image override via base', async () => {
82
+ const runtime = { version: '1.0.0-alpha.232' }
83
+ const image = new TestImage(runtime, {}, compositionDockerfile, 'mono', 'custom.example/base:1')
84
+
85
+ const path = await image.prepare(root)
86
+ const dockerfile = await readFile(join(path, 'Dockerfile'), 'utf8')
87
+
88
+ expect(dockerfile).toContain('FROM custom.example/base:1')
89
+ })
90
+ })
@@ -1,14 +1,14 @@
1
- FROM node:20.9.0-alpine3.18
1
+ FROM {{build.image}}
2
2
 
3
3
  ENV NODE_ENV=production
4
4
  RUN if [ "{{runtime.registry}}" != "" ]; then npm set registry {{runtime.registry}}; fi
5
5
  RUN if [ "{{runtime.proxy}}" != "" ]; then npm set proxy {{runtime.proxy}}; fi
6
- RUN npm i -g @toa.io/runtime@{{runtime.version}} --omit=dev
7
6
 
8
7
  WORKDIR /service
9
8
  COPY --chown=node:node . /service
10
9
 
11
- RUN npm i --omit=dev
10
+ RUN --mount=type=cache,target=/root/.npm \
11
+ npm i --omit=dev
12
12
 
13
13
  USER node
14
14
  CMD toa serve .
@@ -50,6 +50,10 @@ class Operator {
50
50
  variables () {
51
51
  return this.#deployment.variables()
52
52
  }
53
+
54
+ tags () {
55
+ return this.#registry.tags()
56
+ }
53
57
  }
54
58
 
55
59
  /** @type {toa.deployment.installation.Options} */
@@ -1,12 +1,14 @@
1
1
  'use strict'
2
2
 
3
+ const { posix } = require('node:path')
3
4
  const workspace = require('./workspace')
4
- const { newid } = require('@toa.io/generic')
5
5
 
6
6
  /**
7
7
  * @implements {toa.deployment.Registry}
8
8
  */
9
9
  class Registry {
10
+ #scope
11
+
10
12
  #registry
11
13
 
12
14
  #factory
@@ -15,7 +17,11 @@ class Registry {
15
17
 
16
18
  #images = []
17
19
 
18
- constructor (registry, factory, process) {
20
+ /** @type {string | undefined} */
21
+ #builder
22
+
23
+ constructor (scope, registry, factory, process) {
24
+ this.#scope = scope
19
25
  this.#registry = registry
20
26
  this.#factory = factory
21
27
  this.#process = process
@@ -29,6 +35,10 @@ class Registry {
29
35
  return this.#create('service', path, service)
30
36
  }
31
37
 
38
+ mono (composition) {
39
+ return this.#create('mono', composition)
40
+ }
41
+
32
42
  async prepare (root) {
33
43
  const path = await workspace.create('images', root)
34
44
 
@@ -40,9 +50,8 @@ class Registry {
40
50
  async build () {
41
51
  await this.prepare()
42
52
 
43
- for (const image of this.#images) {
53
+ for (const image of this.#images)
44
54
  await this.#build(image)
45
- }
46
55
  }
47
56
 
48
57
  async push () {
@@ -51,8 +60,12 @@ class Registry {
51
60
  for (const image of this.#images) await this.#push(image)
52
61
  }
53
62
 
63
+ tags () {
64
+ return this.#images.map((image) => image.reference)
65
+ }
66
+
54
67
  /**
55
- * @param {'composition' | 'service'} type
68
+ * @param {'composition' | 'service' | 'mono'} type
56
69
  * @param {...any} args
57
70
  * @returns {toa.deployment.images.Image}
58
71
  */
@@ -70,13 +83,17 @@ class Registry {
70
83
  * @returns {Promise<void>}
71
84
  */
72
85
  async #build (image, push = false) {
86
+ if (await this.exists(image.reference)) {
87
+ console.log('Image already exists, skipping:', image.reference)
88
+ return
89
+ }
90
+
73
91
  const args = ['--context=default', 'buildx', 'build']
74
92
 
75
- if (push) {
93
+ if (push)
76
94
  args.push('--push')
77
- } else {
95
+ else
78
96
  args.push('--load')
79
- }
80
97
 
81
98
  args.push('--tag', image.reference, image.context)
82
99
 
@@ -88,14 +105,15 @@ class Registry {
88
105
 
89
106
  if (multiarch) {
90
107
  const platform = this.#registry.platforms.join(',')
91
- const builder = await this.#createBuilder()
108
+ const builder = await this.#ensureBuilder()
92
109
 
93
110
  args.push('--platform', platform)
94
111
  args.push('--builder', builder)
95
112
 
96
- } else {
113
+ if (this.#registry.base !== undefined)
114
+ this.#appendCache(args)
115
+ } else
97
116
  args.push('--builder', 'default')
98
- }
99
117
 
100
118
  args.push('--progress', 'plain')
101
119
 
@@ -106,13 +124,43 @@ class Registry {
106
124
  await this.#build(image, true)
107
125
  }
108
126
 
109
- async #createBuilder () {
110
- const name = `toa-${newid()}`
111
- const create = `buildx create --name ${name} --bootstrap --use`.split(' ')
127
+ async exists (tag) {
128
+ const args = ['manifest', 'inspect', tag]
129
+
130
+ try {
131
+ await this.#process.execute('docker', args, { silently: true })
132
+ } catch (error) {
133
+ console.log(error.message)
134
+
135
+ return false
136
+ }
137
+
138
+ return true
139
+ }
140
+
141
+ async #ensureBuilder () {
142
+ if (this.#builder !== undefined)
143
+ return this.#builder
144
+
145
+ try {
146
+ await this.#process.execute('docker', ['buildx', 'inspect', BUILDER], { silently: true })
147
+ } catch {
148
+ await this.#process.execute('docker', ['buildx', 'create', '--name', BUILDER, '--bootstrap'])
149
+ }
150
+
151
+ this.#builder = BUILDER
152
+
153
+ return BUILDER
154
+ }
112
155
 
113
- await this.#process.execute('docker', create)
156
+ /**
157
+ * @param {string[]} args
158
+ */
159
+ #appendCache (args) {
160
+ const ref = posix.join(this.#registry.base, this.#scope, 'buildcache')
114
161
 
115
- return name
162
+ args.push('--cache-from', `type=registry,ref=${ref}`)
163
+ args.push('--cache-to', `type=registry,ref=${ref},mode=max,image-manifest=true`)
116
164
  }
117
165
  }
118
166
 
@@ -0,0 +1,175 @@
1
+ 'use strict'
2
+
3
+ const { Registry } = require('./registry')
4
+
5
+ /** @type {toa.operations.Process} */
6
+ let process
7
+
8
+ /** @type {toa.deployment.images.Factory} */
9
+ let factory
10
+
11
+ /** @type {toa.deployment.images.Image[]} */
12
+ let images
13
+
14
+ beforeEach(() => {
15
+ images = []
16
+ process = /** @type {toa.operations.Process} */ {
17
+ execute: jest.fn(async (cmd, args) => {
18
+ if (args[0] === 'manifest')
19
+ throw new Error('manifest unknown')
20
+
21
+ if (args[0] === 'buildx' && args[1] === 'inspect')
22
+ throw new Error('builder not found')
23
+
24
+ return ''
25
+ })
26
+ }
27
+
28
+ factory = /** @type {toa.deployment.images.Factory} */ {
29
+ composition: () => createImage('composition-mono'),
30
+ service: () => createImage('extension-realtime')
31
+ }
32
+ })
33
+
34
+ it('should reuse named builder across images', async () => {
35
+ const registry = createRegistry({ base: 'example.com/reg', platforms: ['linux/amd64'] })
36
+
37
+ registry.composition(/** @type {any} */ ({}))
38
+ registry.service('.', /** @type {any} */ ({}))
39
+
40
+ await registry.build()
41
+
42
+ const creates = process.execute.mock.calls.filter(([, args]) =>
43
+ args[0] === 'buildx' && args[1] === 'create')
44
+
45
+ expect(creates).toHaveLength(1)
46
+ expect(creates[0][1]).toEqual(['buildx', 'create', '--name', 'toa', '--bootstrap'])
47
+
48
+ const builds = process.execute.mock.calls.filter(([, args]) =>
49
+ args[0] === '--context=default' && args[1] === 'buildx' && args[2] === 'build')
50
+
51
+ expect(builds).toHaveLength(2)
52
+
53
+ for (const [, args] of builds) {
54
+ expect(args).toContain('--builder')
55
+ expect(args[args.indexOf('--builder') + 1]).toBe('toa')
56
+ }
57
+ })
58
+
59
+ it('should not create builder when it already exists', async () => {
60
+ process.execute = jest.fn(async (cmd, args) => {
61
+ if (args[0] === 'manifest')
62
+ throw new Error('manifest unknown')
63
+
64
+ return ''
65
+ })
66
+
67
+ const registry = createRegistry({ base: 'example.com/reg', platforms: ['linux/amd64'] })
68
+
69
+ registry.composition(/** @type {any} */ ({}))
70
+
71
+ await registry.build()
72
+
73
+ const creates = process.execute.mock.calls.filter(([, args]) =>
74
+ args[0] === 'buildx' && args[1] === 'create')
75
+
76
+ expect(creates).toHaveLength(0)
77
+ })
78
+
79
+ it('should add shared registry cache flags when base is set', async () => {
80
+ const registry = createRegistry({ base: 'example.com/reg', platforms: ['linux/amd64'] })
81
+
82
+ registry.composition(/** @type {any} */ ({}))
83
+ registry.service('.', /** @type {any} */ ({}))
84
+
85
+ await registry.build()
86
+
87
+ const builds = process.execute.mock.calls.filter(([, args]) =>
88
+ args[0] === '--context=default' && args[2] === 'build')
89
+
90
+ expect(builds).toHaveLength(2)
91
+
92
+ for (const [, args] of builds) {
93
+ expect(args).toContain('--cache-from')
94
+ expect(args).toContain('type=registry,ref=example.com/reg/acme/buildcache')
95
+ expect(args).toContain('--cache-to')
96
+ expect(args).toContain('type=registry,ref=example.com/reg/acme/buildcache,mode=max,image-manifest=true')
97
+ }
98
+ })
99
+
100
+ it('should omit cache flags when base is not set', async () => {
101
+ const registry = createRegistry({ platforms: ['linux/amd64'] })
102
+
103
+ registry.composition(/** @type {any} */ ({}))
104
+
105
+ await registry.build()
106
+
107
+ const builds = process.execute.mock.calls.filter(([, args]) =>
108
+ args[0] === '--context=default' && args[2] === 'build')
109
+
110
+ expect(builds).toHaveLength(1)
111
+
112
+ const [, args] = builds[0]
113
+
114
+ expect(args).not.toContain('--cache-from')
115
+ expect(args).not.toContain('--cache-to')
116
+ })
117
+
118
+ it('should use default builder when platforms is null', async () => {
119
+ const registry = createRegistry({ base: 'example.com/reg', platforms: null })
120
+
121
+ registry.composition(/** @type {any} */ ({}))
122
+
123
+ await registry.build()
124
+
125
+ const builds = process.execute.mock.calls.filter(([, args]) =>
126
+ args[0] === '--context=default' && args[2] === 'build')
127
+
128
+ expect(builds).toHaveLength(1)
129
+
130
+ const [, args] = builds[0]
131
+
132
+ expect(args[args.indexOf('--builder') + 1]).toBe('default')
133
+ expect(args).not.toContain('--cache-from')
134
+ expect(args).not.toContain('--platform')
135
+ })
136
+
137
+ it('should skip build when image already exists', async () => {
138
+ process.execute = jest.fn(async () => '')
139
+
140
+ const registry = createRegistry({ base: 'example.com/reg', platforms: ['linux/amd64'] })
141
+
142
+ registry.composition(/** @type {any} */ ({}))
143
+
144
+ await registry.build()
145
+
146
+ const builds = process.execute.mock.calls.filter(([, args]) =>
147
+ args[0] === '--context=default' && args[2] === 'build')
148
+
149
+ expect(builds).toHaveLength(0)
150
+ expect(process.execute).toHaveBeenCalledWith('docker', ['manifest', 'inspect', images[0].reference], { silently: true })
151
+ })
152
+
153
+ /**
154
+ * @param {object} [registry]
155
+ * @returns {Registry}
156
+ */
157
+ function createRegistry (registry = {}) {
158
+ return new Registry('acme', registry, factory, process)
159
+ }
160
+
161
+ /**
162
+ * @param {string} name
163
+ * @returns {toa.deployment.images.Image}
164
+ */
165
+ function createImage (name) {
166
+ const image = /** @type {toa.deployment.images.Image} */ {
167
+ reference: `example.com/reg/acme/${name}:abcdef12`,
168
+ context: `/tmp/${name}`,
169
+ prepare: jest.fn(async () => `/tmp/${name}`)
170
+ }
171
+
172
+ images.push(image)
173
+
174
+ return image
175
+ }
@@ -50,6 +50,7 @@ declare namespace toa.deployment {
50
50
  services?: Service[] // dependency.Service
51
51
  proxies?: Proxy[]
52
52
  variables?: Variables
53
+ events?: string[]
53
54
  }
54
55
 
55
56
  }
@@ -59,6 +60,7 @@ declare namespace toa.deployment {
59
60
  services?: _service.Service[] // deployment.Service
60
61
  proxies?: dependency.Proxy[]
61
62
  variables?: dependency.Variables
63
+ events?: string[]
62
64
  }
63
65
 
64
66
  }