@brutalsystems/dray 0.1.10 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brutalsystems/dray",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Convention-driven multi-repo deploy orchestrator (forge for shipping)",
5
5
  "bin": {
6
6
  "dray": "bin/dray.js"
@@ -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
- async function rollout({ deployment, context, namespace, dryRun }) {
5
- await _run('kubectl', ['rollout', 'restart', `deployment/${deployment}`, ...ns(context, namespace)], { dryRun });
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 }); }