GitNexus/.devcontainer/bootstrap-native.cjs
Gergő Magyar b961e695ca
Some checks failed
Devcontainer Smoke / Config-transform unit tests (push) Has been cancelled
Devcontainer Smoke / Build devcontainer image (default) (push) Has been cancelled
Publish Development Images / publish (core) (push) Has been cancelled
Publish Development Images / publish (ui) (push) Has been cancelled
Devcontainer Smoke / Build devcontainer image (ui) (push) Has been cancelled
CodeQL / Analyze (python) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / ci (push) Blocked by required conditions
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Skill copy sync / shipped skills drift guard (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix(devcontainer): refresh Node and streamline development (#3610)
2026-10-17 21:05:13 +00:00

71 lines
2 KiB
JavaScript

'use strict';
// Runs from the image before any workspace lifecycle script exists in the
// fresh volume. Never reset or overwrite a populated checkout.
const fs = require('node:fs');
const path = require('node:path');
const { execFileSync } = require('node:child_process');
function bootstrap(root, url, ref) {
if (!url || !ref || ref.startsWith('-')) throw new Error('A clone URL and branch are required');
fs.mkdirSync(root, { recursive: true });
const git = (...args) =>
execFileSync('git', args, {
cwd: root,
stdio: ['ignore', 'pipe', 'pipe'],
encoding: 'utf8',
}).trim();
git('check-ref-format', '--branch', ref);
if (!fs.existsSync(path.join(root, '.git'))) git('init');
let origin;
try {
origin = git('remote', 'get-url', 'origin');
} catch {
git('remote', 'add', 'origin', url);
origin = url;
}
if (origin !== url) throw new Error('Workspace volume has another origin; refusing to modify it');
try {
git('rev-parse', '--verify', 'HEAD');
return;
} catch {
/* Resume an interrupted initial fetch. */
}
const upstream = `refs/remotes/origin/${ref}`;
git('fetch', 'origin', `refs/heads/${ref}:${upstream}`);
git('checkout', '--no-overwrite-ignore', '--track', '-b', ref, upstream);
}
module.exports = { bootstrap };
if (require.main === module) {
const root = path.resolve(process.argv[2] || '/workspace');
// Repair UID changes on a reused workspace volume without following symlinks
// or descending into the separately mounted dependency volumes.
const uid = String(process.getuid());
const gid = String(process.getgid());
execFileSync(
'sudo',
[
'-n',
'find',
root,
'-xdev',
'(',
'!',
'-uid',
uid,
'-o',
'!',
'-gid',
gid,
')',
'-exec',
'chown',
'-h',
`${uid}:${gid}`,
'{}',
'+',
],
{ stdio: 'inherit' },
);
bootstrap(root, process.env.GITNEXUS_CLONE_URL, process.env.GITNEXUS_CLONE_REF);
}