Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e0dd211
fix(cloudui): an update switches CloudUI to the new build atomically,…
MorningLightMountain713 Oct 22, 2026
90a5616
test(flux): getFluxInfo's tests stub Docker and MongoDB
MorningLightMountain713 Oct 25, 2026
b21a6b6
feat(cloudui): the installed UI's release tag is in CloudUI/tag and /…
MorningLightMountain713 Oct 25, 2026
4bd71c8
fix(cloudui): a download that stops moving fails the update, and a sl…
MorningLightMountain713 Oct 25, 2026
1008c04
fix(cloudui): a run stopped by a service manager still removes its files
MorningLightMountain713 Oct 25, 2026
ef3819f
fix(cloudui): FluxOS's UI update runs in the background at boot, with…
MorningLightMountain713 Oct 25, 2026
99f2916
fix(cloudui): a stop signal sent twice still lets the run remove its …
MorningLightMountain713 Oct 25, 2026
52b6dee
test(cloudui): each part of the script's signal handling fails a test…
MorningLightMountain713 Oct 25, 2026
bc03cd2
test(cloudui): the script tests stop the timeout of every run they wa…
MorningLightMountain713 Nov 16, 2026
844c108
test(flux): the chain streaming preparation tests stub the app networks
MorningLightMountain713 Nov 16, 2026
aeb04d3
chore(cloudui): git and eslint ignore the root CloudUI and .cloudui, …
MorningLightMountain713 Nov 16, 2026
8b59a25
fix(cloudui): the UI rebuild answers at once while another update is …
MorningLightMountain713 Nov 16, 2026
54a2834
fix(cloudui): an update leaves an installed release alone; the UI reb…
MorningLightMountain713 Nov 16, 2026
97226c6
test(cloudui): the runner and rebuild route tests describe the script…
MorningLightMountain713 Nov 16, 2026
a5496d0
test(harness): 2803 sends its registration once the shaped node holds…
MorningLightMountain713 Nov 16, 2026
2a9002c
fix(cloudui): the boot check installs over a CloudUI holding only its…
MorningLightMountain713 Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/CloudUI/
/CloudUI
/.cloudui/
/config/userconfig.js
/lib/daemonrpc/
/tests/e2e/
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ tests/images/.package_hash
dev/
CLAUDE.md

# CloudUI - Pre-built frontend (downloaded via npm run update:cloudui)
CloudUI/
# CloudUI - Pre-built frontend (downloaded via npm run update:cloudui): a symlink to
# the installed build in .cloudui/
/CloudUI
/.cloudui/

# compiled test-app fixture binary (built via test-infra/test-app/build.sh)
test-infra/test-app/test-app
Expand Down
147 changes: 113 additions & 34 deletions ZelBack/src/services/cloudUIUpdateService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = require('config');
const fs = require('fs');
const path = require('path');
const { execFile } = require('child_process');
const { spawn } = require('child_process');
const axios = require('axios');
const log = require('../lib/log');

Expand All @@ -10,16 +10,23 @@ const RELEASE_API = `${config.github.apiBaseUrl}/repos/${REPO}/releases/latest`;
const PROJECT_ROOT = path.join(__dirname, '..', '..', '..');
const CLOUDUI_DIR = path.join(PROJECT_ROOT, 'CloudUI');
const VERSION_FILE = path.join(CLOUDUI_DIR, 'version');
const TAG_FILE = path.join(CLOUDUI_DIR, 'tag');
// Written by the update script beside the build's own files.
const METADATA_FILES = ['version', 'tag'];

// The part of the script's output kept for the log: a download's progress meter runs for
// as long as the download does.
const MAX_OUTPUT_CHARS = 4000;

// The script's exit status for a run started with --if-idle while another run holds its lock.
const SCRIPT_BUSY = 75;

// ArcaneOS nodes have watchdog handling CloudUI updates
const isArcaneOS = Boolean(process.env.FLUXOS_PATH);

// The run in progress, if there is one. The script removes the served directory
// before it copies the new one into place, so two runs at once means the second
// one's removal lands inside the first one's copy - and the run that wrote the
// version file is then not the run that wrote the files beside it. A second
// caller joins the run already going rather than starting another, which is
// also the honest answer: the rebuild it asked for is happening.
// This process's run in progress, if there is one: a promise of its outcome, 'installed',
// 'failed' or 'busy'. runUpdateScript joins it rather than starting another, and
// rebuildIfIdle answers 'busy' while it is set.
let updateInFlight = null;

