fix: keep app online during deploy preparation
This commit is contained in:
1 parent
1f4aadb3d7
commit
828fda63e7
2 files changed
+38
-18
No files matched your search
@@ -6,6 +6,7 @@ const liveVar = "${" + "LIVE}";
|
||||
const stageVar = "${" + "STAGE}";
|
||||
const userVar = "${" + "DEPLOY_USER}";
|
||||
const groupVar = "${" + "DEPLOY_GROUP}";
|
||||
const cutoverStartedVar = "${" + "CUTOVER_STARTED}";
|
||||
|
||||
function toContainLiteral(workflow: string, literal: string) {
|
||||
return workflow.indexOf(literal) >= 0;
|
||||
@@ -66,7 +67,7 @@ describe("production deploy workflow", () => {
|
||||
expect(deployJob).toContain("pnpm typecheck");
|
||||
});
|
||||
|
||||
it("swaps a built .next artifact during a short service cutover", () => {
|
||||
it("migrates while the current app is online, then swaps the built artifact", () => {
|
||||
expect(deployJob).toContain("mv .next .next.prev");
|
||||
expect(toContainLiteral(deployJob, `mv "${stageVar}/.next" .next`)).toBe(
|
||||
true,
|
||||
@@ -84,12 +85,31 @@ describe("production deploy workflow", () => {
|
||||
startLabelAt,
|
||||
);
|
||||
expect(buildAt).toBeGreaterThan(-1);
|
||||
expect(stopAt).toBeGreaterThan(buildAt);
|
||||
expect(migrateAt).toBeGreaterThan(stopAt);
|
||||
expect(startLabelAt).toBeGreaterThan(migrateAt);
|
||||
expect(migrateAt).toBeGreaterThan(buildAt);
|
||||
expect(stopAt).toBeGreaterThan(migrateAt);
|
||||
expect(startLabelAt).toBeGreaterThan(stopAt);
|
||||
expect(startAt).toBeGreaterThan(startLabelAt);
|
||||
});
|
||||
|
||||
it("does not restart the healthy app when deployment fails before cutover", () => {
|
||||
const handlerStart = deployJob.indexOf("error_handler() {");
|
||||
const handlerEnd = deployJob.indexOf("trap 'error_handler", handlerStart);
|
||||
const handler = deployJob.slice(handlerStart, handlerEnd);
|
||||
const cutoverGuardAt = handler.indexOf(
|
||||
`if [ "${cutoverStartedVar}" = "1" ]; then`,
|
||||
);
|
||||
const restartAt = handler.indexOf("pm2 restart next", cutoverGuardAt);
|
||||
const stageCleanupAt = handler.indexOf(`if [ -n "${stageVar}"`, restartAt);
|
||||
|
||||
expect(handlerStart).toBeGreaterThan(-1);
|
||||
expect(cutoverGuardAt).toBeGreaterThan(-1);
|
||||
expect(restartAt).toBeGreaterThan(cutoverGuardAt);
|
||||
expect(stageCleanupAt).toBeGreaterThan(restartAt);
|
||||
expect(handler.slice(restartAt, stageCleanupAt)).toContain(
|
||||
"\n fi",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not override onlyBuiltDependencies (uses pnpm-workspace.yaml)", () => {
|
||||
expect(workflow).not.toContain("PNPM_CONFIG_ONLY_BUILT_DEPENDENCIES");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user