@brutalsystems/dray 0.1.9 → 0.1.11
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/cli/commands/add.js +14 -1
- package/src/config/registry.js +9 -3
- package/src/core/engine.js +17 -1
- package/src/primitives/kubectl.js +6 -2
package/package.json
CHANGED
package/src/cli/commands/add.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
const fs = require('node:fs'); const path = require('node:path');
|
|
1
2
|
const { loadRepoConfig } = require('../../config/repo'); const { addRepo } = require('../../config/registry');
|
|
3
|
+
|
|
4
|
+
// The registry is consulted from arbitrary working directories, so a stored path
|
|
5
|
+
// MUST be absolute. `dray add .` used to store "." verbatim, which then resolved
|
|
6
|
+
// against whatever cwd dray ran in later -- two repos added that way both pointed
|
|
7
|
+
// at "the current directory", and `dray ship <a>` from repo b deployed b under a's
|
|
8
|
+
// name. realpath so symlinked checkouts land on one canonical path.
|
|
9
|
+
function resolveRepoPath(repoPath) {
|
|
10
|
+
const p = path.resolve(repoPath || process.cwd());
|
|
11
|
+
try { return fs.realpathSync(p); } catch { return p; }
|
|
12
|
+
}
|
|
13
|
+
|
|
2
14
|
module.exports = function registerAdd(program) {
|
|
3
15
|
program.command('add [repoPath]').description('Register a repo').action((repoPath) => {
|
|
4
|
-
const p = repoPath
|
|
16
|
+
const p = resolveRepoPath(repoPath); const config = loadRepoConfig(p);
|
|
5
17
|
addRepo(undefined, { name: config.name, path: p, config }); console.log(`registered ${config.name} → ${p}`);
|
|
6
18
|
});
|
|
7
19
|
};
|
|
20
|
+
module.exports.resolveRepoPath = resolveRepoPath;
|
package/src/config/registry.js
CHANGED
|
@@ -10,16 +10,22 @@ function removeRepo(file, name) { const r = loadRegistry(file); delete r[name];
|
|
|
10
10
|
// without a manual `dray reload`. Falls back to the snapshot when the repo
|
|
11
11
|
// isn't checked out here (stat throws) or its config is momentarily invalid
|
|
12
12
|
// (loadRepoConfig throws) — a broken repo must not break `list`/`--all`.
|
|
13
|
-
function refreshEntry(entry) {
|
|
13
|
+
function refreshEntry(entry, name) {
|
|
14
14
|
try {
|
|
15
15
|
const mtime = Math.floor(fs.statSync(path.join(entry.path, '.dray', 'config.json')).mtimeMs);
|
|
16
16
|
if (mtime <= (Date.parse(entry.addedAt) || 0)) return entry;
|
|
17
|
-
|
|
17
|
+
const config = loadRepoConfig(entry.path);
|
|
18
|
+
// Only adopt a config that still belongs to this entry. A path pointing at a
|
|
19
|
+
// different project (a relative path left by an old `dray add .`, or a moved
|
|
20
|
+
// checkout) would otherwise have its config silently written into this key and
|
|
21
|
+
// PERSISTED -- turning `dray ship <name>` into a deploy of someone else's repo.
|
|
22
|
+
if (name !== undefined && config.name !== name) return entry;
|
|
23
|
+
return { ...entry, config, addedAt: new Date(mtime).toISOString() };
|
|
18
24
|
} catch { return entry; }
|
|
19
25
|
}
|
|
20
26
|
function allRepos(file = REGISTRY) {
|
|
21
27
|
const reg = loadRegistry(file); let changed = false;
|
|
22
|
-
for (const [n, e] of Object.entries(reg)) { const f = refreshEntry(e); if (f !== e) { reg[n] = f; changed = true; } }
|
|
28
|
+
for (const [n, e] of Object.entries(reg)) { const f = refreshEntry(e, n); if (f !== e) { reg[n] = f; changed = true; } }
|
|
23
29
|
if (changed) saveRegistry(file, reg);
|
|
24
30
|
return reg;
|
|
25
31
|
}
|
package/src/core/engine.js
CHANGED
|
@@ -52,9 +52,25 @@ async function execute(steps, { dryRun = false, allowDirty = false, deps } = {})
|
|
|
52
52
|
const vars = {}; for (const s of u.stamp) vars[s.var] = `${s.repoUri}:${sha}`;
|
|
53
53
|
const files = d.render.renderManifests(u.manifests, vars, u.repoPath, { dryRun });
|
|
54
54
|
if (files[0]) renderDirs.push(path.dirname(files[0]));
|
|
55
|
+
// Read the running image BEFORE applying. If it differs from what we
|
|
56
|
+
// are about to stamp, this apply changes the pod template and the
|
|
57
|
+
// Deployment controller starts a rollout on its own — so the rollout
|
|
58
|
+
// step that follows must wait rather than restart, or every ship
|
|
59
|
+
// produces two ReplicaSets and replaces the pod twice.
|
|
60
|
+
//
|
|
61
|
+
// Deliberately conservative: any doubt (dry run, cronjob, unreadable
|
|
62
|
+
// deployment) leaves the restart in place, which is the previous
|
|
63
|
+
// behaviour.
|
|
64
|
+
u._applyStartsRollout = false;
|
|
65
|
+
if (!dryRun && u.workload && u.kind !== 'cronjob') {
|
|
66
|
+
try {
|
|
67
|
+
const before = await d.kubectl.runningImage({ workload: u.workload, kind: u.kind, context: u.defaults.context, namespace: u.defaults.namespace });
|
|
68
|
+
u._applyStartsRollout = before !== `${u.repoUri}:${sha}`;
|
|
69
|
+
} catch { u._applyStartsRollout = false; }
|
|
70
|
+
}
|
|
55
71
|
for (const f of files) await d.kubectl.applyFile({ file: f, context: u.defaults.context, namespace: u.defaults.namespace, dryRun });
|
|
56
72
|
} else if (step.kind === 'rollout') {
|
|
57
|
-
try { await d.kubectl.rollout({ deployment: u.workload, context: u.defaults.context, namespace: u.defaults.namespace, dryRun }); }
|
|
73
|
+
try { await d.kubectl.rollout({ deployment: u.workload, context: u.defaults.context, namespace: u.defaults.namespace, dryRun, restart: !u._applyStartsRollout }); }
|
|
58
74
|
catch (err) { await d.kubectl.rolloutUndo({ deployment: u.workload, context: u.defaults.context, namespace: u.defaults.namespace, dryRun }); throw err; }
|
|
59
75
|
}
|
|
60
76
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
let _run = require('./exec').run; function _withRun(fn) { _run = fn; }
|
|
2
2
|
const ns = (c, n) => ['-n', n, '--context', c];
|
|
3
3
|
function applyFile({ file, context, namespace, dryRun }) { return _run('kubectl', ['apply', '-f', file, ...ns(context, namespace)], { dryRun }); }
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// `restart: false` waits without restarting. Used when the preceding apply
|
|
5
|
+
// stamped a new image SHA and therefore already started a rollout — issuing
|
|
6
|
+
// `rollout restart` on top of that produces a SECOND ReplicaSet and a second
|
|
7
|
+
// pod replacement, doubling the disruption window on every deploy.
|
|
8
|
+
async function rollout({ deployment, context, namespace, dryRun, restart = true }) {
|
|
9
|
+
if (restart) await _run('kubectl', ['rollout', 'restart', `deployment/${deployment}`, ...ns(context, namespace)], { dryRun });
|
|
6
10
|
return _run('kubectl', ['rollout', 'status', `deployment/${deployment}`, '--timeout=180s', ...ns(context, namespace)], { dryRun });
|
|
7
11
|
}
|
|
8
12
|
function rolloutUndo({ deployment, context, namespace, dryRun }) { return _run('kubectl', ['rollout', 'undo', `deployment/${deployment}`, ...ns(context, namespace)], { dryRun }); }
|