fix(authz): make failed deployment retries safe
This commit is contained in:
parent
3acf4a1504
commit
3edca726c1
2 changed files with 18 additions and 2 deletions
|
|
@ -259,8 +259,14 @@ function backupFile(source, backup, records) {
|
||||||
const stat = fs.lstatSync(source);
|
const stat = fs.lstatSync(source);
|
||||||
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("backup_source_not_regular_file");
|
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("backup_source_not_regular_file");
|
||||||
fs.mkdirSync(path.dirname(backup), { recursive: true, mode: 0o700 });
|
fs.mkdirSync(path.dirname(backup), { recursive: true, mode: 0o700 });
|
||||||
fs.copyFileSync(source, backup, fs.constants.COPYFILE_EXCL);
|
if (fs.existsSync(backup)) {
|
||||||
fs.chmodSync(backup, stat.mode & 0o777);
|
const backupStat = fs.lstatSync(backup);
|
||||||
|
if (!backupStat.isFile() || backupStat.isSymbolicLink()) throw new Error("backup_conflict");
|
||||||
|
if (!fs.readFileSync(source).equals(fs.readFileSync(backup))) throw new Error("backup_conflict");
|
||||||
|
} else {
|
||||||
|
fs.copyFileSync(source, backup, fs.constants.COPYFILE_EXCL);
|
||||||
|
fs.chmodSync(backup, stat.mode & 0o777);
|
||||||
|
}
|
||||||
records.push({ source, backup, existed: true, mode: stat.mode & 0o777 });
|
records.push({ source, backup, existed: true, mode: stat.mode & 0o777 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,5 +203,15 @@ test("existing service update restores every changed file when acceptance fails"
|
||||||
assert.equal(fs.readFileSync(path.join(installRoot, "server.js"), "utf8"), "old server\n");
|
assert.equal(fs.readFileSync(path.join(installRoot, "server.js"), "utf8"), "old server\n");
|
||||||
assert.equal(fs.existsSync(path.join(installRoot, "alias.json")), false);
|
assert.equal(fs.existsSync(path.join(installRoot, "alias.json")), false);
|
||||||
assert.equal(fs.readFileSync(path.join(unitDir, "guanghu-ai-discovery.service"), "utf8"), "old unit\n");
|
assert.equal(fs.readFileSync(path.join(unitDir, "guanghu-ai-discovery.service"), "utf8"), "old unit\n");
|
||||||
|
const retry = await provision({ target: "JD-FD-PRIMARY", action: "provision-approved-architecture", resource: `${updateRequestId}@${commit}` }, {
|
||||||
|
repoDir, releasesDir, unitDir, receiptsDir, installRootOverride: installRoot,
|
||||||
|
run: async (file, args) => ({ stdout: args.includes("rev-parse") ? `${commit}\n` : "" }),
|
||||||
|
getJson: async () => ({ ok: true }),
|
||||||
|
healthAttempts: 1,
|
||||||
|
healthDelayMs: 0,
|
||||||
|
});
|
||||||
|
assert.equal(retry.ok, true);
|
||||||
|
assert.equal(fs.readFileSync(path.join(installRoot, "server.js"), "utf8"), "new server\n");
|
||||||
|
assert.equal(fs.existsSync(path.join(installRoot, "alias.json")), true);
|
||||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue