mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-02 15:56:59 +08:00
feat: ship verified platform upgrades with channel bundle releases
Package production dependencies per architecture for online and offline upgrades. Validate dependencies and isolated backend startup before readiness, repair once when permitted, and preserve service/data through failed preparation or rollback. Publish release bundles with master images and expose an opt-in develop build sharing the development index across Alpine and Debian images.
This commit is contained in:
@@ -322,6 +322,10 @@ test(
|
||||
async (t) => {
|
||||
if (process.platform === 'win32') return t.skip('POSIX process groups');
|
||||
const { runProcess } = require('../../dist/internal/runtime/process');
|
||||
const marker = path.join(sandbox(t), 'timeout');
|
||||
const controller = new AbortController();
|
||||
const guard = setTimeout(() => controller.abort(), 4000);
|
||||
t.after(() => clearTimeout(guard));
|
||||
let descendant;
|
||||
t.after(() => {
|
||||
if (descendant)
|
||||
@@ -329,13 +333,17 @@ test(
|
||||
process.kill(descendant, 'SIGKILL');
|
||||
} catch {}
|
||||
});
|
||||
// Start the deadline only after the descendant installed its handlers.
|
||||
// Cold Node startup under parallel load need not fit in 350 milliseconds.
|
||||
const grandchild =
|
||||
'process.on("SIGINT",()=>{});process.on("SIGTERM",()=>{});console.log(process.pid);setInterval(()=>{},1000)';
|
||||
'process.on("SIGINT",()=>{});process.on("SIGTERM",()=>{});console.log(process.pid);require("node:fs").writeSync(3,"T");setInterval(()=>{},1000)';
|
||||
const parent = `require('node:child_process').spawn(process.execPath,['-e',${JSON.stringify(
|
||||
grandchild,
|
||||
)}],{stdio:['ignore',1,2]});setTimeout(()=>process.exit(0),100);`;
|
||||
)}],{stdio:['ignore',1,2,3]});setTimeout(()=>process.exit(0),100);`;
|
||||
const result = await runProcess(process.execPath, ['-e', parent], {
|
||||
timeoutMs: 350,
|
||||
timeoutControl: { marker },
|
||||
signal: controller.signal,
|
||||
graceMs: 100,
|
||||
output: (chunk) => {
|
||||
const pid = Number(chunk.toString().trim());
|
||||
@@ -345,6 +353,7 @@ test(
|
||||
assert.equal(result.code, 124);
|
||||
assert.equal(result.timedOut, true);
|
||||
assert.ok(descendant);
|
||||
assert.equal(fs.existsSync(marker), true);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -20,6 +20,40 @@ const {
|
||||
sourceCommit,
|
||||
} = require('../../../test/helpers/upgrade-fixture.cjs');
|
||||
|
||||
test('CLI service startup drops operation-only upgrade variables and preserves user configuration', async (t) => {
|
||||
const ctx = await fixture(t);
|
||||
ctx.env.CALLS = path.join(ctx.root, 'runtime.jsonl');
|
||||
ctx.env.QL_UPGRADE_FILE = '/old/offline.tar.gz';
|
||||
ctx.env.QL_UPGRADE_REPAIR_DEPS = '1';
|
||||
ctx.env.QL_UPGRADE_LAUNCHER_PID = '12345';
|
||||
ctx.env.QA_USER_SETTING = 'preserved';
|
||||
ctx.env.HTTPS_PROXY = 'http://127.0.0.1:7890';
|
||||
await stub(
|
||||
ctx,
|
||||
'pm2',
|
||||
`require('node:fs').appendFileSync(process.env.CALLS,JSON.stringify({
|
||||
file:process.env.QL_UPGRADE_FILE??null,repair:process.env.QL_UPGRADE_REPAIR_DEPS??null,
|
||||
launcher:process.env.QL_UPGRADE_LAUNCHER_PID??null,user:process.env.QA_USER_SETTING,
|
||||
proxy:process.env.HTTPS_PROXY,
|
||||
})+'\\n');`,
|
||||
);
|
||||
await startPanel(ctx);
|
||||
for (const runtime of (await fs.readFile(ctx.env.CALLS, 'utf8'))
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(JSON.parse))
|
||||
assert.deepEqual(runtime, {
|
||||
file: null,
|
||||
repair: null,
|
||||
launcher: null,
|
||||
user: 'preserved',
|
||||
proxy: 'http://127.0.0.1:7890',
|
||||
});
|
||||
assert.equal(ctx.env.QL_UPGRADE_FILE, '/old/offline.tar.gz');
|
||||
assert.equal(ctx.env.QL_UPGRADE_REPAIR_DEPS, '1');
|
||||
assert.equal(ctx.env.QL_UPGRADE_LAUNCHER_PID, '12345');
|
||||
});
|
||||
|
||||
async function fixture(t) {
|
||||
t.mock.method(
|
||||
require('../../dist/internal/maintenance/upgradeArtifacts.cjs'),
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
test('the standalone operational CLI verifier carries its archive parser without panel dependencies', (t) => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-cli-bundle-'));
|
||||
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
|
||||
const filename = path.join(directory, 'platformBundle.cjs');
|
||||
fs.copyFileSync(
|
||||
path.resolve(
|
||||
__dirname,
|
||||
'../../dist/internal/maintenance/platformBundle.cjs',
|
||||
),
|
||||
filename,
|
||||
);
|
||||
const code = `
|
||||
const Module=require('node:module'),load=Module._load;
|
||||
Module._load=function(name,...args){
|
||||
if(name!==process.argv[1]&&!name.startsWith('node:')&&!Module.builtinModules.includes(name))throw new Error('External dependency: '+name);
|
||||
return load.call(this,name,...args);
|
||||
};
|
||||
const bundle=require(process.argv[1]);
|
||||
if(typeof bundle.stageBundle!=='function')throw new Error('Missing verifier');
|
||||
bundle.runtimeTarget().then(target=>console.log(bundle.targetKey(target))).catch(e=>{console.error(e);process.exitCode=1});
|
||||
`;
|
||||
const result = spawnSync(process.execPath, ['-e', code, filename], {
|
||||
encoding: 'utf8',
|
||||
env: { ...process.env, NODE_PATH: '' },
|
||||
});
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, new RegExp(`^${process.platform}-`));
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const {
|
||||
manualUpgradeFixture,
|
||||
} = require('../../../test/helpers/manual-upgrade-fixture.cjs');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { reloadPanel } = require('../../dist/internal/maintenance/upgrade');
|
||||
const operator = require('../../dist/internal/maintenance/operator');
|
||||
const artifacts = require('../../dist/internal/maintenance/upgradeArtifacts.cjs');
|
||||
|
||||
for (const status of ['ready', 'failed', 'completed', 'absent'])
|
||||
for (const wrongVersion of [false, true])
|
||||
test(`CLI validates and records manual reload after ${status}; wrong version=${wrongVersion}`, async (t) => {
|
||||
const f = await manualUpgradeFixture(t, wrongVersion);
|
||||
await fs.writeFile(
|
||||
path.join(f.root, 'package.json'),
|
||||
'{"qinglongUpgradeFormat":2}',
|
||||
);
|
||||
const file = path.join(f.tmp, 'panel-upgrade.json');
|
||||
if (status === 'absent') await fs.unlink(file);
|
||||
else
|
||||
await fs.writeFile(
|
||||
file,
|
||||
JSON.stringify({
|
||||
...(await f.state()),
|
||||
status,
|
||||
error: 'old error',
|
||||
version: '9.9.9',
|
||||
sourceCommit: 'f'.repeat(40),
|
||||
}),
|
||||
);
|
||||
t.mock.method(operator, 'stopPanel', async () => {});
|
||||
t.mock.method(operator, 'startPanel', async () => ({
|
||||
manager: 'fixture',
|
||||
}));
|
||||
t.mock.method(artifacts, 'waitForHealth', async () => {});
|
||||
const operation = reloadPanel(
|
||||
createContext({ root: f.root }, f.env),
|
||||
'system',
|
||||
);
|
||||
if (wrongVersion)
|
||||
await assert.rejects(operation, /启动版本与更新包不一致/);
|
||||
else await operation;
|
||||
const state = await f.state();
|
||||
assert.equal(state.status, wrongVersion ? 'failed' : 'completed');
|
||||
assert.equal(state.sourceCommit, f.expected.sourceCommit);
|
||||
assert.equal(state.version, f.expected.version);
|
||||
assert.notEqual(state.error, 'old error');
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(f.root, 'static/build/app.js'), 'utf8'),
|
||||
wrongVersion ? 'old backend' : 'new backend',
|
||||
);
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(f.root, 'data/keep'), 'utf8'),
|
||||
'preserve data',
|
||||
);
|
||||
});
|
||||
|
||||
for (const wrongVersion of [false, true]) {
|
||||
test(`operational CLI synchronizes prepared jobs and verifies startup before committing; wrong version=${wrongVersion}`, async (t) => {
|
||||
const f = await manualUpgradeFixture(t, wrongVersion);
|
||||
const context = createContext({ root: f.root }, f.env);
|
||||
const timeouts = [];
|
||||
t.mock.method(artifacts, 'waitForHealth', async (_env, timeout) => {
|
||||
timeouts.push(timeout);
|
||||
});
|
||||
t.mock.method(operator, 'stopPanel', async () => {
|
||||
assert.equal((await f.state()).status, 'restarting');
|
||||
});
|
||||
t.mock.method(operator, 'startPanel', async () => ({ manager: 'fixture' }));
|
||||
const operation = reloadPanel(context, 'system');
|
||||
if (wrongVersion) await assert.rejects(operation, /启动版本与更新包不一致/);
|
||||
else await operation;
|
||||
assert.ok(timeouts.length > 0);
|
||||
assert.ok(
|
||||
timeouts.every((timeout) => timeout === undefined),
|
||||
'use the shared ARMv6/default startup deadline',
|
||||
);
|
||||
assert.equal(
|
||||
(await f.state()).status,
|
||||
wrongVersion ? 'failed' : 'completed',
|
||||
);
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(f.root, 'static/build/app.js'), 'utf8'),
|
||||
wrongVersion ? 'old backend' : 'new backend',
|
||||
);
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(f.root, 'data/keep'), 'utf8'),
|
||||
'preserve data',
|
||||
);
|
||||
if (wrongVersion)
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(f.root, 'node_modules/old'), 'utf8'),
|
||||
'old dependency',
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user