@toa.io/operations 1.0.0-alpha.7 → 1.0.0-alpha.70
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 +8 -8
- package/src/deployment/.deployment/.describe/compositions.js +4 -2
- package/src/deployment/.deployment/.describe/mounts.js +24 -0
- package/src/deployment/.deployment/.describe/variables.js +5 -4
- package/src/deployment/.deployment/describe.js +15 -6
- package/src/deployment/.deployment/merge.js +4 -1
- package/src/deployment/chart/templates/compositions.yaml +15 -0
- package/src/deployment/chart/templates/services.yaml +18 -3
- package/src/deployment/chart/values.yaml +10 -2
- package/src/deployment/factory.js +0 -1
- package/src/deployment/images/factory.js +0 -3
- package/src/deployment/images/image.js +1 -1
- package/src/deployment/operator.js +4 -0
- package/src/deployment/registry.js +22 -16
- package/types/_deployment/registry.d.ts +9 -7
- package/types/dependency.ts +58 -0
- package/types/dependency.d.ts +0 -30
- /package/types/{index.d.ts → index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/operations",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.70",
|
|
4
4
|
"description": "Toa Deployment",
|
|
5
5
|
"homepage": "https://toa.io",
|
|
6
6
|
"author": {
|
|
@@ -16,23 +16,23 @@
|
|
|
16
16
|
"url": "https://github.com/toa-io/toa/issues"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">= 20.0.0"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"main": "src/index.js",
|
|
25
|
-
"types": "types/index.
|
|
25
|
+
"types": "types/index.ts",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@toa.io/filesystem": "1.0.0-alpha.
|
|
31
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
32
|
-
"@toa.io/norm": "1.0.0-alpha.
|
|
33
|
-
"@toa.io/yaml": "1.0.0-alpha.
|
|
30
|
+
"@toa.io/filesystem": "1.0.0-alpha.63",
|
|
31
|
+
"@toa.io/generic": "1.0.0-alpha.63",
|
|
32
|
+
"@toa.io/norm": "1.0.0-alpha.67",
|
|
33
|
+
"@toa.io/yaml": "1.0.0-alpha.63",
|
|
34
34
|
"execa": "5.1.1",
|
|
35
35
|
"fs-extra": "11.1.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "3fe12fa8b6a82fecc9205e9f6dd4b39e03184c7b"
|
|
38
38
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { addVariables } = require('./variables')
|
|
4
|
+
const { addMounts } = require('./mounts')
|
|
4
5
|
|
|
5
|
-
function compositions (compositions,
|
|
6
|
+
function compositions (compositions, dependency) {
|
|
6
7
|
for (const composition of compositions) {
|
|
7
|
-
addVariables(composition, variables)
|
|
8
|
+
addVariables(composition, dependency.variables)
|
|
9
|
+
addMounts(composition, dependency.mounts)
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function addMounts (composition, mounts) {
|
|
4
|
+
if (mounts === undefined)
|
|
5
|
+
return
|
|
6
|
+
|
|
7
|
+
const used = new Set()
|
|
8
|
+
|
|
9
|
+
for (const [key, mount] of Object.entries(mounts)) {
|
|
10
|
+
if (key !== 'global' && !composition.components?.includes(key))
|
|
11
|
+
continue
|
|
12
|
+
|
|
13
|
+
for (const { name, path, claim } of mount) {
|
|
14
|
+
if (used.has(name))
|
|
15
|
+
continue
|
|
16
|
+
|
|
17
|
+
composition.mounts ??= []
|
|
18
|
+
composition.mounts.push({ name, path, claim })
|
|
19
|
+
used.add(name)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.addMounts = addMounts
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
function addVariables (
|
|
3
|
+
function addVariables (composition, variables) {
|
|
4
4
|
const used = new Set()
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
composition.variables ??= []
|
|
7
7
|
|
|
8
8
|
for (const [key, set] of Object.entries(variables)) {
|
|
9
|
-
if (key !== 'global' && !
|
|
9
|
+
if (key !== 'global' && !composition.components?.includes(key))
|
|
10
|
+
continue
|
|
10
11
|
|
|
11
12
|
for (const variable of set) {
|
|
12
13
|
if (used.has(variable.name)) continue
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
composition.variables.push(variable)
|
|
15
16
|
used.add(variable.name)
|
|
16
17
|
}
|
|
17
18
|
}
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const desc = require('./.describe')
|
|
4
4
|
|
|
5
5
|
const describe = (context, compositions, dependency) => {
|
|
6
6
|
const { services } = dependency
|
|
7
7
|
|
|
8
8
|
dependency.variables.global ??= []
|
|
9
|
-
dependency.variables.global.unshift({ name: 'TOA_ENV', value: context.environment })
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
dependency.variables.global.unshift(
|
|
11
|
+
{
|
|
12
|
+
name: 'TOA_CONTEXT',
|
|
13
|
+
value: context.name
|
|
14
|
+
}, {
|
|
15
|
+
name: 'TOA_ENV',
|
|
16
|
+
value: context.environment
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const components = desc.components(compositions)
|
|
12
21
|
const credentials = context.registry?.credentials
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
desc.compositions(compositions, dependency)
|
|
24
|
+
desc.services(services, dependency.variables)
|
|
16
25
|
|
|
17
26
|
return {
|
|
18
27
|
compositions,
|
|
19
28
|
components,
|
|
20
29
|
services,
|
|
21
|
-
credentials
|
|
30
|
+
credentials
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
|
|
@@ -13,14 +13,17 @@ const merge = (dependencies) => {
|
|
|
13
13
|
/** @type {toa.deployment.dependency.Variables} */
|
|
14
14
|
const variables = {}
|
|
15
15
|
|
|
16
|
+
const mounts = {}
|
|
17
|
+
|
|
16
18
|
for (const dependency of dependencies) {
|
|
17
19
|
if (dependency.references !== undefined) references.push(...dependency.references)
|
|
18
20
|
if (dependency.services !== undefined) services.push(...dependency.services)
|
|
19
21
|
if (dependency.proxies !== undefined) proxies.push(...dependency.proxies)
|
|
20
22
|
if (dependency.variables !== undefined) append(variables, dependency.variables)
|
|
23
|
+
if (dependency.mounts !== undefined) append(mounts, dependency.mounts)
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
return { references, services, proxies, variables }
|
|
26
|
+
return { references, services, proxies, variables, mounts }
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
const append = (merged, variables) => {
|
|
@@ -25,9 +25,24 @@ spec:
|
|
|
25
25
|
{{- include "env.var" . | indent 12 }}
|
|
26
26
|
{{- end }}
|
|
27
27
|
{{- end }}
|
|
28
|
+
{{- if .mounts }}
|
|
29
|
+
volumeMounts:
|
|
30
|
+
{{- range .mounts }}
|
|
31
|
+
- name: {{ .name }}
|
|
32
|
+
mountPath: {{ .path }}
|
|
33
|
+
{{- end }}
|
|
34
|
+
{{- end }}
|
|
28
35
|
{{- if $.Values.credentials }}
|
|
29
36
|
imagePullSecrets:
|
|
30
37
|
- name: {{ $.Values.credentials }}
|
|
31
38
|
{{- end }}
|
|
39
|
+
{{- if .mounts }}
|
|
40
|
+
volumes:
|
|
41
|
+
{{- range .mounts }}
|
|
42
|
+
- name: {{ .name }}
|
|
43
|
+
persistentVolumeClaim:
|
|
44
|
+
claimName: {{ .claim }}
|
|
45
|
+
{{- end }}
|
|
46
|
+
{{- end }}
|
|
32
47
|
---
|
|
33
48
|
{{- end }}
|
|
@@ -22,6 +22,16 @@ spec:
|
|
|
22
22
|
{{- include "env.var" . | indent 12 }}
|
|
23
23
|
{{- end }}
|
|
24
24
|
{{- end }}
|
|
25
|
+
{{- if .probe }}
|
|
26
|
+
readinessProbe:
|
|
27
|
+
httpGet:
|
|
28
|
+
path: {{ .probe.path }}
|
|
29
|
+
port: {{ .probe.port }}
|
|
30
|
+
{{- if .probe.delay }}
|
|
31
|
+
initialDelaySeconds: {{ .probe.delay }}
|
|
32
|
+
{{- end }}
|
|
33
|
+
{{- end }}
|
|
34
|
+
{{- if .port }}
|
|
25
35
|
---
|
|
26
36
|
apiVersion: v1
|
|
27
37
|
kind: Service
|
|
@@ -36,8 +46,10 @@ spec:
|
|
|
36
46
|
protocol: TCP
|
|
37
47
|
port: {{ .port }}
|
|
38
48
|
targetPort: {{ .port }}
|
|
39
|
-
|
|
49
|
+
{{- end }}
|
|
40
50
|
{{- if .ingress }}
|
|
51
|
+
{{- $service := .name }}
|
|
52
|
+
---
|
|
41
53
|
apiVersion: networking.k8s.io/v1
|
|
42
54
|
kind: Ingress
|
|
43
55
|
metadata:
|
|
@@ -51,15 +63,18 @@ spec:
|
|
|
51
63
|
ingressClassName: {{ .ingress.class }}
|
|
52
64
|
{{- end }}
|
|
53
65
|
rules:
|
|
54
|
-
|
|
66
|
+
{{- range .ingress.hosts }}
|
|
67
|
+
- host: {{ . }}
|
|
55
68
|
http:
|
|
56
69
|
paths:
|
|
57
70
|
- path: /
|
|
58
71
|
pathType: Prefix
|
|
59
72
|
backend:
|
|
60
73
|
service:
|
|
61
|
-
name: extension-{{
|
|
74
|
+
name: extension-{{ $service }}
|
|
62
75
|
port:
|
|
63
76
|
number: 8000
|
|
77
|
+
{{- end }}
|
|
64
78
|
{{- end }}
|
|
79
|
+
---
|
|
65
80
|
{{- end }}
|
|
@@ -3,6 +3,10 @@ compositions:
|
|
|
3
3
|
- name: todos
|
|
4
4
|
image: localhost:5000/composition-todos:0.0.0
|
|
5
5
|
replicas: 2
|
|
6
|
+
mounts:
|
|
7
|
+
- name: mount-name
|
|
8
|
+
path: /storage
|
|
9
|
+
claim: storage-pvc
|
|
6
10
|
components:
|
|
7
11
|
- todos-tasks
|
|
8
12
|
- todos-stats
|
|
@@ -18,7 +22,6 @@ compositions:
|
|
|
18
22
|
replicas: 3
|
|
19
23
|
components:
|
|
20
24
|
- users-users
|
|
21
|
-
# TODO: create component services only if sync binding is being used
|
|
22
25
|
components:
|
|
23
26
|
- todos-tasks
|
|
24
27
|
- todos-stats
|
|
@@ -29,7 +32,7 @@ services:
|
|
|
29
32
|
port: 8000
|
|
30
33
|
replicas: 2
|
|
31
34
|
ingress:
|
|
32
|
-
|
|
35
|
+
hosts: [dummies.toa.io]
|
|
33
36
|
class: alb
|
|
34
37
|
annotations:
|
|
35
38
|
alb.ingress.kubernetes.io/scheme: internet-facing
|
|
@@ -41,6 +44,11 @@ services:
|
|
|
41
44
|
secret:
|
|
42
45
|
name: secret-name
|
|
43
46
|
key: secret-key
|
|
47
|
+
probe:
|
|
48
|
+
port: 8000
|
|
49
|
+
path: /.ready
|
|
50
|
+
delay: 1
|
|
51
|
+
|
|
44
52
|
proxies:
|
|
45
53
|
- name: storage-proxy
|
|
46
54
|
target: host.docker.internal
|
|
@@ -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)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const workspace = require('./workspace')
|
|
4
|
+
const { newid } = require('@toa.io/generic')
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @implements {toa.deployment.Registry}
|
|
@@ -39,7 +40,9 @@ class Registry {
|
|
|
39
40
|
async build () {
|
|
40
41
|
await this.prepare()
|
|
41
42
|
|
|
42
|
-
for (const image of this.#images)
|
|
43
|
+
for (const image of this.#images) {
|
|
44
|
+
await this.#build(image)
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
async push () {
|
|
@@ -48,6 +51,10 @@ class Registry {
|
|
|
48
51
|
for (const image of this.#images) await this.#push(image)
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
tags () {
|
|
55
|
+
return this.#images.map((image) => image.reference)
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
/**
|
|
52
59
|
* @param {'composition' | 'service'} type
|
|
53
60
|
* @param {...any} args
|
|
@@ -69,7 +76,11 @@ class Registry {
|
|
|
69
76
|
async #build (image, push = false) {
|
|
70
77
|
const args = ['--context=default', 'buildx', 'build']
|
|
71
78
|
|
|
72
|
-
if (push)
|
|
79
|
+
if (push) {
|
|
80
|
+
args.push('--push')
|
|
81
|
+
} else {
|
|
82
|
+
args.push('--load')
|
|
83
|
+
}
|
|
73
84
|
|
|
74
85
|
args.push('--tag', image.reference, image.context)
|
|
75
86
|
|
|
@@ -81,12 +92,14 @@ class Registry {
|
|
|
81
92
|
|
|
82
93
|
if (multiarch) {
|
|
83
94
|
const platform = this.#registry.platforms.join(',')
|
|
95
|
+
const builder = await this.#createBuilder()
|
|
84
96
|
|
|
85
97
|
args.push('--platform', platform)
|
|
86
|
-
args.push('--builder',
|
|
98
|
+
args.push('--builder', builder)
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
} else {
|
|
101
|
+
args.push('--builder', 'default')
|
|
102
|
+
}
|
|
90
103
|
|
|
91
104
|
args.push('--progress', 'plain')
|
|
92
105
|
|
|
@@ -97,20 +110,13 @@ class Registry {
|
|
|
97
110
|
await this.#build(image, true)
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
async #ensureBuilder () {
|
|
101
|
-
const ls = 'buildx ls'.split(' ')
|
|
102
|
-
const output = await this.#process.execute('docker', ls, { silently: true })
|
|
103
|
-
const exists = output.split('\n').findIndex((line) => line.startsWith('toa '))
|
|
104
|
-
|
|
105
|
-
if (exists === -1) await this.#createBuilder()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
113
|
async #createBuilder () {
|
|
109
|
-
const
|
|
110
|
-
const
|
|
114
|
+
const name = `toa-${newid()}`
|
|
115
|
+
const create = `buildx create --name ${name} --bootstrap --use`.split(' ')
|
|
111
116
|
|
|
112
117
|
await this.#process.execute('docker', create)
|
|
113
|
-
|
|
118
|
+
|
|
119
|
+
return name
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type * as _norm from '@toa.io/norm/types'
|
|
2
2
|
import type * as _dependency from './dependency'
|
|
3
|
-
import type * as _image from
|
|
3
|
+
import type * as _image from './images/image'
|
|
4
4
|
|
|
5
5
|
declare namespace toa.deployment {
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
interface Registry {
|
|
8
|
-
composition(composition: _norm.Composition): _image.Image
|
|
8
|
+
composition (composition: _norm.Composition): _image.Image
|
|
9
|
+
|
|
10
|
+
service (path: string, service: _dependency.Service): _image.Image
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
prepare (path: string): Promise<string>
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
build (): Promise<void>
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
push (): Promise<void>
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
tags (): string[]
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Manifest } from '@toa.io/norm'
|
|
2
|
+
import type { Locator } from '@toa.io/core'
|
|
3
|
+
|
|
4
|
+
export interface Service {
|
|
5
|
+
group: string
|
|
6
|
+
name: string
|
|
7
|
+
version: string
|
|
8
|
+
port?: number
|
|
9
|
+
ingress?: Ingress
|
|
10
|
+
variables?: Variable[]
|
|
11
|
+
components?: string[]
|
|
12
|
+
probe?: Probe
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Variable {
|
|
16
|
+
name: string
|
|
17
|
+
value?: string
|
|
18
|
+
secret?: {
|
|
19
|
+
name: string
|
|
20
|
+
key: string
|
|
21
|
+
optional?: boolean
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Instance<T> {
|
|
26
|
+
locator: Locator
|
|
27
|
+
manifest: T
|
|
28
|
+
component: Manifest
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type Instances<T> = Array<Instance<T>>
|
|
32
|
+
|
|
33
|
+
export type Variables = Record<'global' | string, Variable[]>
|
|
34
|
+
export type Mounts = Record<'global' | string, Mount[]>
|
|
35
|
+
|
|
36
|
+
export interface Dependency {
|
|
37
|
+
services?: Service[]
|
|
38
|
+
variables?: Variables
|
|
39
|
+
mounts?: Mounts
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Ingress {
|
|
43
|
+
hosts: string[]
|
|
44
|
+
class?: string
|
|
45
|
+
annotations?: object
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface Probe {
|
|
49
|
+
port: number
|
|
50
|
+
path: string
|
|
51
|
+
delay?: number
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface Mount {
|
|
55
|
+
name: string
|
|
56
|
+
path: string
|
|
57
|
+
claim: string
|
|
58
|
+
}
|
package/types/dependency.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export type Service = {
|
|
2
|
-
group: string
|
|
3
|
-
name: string
|
|
4
|
-
version: string
|
|
5
|
-
port: number
|
|
6
|
-
ingress?: {
|
|
7
|
-
host: string
|
|
8
|
-
class?: string
|
|
9
|
-
annotations?: object
|
|
10
|
-
}
|
|
11
|
-
variables: Variable[]
|
|
12
|
-
components?: string[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type Variable = {
|
|
16
|
-
name: string
|
|
17
|
-
value?: string
|
|
18
|
-
secret?: {
|
|
19
|
-
name: string,
|
|
20
|
-
key: string
|
|
21
|
-
optional?: boolean
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type Variables = Record<'global' | string, Variable[]>
|
|
26
|
-
|
|
27
|
-
export type Dependency = {
|
|
28
|
-
services?: Service[]
|
|
29
|
-
variables?: Variables
|
|
30
|
-
}
|
|
File without changes
|