@toa.io/operations 1.0.0-alpha.6 → 1.0.0-alpha.8
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": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.8",
|
|
4
4
|
"description": "Toa Deployment",
|
|
5
5
|
"homepage": "https://toa.io",
|
|
6
6
|
"author": {
|
|
@@ -27,12 +27,12 @@
|
|
|
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.8",
|
|
31
|
+
"@toa.io/generic": "1.0.0-alpha.8",
|
|
32
|
+
"@toa.io/norm": "1.0.0-alpha.8",
|
|
33
|
+
"@toa.io/yaml": "1.0.0-alpha.8",
|
|
34
34
|
"execa": "5.1.1",
|
|
35
35
|
"fs-extra": "11.1.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2ee18835c8214600e1d354251fa632913bff38c3"
|
|
38
38
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { join } = require('node:path')
|
|
4
|
-
const { hash } = require('@toa.io/generic')
|
|
5
4
|
const fs = require('fs-extra')
|
|
5
|
+
const { createHash } = require('node:crypto')
|
|
6
6
|
|
|
7
7
|
const { Image } = require('./image')
|
|
8
8
|
|
|
@@ -26,22 +26,29 @@ class Composition extends Image {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
get version () {
|
|
29
|
-
const
|
|
29
|
+
const hash = createHash('sha256')
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
for (const component of this.#components) {
|
|
32
|
+
hash.update(component.locator.id)
|
|
33
|
+
hash.update(component.version)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return hash.digest('hex').slice(0, 8)
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
get base () {
|
|
35
|
-
if (this.#image !== undefined)
|
|
40
|
+
if (this.#image !== undefined) {
|
|
36
41
|
return this.#image
|
|
42
|
+
}
|
|
37
43
|
|
|
38
44
|
let image = null
|
|
39
45
|
|
|
40
46
|
for (const component of this.#components) {
|
|
41
47
|
const value = component.build?.image
|
|
42
48
|
|
|
43
|
-
if (image !== null && image !== value)
|
|
49
|
+
if (image !== null && image !== value) {
|
|
44
50
|
throw new Error(`Composition '${this.#name}' requires different base images for its components. Specify base image for the composition in the context.`)
|
|
51
|
+
}
|
|
45
52
|
|
|
46
53
|
image = value
|
|
47
54
|
}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { Image } = require('./image')
|
|
4
4
|
const { generate } = require('randomstring')
|
|
5
|
-
const { hash } = require('@toa.io/generic')
|
|
6
5
|
|
|
7
|
-
const version =
|
|
6
|
+
const version = '168b04ff'
|
|
8
7
|
const name = generate()
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -22,17 +21,17 @@ class Class extends Image {
|
|
|
22
21
|
|
|
23
22
|
/** @type {toa.norm.context.Runtime} */
|
|
24
23
|
const runtime = {
|
|
25
|
-
version:
|
|
24
|
+
version: '0.0.0'
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/** @type {toa.norm.context.Registry} */
|
|
29
28
|
const registry = {
|
|
30
|
-
base:
|
|
29
|
+
base: 'node:alpine'
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
exports.scope = generate()
|
|
34
33
|
exports.name = name
|
|
35
|
-
exports.version =
|
|
34
|
+
exports.version = 'ba2409fc'
|
|
36
35
|
exports.Class = Class
|
|
37
36
|
exports.runtime = runtime
|
|
38
37
|
exports.registry = registry
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
3
|
+
const {
|
|
4
|
+
join,
|
|
5
|
+
posix
|
|
6
|
+
} = require('node:path')
|
|
7
|
+
const {
|
|
8
|
+
readFile: read,
|
|
9
|
+
writeFile: write
|
|
10
|
+
} = require('node:fs/promises')
|
|
11
|
+
const { createHash } = require('node:crypto')
|
|
12
|
+
|
|
13
|
+
const { overwrite } = require('@toa.io/generic')
|
|
14
|
+
const { mkdir } = require('node:fs/promises')
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* @implements {toa.deployment.images.Image}
|
|
@@ -31,7 +38,12 @@ class Image {
|
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
tag () {
|
|
34
|
-
const
|
|
41
|
+
const hash = createHash('sha256')
|
|
42
|
+
|
|
43
|
+
hash.update(this.#runtime.version)
|
|
44
|
+
hash.update(this.version)
|
|
45
|
+
|
|
46
|
+
const tag = hash.digest('hex').slice(0, 8)
|
|
35
47
|
|
|
36
48
|
this.reference = posix.join(this.#registry.base ?? '', this.#scope, `${this.name}:${tag}`)
|
|
37
49
|
}
|
|
@@ -49,7 +61,7 @@ class Image {
|
|
|
49
61
|
|
|
50
62
|
const path = join(root, `${this.name}.${this.version}`)
|
|
51
63
|
|
|
52
|
-
await
|
|
64
|
+
await mkdir(path, { recursive: true })
|
|
53
65
|
|
|
54
66
|
const template = await read(this.dockerfile, 'utf-8')
|
|
55
67
|
const contents = template.replace(/{{(\S{1,32})}}/g, (_, key) => this.#value(key))
|
|
@@ -69,8 +81,9 @@ class Image {
|
|
|
69
81
|
|
|
70
82
|
const image = this.base
|
|
71
83
|
|
|
72
|
-
if (image !== undefined)
|
|
84
|
+
if (image !== undefined) {
|
|
73
85
|
this.#values.build.image = image
|
|
86
|
+
}
|
|
74
87
|
|
|
75
88
|
if (this.#values.build.arguments !== undefined) this.#values.build.arguments = createArguments(this.#values.build.arguments)
|
|
76
89
|
if (this.#values.build.run !== undefined) this.#values.build.run = createRunCommands(this.#values.build.run)
|
|
@@ -39,7 +39,9 @@ class Registry {
|
|
|
39
39
|
async build () {
|
|
40
40
|
await this.prepare()
|
|
41
41
|
|
|
42
|
-
for (const image of this.#images)
|
|
42
|
+
for (const image of this.#images) {
|
|
43
|
+
await this.#build(image)
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async push () {
|
|
@@ -69,7 +71,11 @@ class Registry {
|
|
|
69
71
|
async #build (image, push = false) {
|
|
70
72
|
const args = ['--context=default', 'buildx', 'build']
|
|
71
73
|
|
|
72
|
-
if (push)
|
|
74
|
+
if (push) {
|
|
75
|
+
args.push('--push')
|
|
76
|
+
} else {
|
|
77
|
+
args.push('--load')
|
|
78
|
+
}
|
|
73
79
|
|
|
74
80
|
args.push('--tag', image.reference, image.context)
|
|
75
81
|
|
|
@@ -86,7 +92,9 @@ class Registry {
|
|
|
86
92
|
args.push('--builder', BUILDER)
|
|
87
93
|
|
|
88
94
|
await this.#ensureBuilder()
|
|
89
|
-
} else
|
|
95
|
+
} else {
|
|
96
|
+
args.push('--builder', 'default')
|
|
97
|
+
}
|
|
90
98
|
|
|
91
99
|
args.push('--progress', 'plain')
|
|
92
100
|
|