@toa.io/operations 1.0.0-alpha.6 → 1.0.0-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/operations",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
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.6",
31
- "@toa.io/generic": "1.0.0-alpha.6",
32
- "@toa.io/norm": "1.0.0-alpha.6",
33
- "@toa.io/yaml": "1.0.0-alpha.6",
30
+ "@toa.io/filesystem": "1.0.0-alpha.7",
31
+ "@toa.io/generic": "1.0.0-alpha.7",
32
+ "@toa.io/norm": "1.0.0-alpha.7",
33
+ "@toa.io/yaml": "1.0.0-alpha.7",
34
34
  "execa": "5.1.1",
35
35
  "fs-extra": "11.1.1"
36
36
  },
37
- "gitHead": "f28d629a9477646e267a8af8479cc1bb10d62c80"
37
+ "gitHead": "4f5ac0bc342d4b7bd469fbe5c74266f050b55c9f"
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 tags = this.#components.map((component) => component.locator.id + ':' + component.version)
29
+ const hash = createHash('sha256')
30
30
 
31
- return hash(tags.join(';'))
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 = generate()
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: generate()
24
+ version: '0.0.0'
26
25
  }
27
26
 
28
27
  /** @type {toa.norm.context.Registry} */
29
28
  const registry = {
30
- base: generate()
29
+ base: 'node:alpine'
31
30
  }
32
31
 
33
32
  exports.scope = generate()
34
33
  exports.name = name
35
- exports.version = hash(runtime.version + ';' + 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 { join, posix } = require('node:path')
4
- const { readFile: read, writeFile: write } = require('node:fs/promises')
5
-
6
- const { hash, overwrite } = require('@toa.io/generic')
7
- const fs = require('fs-extra')
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 tag = hash(this.#runtime?.version + ';' + this.version)
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 fs.ensureDir(path)
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)