/**
Expand All @@ -32,8 +39,7 @@ function cloudUIExists() {
return false;
}
const files = fs.readdirSync(CLOUDUI_DIR);
// Check if there are files (not just version file)
return files.length > 1 || (files.length === 1 && files[0] !== 'version');
return files.some((file) => !METADATA_FILES.includes(file));
} catch (error) {
log.error(`Error checking CloudUI folder: ${error.message}`);
return false;
Expand All @@ -56,6 +62,22 @@ function getLocalVersionHash() {
}
}

/**
* Gets the release tag of the installed build from the tag file
* @returns {string|null}
*/
function getLocalVersionTag() {
try {
if (!fs.existsSync(TAG_FILE)) {
return null;
}
return fs.readFileSync(TAG_FILE, 'utf8').trim() || null;
} catch (error) {
log.error(`Error reading local tag file: ${error.message}`);
return null;
}
}

/**
* Fetches the latest release information from GitHub
* @returns {Promise<{hash: string, tag: string}|null>}
Expand Down Expand Up @@ -123,51 +145,94 @@ function watchdogManagesCloudUI() {
}

/**
* Executes the update:cloudui script
* @returns {Promise<boolean>}
* Executes the update:cloudui script. A run already in progress in this process is joined,
* whatever its options; one in another process (the watchdog's, or one started by hand) is
* waited for.
* @param {object} [options]
* @param {boolean} [options.force] Passes --force, so a release that CloudUI/version
* already names is installed again.
* @returns {Promise<boolean>} Whether the script installed the release.
*/
function runUpdateScript() {
function runUpdateScript({ force = false } = {}) {
if (updateInFlight) {
log.info('CloudUI: an update is already running, waiting for it rather than starting another');
return updateInFlight;
} else {
updateInFlight = startUpdateScript({ force }).finally(() => { updateInFlight = null; });
}

return updateInFlight.then((outcome) => outcome === 'installed');
}

/**
* Executes the update:cloudui script with --force, installing the release even where
* CloudUI/version already names it, unless another run is in progress, in this process or
* any other, and then answers at once without waiting for it.
* @returns {Promise<'installed'|'failed'|'busy'>}
*/
function rebuildIfIdle() {
if (updateInFlight) {
log.info('CloudUI: an update is already running, not starting a rebuild');
return Promise.resolve('busy');
}

updateInFlight = startUpdateScript().finally(() => { updateInFlight = null; });
updateInFlight = startUpdateScript({ ifIdle: true, force: true }).finally(() => { updateInFlight = null; });

return updateInFlight;
}

/**
* Runs the update:cloudui script, unconditionally. Reached only through
* runUpdateScript, which is what keeps two of them from overlapping.
* @returns {Promise<boolean>}
* Runs the update:cloudui script, unconditionally. Reached only through runUpdateScript
* and rebuildIfIdle, which keep two of them in this process from overlapping.
*
* There is no time limit: the script gives up on a download that stops moving, and a
* slow one takes as long as it takes.
* @param {object} [options]
* @param {boolean} [options.ifIdle] Passes --if-idle, so a run another process holds the
* lock against exits at once.
* @param {boolean} [options.force] Passes --force, so a release that is already installed
* is installed again.
* @returns {Promise<'installed'|'failed'|'busy'>}
*/
function startUpdateScript() {
function startUpdateScript({ ifIdle = false, force = false } = {}) {
return new Promise((resolve) => {
log.info('CloudUI: Running update script...');

// The script is handed the API host rather than knowing one. Config is the single
// source of truth for every endpoint a node reaches, so a hardcoded URL in the script,
// or one taken from the environment, would sit outside it and be unreachable by the
// harness.
execFile('npm', ['run', 'update:cloudui', '--', config.github.apiBaseUrl], { cwd: PROJECT_ROOT, timeout: 300000 }, (error, stdout, stderr) => {
if (error) {
log.error(`CloudUI update script error: ${error.message}`);
if (stderr) {
log.error(`CloudUI update stderr: ${stderr}`);
}
resolve(false);
const args = ['run', 'update:cloudui', '--', config.github.apiBaseUrl];
if (ifIdle) args.push('--if-idle');
if (force) args.push('--force');
const child = spawn('npm', args, {
cwd: PROJECT_ROOT,
stdio: ['ignore', 'pipe', 'pipe'],
});
let output = '';
const keep = (chunk) => { output = (output + chunk).slice(-MAX_OUTPUT_CHARS); };
child.stdout.on('data', keep);
child.stderr.on('data', keep);

child.on('error', (error) => {
log.error(`CloudUI update script error: ${error.message}`);
resolve('failed');
});
child.on('close', (code, signal) => {
const lastLines = output.trim().split('\n').slice(-5).join('\n');
if (code === 0) {
log.info('CloudUI: Update script completed');
if (lastLines) log.info(`CloudUI update output:\n${lastLines}`);
resolve('installed');
return;
}

log.info('CloudUI: Update script completed');
if (stdout) {
// Log last few lines of output
const lines = stdout.trim().split('\n');
const lastLines = lines.slice(-5).join('\n');
log.info(`CloudUI update output:\n${lastLines}`);
if (ifIdle && code === SCRIPT_BUSY) {
log.info('CloudUI: another update is in progress, the rebuild did not start');
resolve('busy');
return;
}
resolve(true);
log.error(`CloudUI update script ${signal ? `killed by ${signal}` : `exited with code ${code}`}`);
if (lastLines) log.error(`CloudUI update output:\n${lastLines}`);
resolve('failed');
});
});
}
Expand All @@ -189,9 +254,11 @@ async function checkAndUpdateCloudUI() {
// Check if CloudUI folder exists with content
const exists = cloudUIExists();

// A CloudUI holding only its version and tag files still names the release, so the
// install is forced past the script's already-installed check.
if (!exists) {
log.info('CloudUI: Folder missing or empty, installing...');
const success = await runUpdateScript();
const success = await runUpdateScript({ force: true });
if (success) {
log.info('CloudUI: Installation completed successfully');
} else {
Expand Down Expand Up @@ -249,15 +316,27 @@ async function checkAndUpdateCloudUI() {
}
}

/**
* Starts the update check in the background and returns at once, so a slow download
* holds up nothing that starts after it. The check logs its own outcome.
*/
function startCloudUIUpdateCheck() {
checkAndUpdateCloudUI();
}

module.exports = {
checkAndUpdateCloudUI,
startCloudUIUpdateCheck,
cloudUIExists,
runUpdateScript,
rebuildIfIdle,
watchdogManagesCloudUI,
getLocalVersionHash,
getLocalVersionTag,
getRemoteVersionInfo,
// Exported for testing
CLOUDUI_DIR,
VERSION_FILE,
TAG_FILE,
isArcaneOS,
};
21 changes: 17 additions & 4 deletions ZelBack/src/services/fluxService.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,21 @@ async function rebuildUi(req, res) {
// repository, so rebuilding it means taking that release again through the one path
// that knows which host to ask - the same path the periodic check uses.
//
// Unconditionally, unlike the periodic check: that one stands down when the
// Whatever is on disk, unlike the periodic check: that one stands down when the
// installed hash already matches the release, and a CloudUI which is damaged
// rather than out of date matches all the same. Repairing one is what this is
// for, so it takes the release again whatever is on disk.
const rebuilt = await cloudUIUpdateService.runUpdateScript();
// for, so it takes the release again.
//
// Not while another update is in progress: the caller is answered at once rather
// than held behind it, and that update installs the release anyway.
const outcome = await cloudUIUpdateService.rebuildIfIdle();

if (!rebuilt) {
if (outcome === 'busy') {
const errMessage = messageHelper.createErrorMessage('A Flux UI update is already in progress on this node, try again once it has finished');
return res.json(errMessage);
}

if (outcome !== 'installed') {
const errMessage = messageHelper.createErrorMessage('Error rebuilding Flux UI, see the node log for what the fetch reported');
return res.json(errMessage);
}
Expand Down Expand Up @@ -1557,6 +1565,11 @@ async function getFluxInfo(req, res) {
throw versionRes.data;
}
info.flux.version = versionRes.data;
// The installed UI release; each is null where the update script has not written it.
info.flux.cloudUI = {
tag: cloudUIUpdateService.getLocalVersionTag(),
sha256: cloudUIUpdateService.getLocalVersionHash(),
};
const nodeJsVersionsRes = await getNodeJsVersions();
if (nodeJsVersionsRes.status === 'error') {
throw nodeJsVersionsRes.data;
Expand Down
2 changes: 1 addition & 1 deletion ZelBack/src/services/serviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ async function startFluxFunctions() {

// Check and update CloudUI if needed (for legacy nodes without watchdog)
log.info('Checking CloudUI installation...');
await cloudUIUpdateService.checkAndUpdateCloudUI();
cloudUIUpdateService.startCloudUIUpdateCheck();
startRouterAddressUpkeep();
await fluxNetworkHelper.addFluxNodeServiceIpToLoopback();
await fluxNetworkHelper.allowOnlyDockerNetworksToFluxNodeService();
Expand Down
Loading
Loading