mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
* fix(devcontainer): move workspace and snapshots to Linux volumes * fix(devcontainer): exclude evaluation virtualenv from source import * fix(devcontainer): preserve WSL links during volume imports * fix(devcontainer): skip parser caches and report import progress Exclude regenerable GitNexus parser caches from every nested worktree while preserving graph databases, Git state, and local work. Report archive bytes and elapsed time every five seconds, and stream output with activity updates during longer Docker initialization stages. * fix(devcontainer): resolve workspace volume ID before startup * fix(devcontainer): relink nested worktrees and harden host imports - Relink nested worktrees whose Git pointers still name the host path (C:/..., /Users/...): match the longest existing suffix in the copy and rewrite both pointers, as `git worktree repair` would. - Fail the import when a file changes while tar reads it. bsdtar on macOS and Windows pads or truncates such files and exits 0. - Disable AppleDouble `._*` entries from macOS tar (COPYFILE_DISABLE). - Follow selected snapshot roots that are symlinks (dotfile-managed ~/.config/gh, ~/.claude.json) like the bind mounts they replace. - Keep node at UID 1000 for root host users; the Dev Containers CLI skips UID realignment for UID 0. - Make fixture modes independent of the process umask and check the no-partial-write case with lstat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(devcontainer): stage on the host and commit once at container creation initializeCommand also runs when an existing container is reopened. A developer who pulled the volume change and reopened the old bind-mount container got an import marked ready, and the eventual rebuild silently showed that stale copy. - The host now only stages the checkout into gitnexus-seed-<id> (tree/ plus a stage-complete marker written last); the helper mounts the source volume read-only. - onCreateCommand, which runs once per container creation, commits a complete stage into the empty source volume, empties the stage and repairs ownership. initializeCommand copies the host's seed-workspace.cjs into the seed volume on every start, so the commit matches devcontainer.json and works with any image. - Staging and snapshot retakes are best-effort: a failure clears its target, warns and is retried next start, so a busy host never locks out reopening an existing container. Creation without a complete stage stops at onCreateCommand with a clear message. - Snapshots are retaken while the source volume is uncommitted, and a partial snapshot is replaced instead of failing closed; snapshots are read-only host copies, so replacing them is safe. - Node writes the tar stream (ustar + PAX for long and UTF-8 names). Windows tar.exe read the file list in the ANSI code page, so any non-ASCII path failed; macOS tar added AppleDouble files; both padded or truncated a file that changed while being read. A changed file now discards that copy. The host no longer needs tar. Sockets and FIFOs are skipped, as tar did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(devcontainer): simplify importer helpers and read small files whole - tarStream reads files up to 1 MiB in one call instead of opening a stream per file: 50k files stream in 1.0 s instead of 12 s, with a byte-identical archive and unchanged change detection. - Drop copyArchive's dead `excludes` parameter; the snapshot marker is excluded through the existing predicate. - Share the source/target overlap check and the common-dir check. - Remove exports with no consumer and two comments left from the host-tar implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): skip POSIX-only tar assertions on Windows (#3835) - Address PR review feedback: the tar round-trip test ran mkfifo and asserted a 0755 mode unconditionally. Split it: UTF-8, long-name and empty-file round-trips run everywhere; POSIX mode preservation and FIFO exclusion move to a test skipped on win32, where tarStream writes 0644 by design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): skip POSIX-tooling importer tests on Windows (#3835) - Address PR review feedback: the Docker-adapter fixture assumed a POSIX PATH separator. A Windows-safe separator would not help: the fake `docker` is a shebang script Windows cannot spawn, and it runs Linux helper commands. One shared `posixOnly` skip option now covers the seven Docker-adapter tests, the bash credential test and the POSIX modes/FIFO test; all still run on Linux. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(devcontainer): keep failed snapshots retryable and nested worktrees local (#3835) Address PR review feedback: - Select snapshot roots with lstat, so a dangling or unfollowable `.claude.json` link reaches the archiver and is preserved as a link. A path under a non-directory still counts as absent. - post-create.sh publishes the one-shot identity and shareable seed markers only when /host carries its completion marker; a snapshot skipped during initialization is seeded by a later rebuild. - Remove an absolute core.worktree from each relinked nested worktree's config.worktree before Git first reads that checkout, as already done for the root configuration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): run fake-Docker importer tests only on Linux (#3835) - Address PR review feedback: on macOS the importer passes container UID 1000, and the fake Docker adapter ran finishSnapshot's chown as the unprivileged host user. The adapter emulates the Linux helper container on the host, so its seven tests now share a `linuxHelper` gate; the bash, mode and FIFO tests keep the narrower `posixOnly`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(devcontainer): run host importer tests on macOS and Windows (#3835) Address PR review feedback: the suite's platform assumptions surfaced one review finding per push. The host-side importer now runs on all three CI hosts and the tests state what each one needs. - New `host-importer` job runs initialize-volumes.test.cjs on macos-latest and windows-latest (Linux already runs every test). - The importer reads its Docker CLI from GITNEXUS_IMPORT_DOCKER (JSON argv, default docker). Windows spawn resolves only .exe/.com, so the test adapter is now a Node script on every OS instead of a shebang file on PATH. The adapter emulates the helper's find/mkdir/touch and, on Windows, snapshot finalization. - Gates: posixOnly (bash, modes, mkfifo), a symlink capability probe, and containerSide (Linux only) for code that runs only in the dev container or helper. Host staging assertions read the staged tree; the commit and 0600 snapshot modes stay in one Linux test. - seed-workspace.test.cjs is container-side, so it skips on other hosts. - The long-name round trip stays above 100 bytes (PAX) but under Windows MAX_PATH once extracted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): verify the tar stream with Python's PAX reader (#3835) Windows tar.exe converts names to the ANSI code page while extracting, so it cannot write `jegyzet-ő.md` or an emoji directory ("empty or unreadable filename") - the limitation the Node writer exists to avoid. Production never extracts with it; Docker's Go extractor does. Read the round-trip archive with Python's tarfile instead, an independent PAX reader that handles UTF-8 on every host, so the UTF-8 check also runs on Windows CI. A capability gate skips the test when no Python 3 is installed. Removing the PAX path record fails the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
421 lines
15 KiB
JavaScript
421 lines
15 KiB
JavaScript
'use strict';
|
|
// Host-side importer. Docker's copy API transfers bytes without mounting the host.
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const { execFileSync, spawn } = require('node:child_process');
|
|
const { Readable, Transform } = require('node:stream');
|
|
const { pipeline } = require('node:stream/promises');
|
|
const {
|
|
archiveEntries,
|
|
isWorkspaceExcluded,
|
|
validateGitDirectory,
|
|
STAGE_COMPLETE,
|
|
STAGE_TREE,
|
|
} = require('./seed-workspace.cjs');
|
|
|
|
const SNAPSHOT_MARKER = '.devcontainer-snapshot-v1';
|
|
// Tests replace the Docker CLI with a Node adapter (JSON argv). Windows spawn
|
|
// resolves only .exe/.com files, so a script on PATH cannot stand in for docker.
|
|
const [DOCKER, ...DOCKER_ARGS] = JSON.parse(process.env.GITNEXUS_IMPORT_DOCKER || '["docker"]');
|
|
const HOST_PATHS = [
|
|
'.claude.json',
|
|
...[
|
|
'.credentials.json',
|
|
'.claude.json',
|
|
'settings.json',
|
|
'skills',
|
|
'agents',
|
|
'memory',
|
|
'commands',
|
|
'plugins',
|
|
].map((p) => `.claude/${p}`),
|
|
...['auth.json', 'config.toml', 'plugins', 'prompts', 'memories', 'skills'].map(
|
|
(p) => `.codex/${p}`,
|
|
),
|
|
...['cli-config.json', 'mcp.json', 'rules', 'commands', 'agents', 'skills', 'plugins'].map(
|
|
(p) => `.cursor/${p}`,
|
|
),
|
|
'.config/gh',
|
|
'.claude-mem',
|
|
];
|
|
const IDENTITIES = {
|
|
ssh: '.ssh',
|
|
docker: '.docker',
|
|
aws: '.aws',
|
|
azure: '.azure',
|
|
git: '.config/git',
|
|
};
|
|
|
|
function snapshotState(root) {
|
|
const marker = path.join(root, SNAPSHOT_MARKER);
|
|
return fs.existsSync(marker) && fs.lstatSync(marker).isFile() ? 'ready' : 'stale';
|
|
}
|
|
|
|
function finishSnapshot(root, uid, gid, complete) {
|
|
if (!Number.isSafeInteger(uid) || uid < 0 || !Number.isSafeInteger(gid) || gid < 0)
|
|
throw new Error('Invalid snapshot owner');
|
|
const owner = fs.statSync(root);
|
|
if (complete || owner.uid !== uid || owner.gid !== gid) {
|
|
// Never follow host symlinks, including links whose target exists in the helper.
|
|
execFileSync('find', [root, '-xdev', '-type', 'd', '-exec', 'chmod', '700', '{}', '+']);
|
|
execFileSync('find', [root, '-xdev', '-type', 'f', '-exec', 'chmod', 'u+rw,go-rwx', '{}', '+']);
|
|
execFileSync('find', [root, '-xdev', '-exec', 'chown', '-h', `${uid}:${gid}`, '{}', '+']);
|
|
}
|
|
if (complete) {
|
|
fs.writeFileSync(
|
|
path.join(root, SNAPSHOT_MARKER),
|
|
'One-time host snapshot. Host edits are not synchronized.\n',
|
|
{ flag: 'wx', mode: 0o600 },
|
|
);
|
|
fs.chownSync(path.join(root, SNAPSHOT_MARKER), uid, gid);
|
|
}
|
|
}
|
|
|
|
// Docker's copy API takes a tar stream, written here as ustar with PAX records
|
|
// for long or non-ASCII names. Host tar is avoided: Windows tar reads file lists
|
|
// in the ANSI code page, macOS tar adds AppleDouble ._* entries, and both pad or
|
|
// truncate a file that changes while it is read.
|
|
const MAX_OCTAL_SIZE = 0o77777777777;
|
|
const tarPadding = (size) => Buffer.alloc((512 - (size % 512)) % 512);
|
|
|
|
function tarHeader(name, type, size, mode, mtime) {
|
|
const block = Buffer.alloc(512);
|
|
// Width - 1 octal digits; the zero-filled last byte terminates each field.
|
|
const octal = (offset, width, value) =>
|
|
block.write(value.toString(8).padStart(width - 1, '0'), offset, width - 1, 'ascii');
|
|
block.write(name.replace(/[^ -~]/g, '_').slice(-100), 0, 100, 'ascii'); // PAX holds the real name.
|
|
octal(100, 8, mode);
|
|
octal(108, 8, 0);
|
|
octal(116, 8, 0);
|
|
octal(124, 12, size);
|
|
octal(136, 12, mtime);
|
|
block.write(type, 156, 1, 'ascii');
|
|
block.write('ustar\x0000', 257, 8, 'ascii');
|
|
block.fill(0x20, 148, 156);
|
|
const sum = block.reduce((total, byte) => total + byte, 0);
|
|
block.write(`${sum.toString(8).padStart(6, '0')}\0 `, 148, 8, 'ascii');
|
|
return block;
|
|
}
|
|
|
|
function paxRecord(key, value) {
|
|
const body = ` ${key}=${value}\n`;
|
|
const bytes = Buffer.byteLength(body);
|
|
let length = bytes + 1;
|
|
while (String(length).length + bytes !== length) length = String(length).length + bytes;
|
|
return `${length}${body}`;
|
|
}
|
|
|
|
async function* tarStream(source, names) {
|
|
for (const name of names) {
|
|
const file = path.join(source, name);
|
|
const before = fs.statSync(file, { throwIfNoEntry: false });
|
|
const directory = before?.isDirectory();
|
|
if (!directory && !before?.isFile())
|
|
throw new Error(`${file} changed during the import; stop host writers and retry`);
|
|
// Windows reports 0666/0777 modes; normalizeGit restores tracked executable bits.
|
|
const mode = process.platform === 'win32' ? (directory ? 0o755 : 0o644) : before.mode & 0o777;
|
|
const mtime = Math.max(0, Math.floor(before.mtimeMs / 1000));
|
|
const size = directory ? 0 : before.size;
|
|
const entry = directory ? `${name}/` : name;
|
|
const records = [];
|
|
if (!/^[ -~]{1,100}$/.test(entry)) records.push(paxRecord('path', entry));
|
|
if (size > MAX_OCTAL_SIZE) records.push(paxRecord('size', String(size)));
|
|
if (records.length) {
|
|
const body = Buffer.from(records.join(''));
|
|
yield tarHeader('PaxHeader', 'x', body.length, 0o644, mtime);
|
|
yield body;
|
|
yield tarPadding(body.length);
|
|
}
|
|
yield tarHeader(entry, directory ? '5' : '0', size > MAX_OCTAL_SIZE ? 0 : size, mode, mtime);
|
|
if (directory) continue;
|
|
let read = 0;
|
|
// Reading a small file whole is ~10x faster than opening a stream for it.
|
|
const chunks =
|
|
size <= 1 << 20
|
|
? [fs.readFileSync(file)]
|
|
: fs.createReadStream(file, { highWaterMark: 1 << 20 });
|
|
for await (const chunk of chunks) {
|
|
read += chunk.length;
|
|
if (read > size) break;
|
|
yield chunk;
|
|
}
|
|
const after = fs.statSync(file, { throwIfNoEntry: false });
|
|
if (read !== size || after?.size !== size || after.mtimeMs !== before.mtimeMs)
|
|
throw new Error(`${file} changed during the import; stop host writers and retry`);
|
|
yield tarPadding(size);
|
|
}
|
|
yield Buffer.alloc(1024);
|
|
}
|
|
|
|
function startProgress(label, details = () => '', intervalMs = 5000) {
|
|
const started = performance.now();
|
|
const report = (status) => {
|
|
const elapsed = ((performance.now() - started) / 1000).toFixed(1);
|
|
console.log(`[volumes] ${label}: ${status}; ${elapsed}s elapsed${details()}`);
|
|
};
|
|
report('starting');
|
|
const timer = setInterval(() => report('working'), intervalMs);
|
|
return (status) => {
|
|
clearInterval(timer);
|
|
report(status);
|
|
};
|
|
}
|
|
|
|
function childDone(child, name) {
|
|
return new Promise((resolve, reject) => {
|
|
child.once('error', reject);
|
|
child.once('close', (code, signal) =>
|
|
code === 0 ? resolve() : reject(new Error(`${name} exited ${signal || code}`)),
|
|
);
|
|
});
|
|
}
|
|
|
|
async function runWithProgress(label, args, input) {
|
|
const finish = startProgress(label);
|
|
const child = spawn(DOCKER, [...DOCKER_ARGS, ...args], {
|
|
stdio: [input === undefined ? 'ignore' : 'pipe', 'inherit', 'inherit'],
|
|
});
|
|
try {
|
|
const done = childDone(child, label);
|
|
const written =
|
|
input === undefined ? Promise.resolve() : pipeline(Readable.from([input]), child.stdin);
|
|
await Promise.all([done, written]);
|
|
finish('done');
|
|
} catch (error) {
|
|
child.kill();
|
|
finish('failed');
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async function copyArchive(source, entries, destination, exclude = () => false) {
|
|
if (!entries.length) return;
|
|
const links = [];
|
|
let queued = 0;
|
|
let bytes = 0;
|
|
let skipped = 0;
|
|
const finish = startProgress(
|
|
`Archive to ${destination.slice(destination.indexOf(':') + 1)}`,
|
|
() =>
|
|
`; ${queued} entries queued, ${links.length} symlinks, ${skipped} excluded paths; ${(bytes / 1024 ** 2).toFixed(1)} MiB streamed to Docker`,
|
|
);
|
|
const listing = archiveEntries(source, entries, {
|
|
links,
|
|
exclude: (relative) => {
|
|
const omit = exclude(relative);
|
|
if (omit) skipped++;
|
|
return omit;
|
|
},
|
|
});
|
|
const copy = spawn(DOCKER, [...DOCKER_ARGS, 'cp', '-', destination], {
|
|
stdio: ['pipe', 'inherit', 'inherit'],
|
|
});
|
|
const meter = new Transform({
|
|
transform(chunk, encoding, callback) {
|
|
bytes += chunk.length;
|
|
callback(null, chunk);
|
|
},
|
|
});
|
|
try {
|
|
const names = (function* () {
|
|
for (const entry of listing) {
|
|
queued++;
|
|
yield entry;
|
|
}
|
|
})();
|
|
await Promise.all([
|
|
childDone(copy, 'docker cp'),
|
|
pipeline(Readable.from(tarStream(fs.realpathSync(source), names)), meter, copy.stdin),
|
|
]);
|
|
if (links.length) {
|
|
const separator = destination.indexOf(':');
|
|
await runWithProgress(
|
|
'Restoring symlinks',
|
|
[
|
|
'exec',
|
|
'-i',
|
|
destination.slice(0, separator),
|
|
'node',
|
|
'/tmp/seed-workspace.cjs',
|
|
'--restore-links',
|
|
destination.slice(separator + 1),
|
|
],
|
|
JSON.stringify(links),
|
|
);
|
|
}
|
|
finish('done');
|
|
} catch (error) {
|
|
copy.kill();
|
|
finish('failed');
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async function initialize(
|
|
id,
|
|
mode = 'source',
|
|
workspace = path.resolve(__dirname, '..'),
|
|
home = os.homedir(),
|
|
) {
|
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,100}$/.test(id || '') || !['source', 'native'].includes(mode))
|
|
throw new Error('Usage: initialize-volumes.cjs DEVCONTAINER_ID [source|native]');
|
|
const docker = (...args) =>
|
|
execFileSync(DOCKER, [...DOCKER_ARGS, ...args], {
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'inherit'],
|
|
}).trim();
|
|
const image = fs
|
|
.readFileSync(path.join(__dirname, 'Dockerfile'), 'utf8')
|
|
.match(/^FROM (\S+)$/m)?.[1];
|
|
if (!image || !image.includes('@sha256:'))
|
|
throw new Error('A digest-pinned importer image is required');
|
|
const snapshots = [
|
|
{ volume: `gitnexus-host-snapshot-${id}`, target: '/host', source: home, entries: HOST_PATHS },
|
|
...Object.entries(IDENTITIES).map(([name, dir]) => ({
|
|
volume: `gitnexus-${name}-snapshot-${id}`,
|
|
target: `/identity/${name}`,
|
|
source: path.join(home, dir),
|
|
entries: ['.'],
|
|
})),
|
|
];
|
|
const mounts = snapshots.map(
|
|
(s) => `type=volume,source=${s.volume},target=${s.target},volume-nocopy`,
|
|
);
|
|
// The host never writes the workspace volume; it only fills the staging volume.
|
|
if (mode === 'source')
|
|
mounts.push(
|
|
`type=volume,source=gitnexus-source-${id},target=/workspace,volume-nocopy,readonly`,
|
|
`type=volume,source=gitnexus-seed-${id},target=/seed,volume-nocopy`,
|
|
);
|
|
// A stable name serializes imports. Never remove someone else's running importer.
|
|
const name = `gitnexus-import-${id}`;
|
|
let created = false;
|
|
try {
|
|
await runWithProgress('Preparing import helper', [
|
|
'create',
|
|
'--name',
|
|
name,
|
|
'--user',
|
|
'0',
|
|
'--network',
|
|
'none',
|
|
...mounts.flatMap((m) => ['--mount', m]),
|
|
'--entrypoint',
|
|
'sleep',
|
|
image,
|
|
'infinity',
|
|
]);
|
|
created = true;
|
|
await runWithProgress('Starting import helper', ['start', name]);
|
|
for (const file of ['initialize-volumes.cjs', 'seed-workspace.cjs'])
|
|
docker('cp', path.join(__dirname, file), `${name}:/tmp/${file}`);
|
|
const run = (script, ...args) => docker('exec', name, 'node', `/tmp/${script}`, ...args);
|
|
const clear = (target) =>
|
|
docker('exec', name, 'find', target, '-xdev', '-mindepth', '1', '-delete');
|
|
// Stages and snapshot retakes are best-effort: initializeCommand also runs
|
|
// when an existing container is reopened, and a busy host must not lock it
|
|
// out. A failure clears its target; the next start retries it.
|
|
const attempt = async (label, target, work) => {
|
|
try {
|
|
await work();
|
|
return true;
|
|
} catch (error) {
|
|
clear(target);
|
|
console.warn(`[volumes] ${label} skipped and retried on the next start: ${error.message}`);
|
|
return false;
|
|
}
|
|
};
|
|
// The host only stages. onCreateCommand commits a complete stage once per
|
|
// container creation, so reopening an older container just refreshes it.
|
|
const staging =
|
|
mode === 'source' && run('seed-workspace.cjs', '--state', '/workspace') === 'empty';
|
|
if (staging)
|
|
await attempt('Staging the checkout', '/seed', async () => {
|
|
console.log(
|
|
'[volumes] Staging the checkout, Git metadata and local work; skipping dependencies and regenerable parser caches. Container creation copies it into the source volume once.',
|
|
);
|
|
clear('/seed'); // Removes the completion marker before anything else.
|
|
validateGitDirectory(path.join(workspace, '.git'));
|
|
docker('exec', name, 'mkdir', `/seed/${STAGE_TREE}`);
|
|
await copyArchive(workspace, ['.'], `${name}:/seed/${STAGE_TREE}`, isWorkspaceExcluded);
|
|
docker('exec', name, 'touch', `/seed/${STAGE_COMPLETE}`); // Written last.
|
|
});
|
|
// onCreateCommand runs this host copy, so it matches devcontainer.json and
|
|
// works with any image, including prebuilt ones.
|
|
if (mode === 'source')
|
|
docker('cp', path.join(__dirname, 'seed-workspace.cjs'), `${name}:/seed/seed-workspace.cjs`);
|
|
// Linux hosts realign the remote UID; Desktop on Windows/macOS keeps node=1000.
|
|
// updateRemoteUserUID skips root hosts (UID 0 already exists), so node stays 1000.
|
|
const realign = process.platform === 'linux' && process.getuid() !== 0;
|
|
const uid = String(realign ? process.getuid() : 1000);
|
|
const gid = String(realign ? process.getgid() : 1000);
|
|
for (const snapshot of snapshots) {
|
|
// Snapshots are read-only host copies, so replacing one is always safe.
|
|
// Refresh partial ones, and all of them until the workspace is committed.
|
|
const fresh =
|
|
staging || run('initialize-volumes.cjs', '--snapshot-state', snapshot.target) !== 'ready';
|
|
const copied =
|
|
fresh &&
|
|
(await attempt(`Snapshot ${snapshot.volume}`, snapshot.target, async () => {
|
|
clear(snapshot.target);
|
|
// lstat keeps dangling links; the archiver records any root it cannot follow.
|
|
// Like existsSync, a path under a non-directory is just absent.
|
|
const entries = snapshot.entries.filter((entry) => {
|
|
try {
|
|
return Boolean(fs.lstatSync(path.join(snapshot.source, entry)));
|
|
} catch {
|
|
return false;
|
|
}
|
|
});
|
|
console.log(`[volumes] Creating ${snapshot.volume}`);
|
|
await copyArchive(
|
|
snapshot.source,
|
|
entries,
|
|
`${name}:${snapshot.target}`,
|
|
(relative) => relative === SNAPSHOT_MARKER,
|
|
);
|
|
}));
|
|
if (fresh && !copied) continue; // Never mark a cleared snapshot complete.
|
|
await runWithProgress(`Finalizing ${snapshot.target}`, [
|
|
'exec',
|
|
name,
|
|
'node',
|
|
'/tmp/initialize-volumes.cjs',
|
|
'--snapshot-finish',
|
|
snapshot.target,
|
|
uid,
|
|
gid,
|
|
fresh ? 'fresh' : 'kept',
|
|
]);
|
|
}
|
|
console.log('[volumes] Linux volumes ready. Host files are not synchronized.');
|
|
} finally {
|
|
// Only the disposable helper is removed, never any volume or host file.
|
|
if (created) await runWithProgress('Removing temporary import helper', ['rm', '-f', name]);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
initialize,
|
|
tarStream,
|
|
startProgress,
|
|
snapshotState,
|
|
HOST_PATHS,
|
|
};
|
|
if (require.main === module) {
|
|
(async () => {
|
|
if (process.argv[2] === '--snapshot-state') console.log(snapshotState(process.argv[3]));
|
|
else if (process.argv[2] === '--snapshot-finish')
|
|
finishSnapshot(
|
|
process.argv[3],
|
|
Number(process.argv[4]),
|
|
Number(process.argv[5]),
|
|
process.argv[6] === 'fresh',
|
|
);
|
|
else await initialize(process.argv[2], process.argv[3]);
|
|
})().catch((error) => {
|
|
console.error(`[volumes] ${error.message}`);
|
|
process.exitCode = 1;
|
|
});
|
|
}
|