Skip to content

Commit cd98731

Browse files
Mossakaclaude
andauthored
fix: pass BUN_INSTALL to chroot to prevent Bun core dump (#546)
Bun crashes with a core dump when installed inside the chroot due to restricted /proc access (/proc/self only). Instead, Bun should be pre-installed on the host (via setup-bun action) and its install path passed through to the chroot via AWF_BUN_INSTALL, following the same pattern as GOROOT, CARGO_HOME, and JAVA_HOME. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 48b61f8 commit cd98731

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

containers/agent/entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ AWFEOF
239239
echo "export PATH=\"${AWF_GOROOT}/bin:\$PATH\"" >> "/host${SCRIPT_FILE}"
240240
echo "export GOROOT=\"${AWF_GOROOT}\"" >> "/host${SCRIPT_FILE}"
241241
fi
242+
# Add BUN_INSTALL/bin to PATH if provided (for Bun on GitHub Actions)
243+
# Bun must be pre-installed on the host because it crashes inside chroot (restricted /proc)
244+
if [ -n "${AWF_BUN_INSTALL}" ]; then
245+
echo "[entrypoint] Adding BUN_INSTALL/bin to PATH: ${AWF_BUN_INSTALL}/bin"
246+
echo "export PATH=\"${AWF_BUN_INSTALL}/bin:\$PATH\"" >> "/host${SCRIPT_FILE}"
247+
echo "export BUN_INSTALL=\"${AWF_BUN_INSTALL}\"" >> "/host${SCRIPT_FILE}"
248+
fi
242249
else
243250
echo "[entrypoint] Constructing default PATH for chroot"
244251
cat > "/host${SCRIPT_FILE}" << 'AWFEOF'

src/docker-manager.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,16 @@ describe('docker-manager', () => {
624624
expect(environment.AWF_CHROOT_ENABLED).toBe('true');
625625
});
626626

627-
it('should pass GOROOT, CARGO_HOME, JAVA_HOME to container when enableChroot is true and env vars are set', () => {
627+
it('should pass GOROOT, CARGO_HOME, JAVA_HOME, BUN_INSTALL to container when enableChroot is true and env vars are set', () => {
628628
const originalGoroot = process.env.GOROOT;
629629
const originalCargoHome = process.env.CARGO_HOME;
630630
const originalJavaHome = process.env.JAVA_HOME;
631+
const originalBunInstall = process.env.BUN_INSTALL;
631632

632633
process.env.GOROOT = '/usr/local/go';
633634
process.env.CARGO_HOME = '/home/user/.cargo';
634635
process.env.JAVA_HOME = '/usr/lib/jvm/java-17';
636+
process.env.BUN_INSTALL = '/home/user/.bun';
635637

636638
try {
637639
const configWithChroot = {
@@ -645,6 +647,7 @@ describe('docker-manager', () => {
645647
expect(environment.AWF_GOROOT).toBe('/usr/local/go');
646648
expect(environment.AWF_CARGO_HOME).toBe('/home/user/.cargo');
647649
expect(environment.AWF_JAVA_HOME).toBe('/usr/lib/jvm/java-17');
650+
expect(environment.AWF_BUN_INSTALL).toBe('/home/user/.bun');
648651
} finally {
649652
// Restore original values
650653
if (originalGoroot !== undefined) {
@@ -662,6 +665,32 @@ describe('docker-manager', () => {
662665
} else {
663666
delete process.env.JAVA_HOME;
664667
}
668+
if (originalBunInstall !== undefined) {
669+
process.env.BUN_INSTALL = originalBunInstall;
670+
} else {
671+
delete process.env.BUN_INSTALL;
672+
}
673+
}
674+
});
675+
676+
it('should NOT set AWF_BUN_INSTALL when BUN_INSTALL is not in environment', () => {
677+
const originalBunInstall = process.env.BUN_INSTALL;
678+
delete process.env.BUN_INSTALL;
679+
680+
try {
681+
const configWithChroot = {
682+
...mockConfig,
683+
enableChroot: true
684+
};
685+
const result = generateDockerCompose(configWithChroot, mockNetworkConfig);
686+
const agent = result.services.agent;
687+
const environment = agent.environment as Record<string, string>;
688+
689+
expect(environment.AWF_BUN_INSTALL).toBeUndefined();
690+
} finally {
691+
if (originalBunInstall !== undefined) {
692+
process.env.BUN_INSTALL = originalBunInstall;
693+
}
665694
}
666695
});
667696

src/docker-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ export function generateDockerCompose(
353353
if (process.env.JAVA_HOME) {
354354
environment.AWF_JAVA_HOME = process.env.JAVA_HOME;
355355
}
356+
// Bun: Pass BUN_INSTALL so entrypoint can add $BUN_INSTALL/bin to PATH
357+
// Bun crashes with core dump when installed inside chroot (restricted /proc access),
358+
// so it must be pre-installed on the host via setup-bun action
359+
if (process.env.BUN_INSTALL) {
360+
environment.AWF_BUN_INSTALL = process.env.BUN_INSTALL;
361+
}
356362
}
357363

358364
// If --env-all is specified, pass through all host environment variables (except excluded ones)

0 commit comments

Comments
 (0)