@brutalsystems/dray 0.1.7 → 0.1.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 +1 -1
- package/src/core/depsCache.js +17 -3
package/package.json
CHANGED
package/src/core/depsCache.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
const fs = require('node:fs'); const path = require('node:path'); const crypto = require('node:crypto');
|
|
2
|
+
const { execFileSync } = require('node:child_process');
|
|
2
3
|
const { DRAY_HOME } = require('../constants');
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
// Whether the deps base image tag exists in the local Docker image store. A
|
|
6
|
+
// `docker system prune` can evict it while the lockfiles are unchanged — the hash
|
|
7
|
+
// check alone would then skip the rebuild and the main build fails at
|
|
8
|
+
// `FROM <depsImage.tag>: not found`.
|
|
9
|
+
function depsImagePresent(tag) {
|
|
10
|
+
try { execFileSync('docker', ['image', 'inspect', tag], { stdio: 'ignore' }); return true; }
|
|
11
|
+
catch { return false; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// `imagePresent` is injectable for tests; defaults to the real docker check.
|
|
15
|
+
function needsDepsRebuild(image, repoPath, repo, stateDir = path.join(DRAY_HOME, 'depshash'), imagePresent = depsImagePresent) {
|
|
4
16
|
if (!image.depsImage) return false;
|
|
5
17
|
const h = crypto.createHash('sha256');
|
|
6
18
|
for (const rel of image.depsImage.rebuildOn || []) {
|
|
@@ -11,7 +23,9 @@ function needsDepsRebuild(image, repoPath, repo, stateDir = path.join(DRAY_HOME,
|
|
|
11
23
|
fs.mkdirSync(stateDir, { recursive: true });
|
|
12
24
|
const file = path.join(stateDir, `${repo}__${image.name}.depshash`);
|
|
13
25
|
const prev = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
14
|
-
|
|
26
|
+
// Rebuild when the lockfiles changed OR the cached deps image tag is gone.
|
|
27
|
+
const present = !image.depsImage.tag || imagePresent(image.depsImage.tag);
|
|
28
|
+
if (prev === digest && present) return false;
|
|
15
29
|
fs.writeFileSync(file, digest); return true;
|
|
16
30
|
}
|
|
17
|
-
module.exports = { needsDepsRebuild };
|
|
31
|
+
module.exports = { needsDepsRebuild, depsImagePresent };
|