Skip to content

Commit 0602285

Browse files
authored
fix: prevent Bazel OOM crash on CI runners (#1147)
* fix: prevent Bazel OOM crash on CI runners - Add resource limits to all CI workflows' bazelrc configuration: - Limit RAM to 6GB (GitHub Actions ubuntu-latest has 7GB) - Limit CPUs to 2 - Limit parallel jobs to 4 - Reduce JVM heap to 2GB max - Discard analysis cache after build to reduce memory pressure - Add build output verification in adev.ts to detect silent failures when Bazel server is killed mid-build * fix: limit env scope to build step only - Move _JAVA_OPTIONS and NODE_OPTIONS to build step env - Remove startup options from bazelrc (use _JAVA_OPTIONS instead) - Reduce local_ram_resources to 4096MB - Reduce jobs to 2
1 parent 7eda322 commit 0602285

4 files changed

Lines changed: 44 additions & 24 deletions

File tree

.github/workflows/adev-preview-build.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ jobs:
3535
disk-cache: ${{ github.workflow }}
3636
repository-cache: true
3737
bazelrc: |
38-
# Print all the options that apply to the build.
39-
# This helps us diagnose which options override others
40-
# (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc)
41-
build --announce_rc
42-
43-
# More details on failures
44-
build --verbose_failures=true
45-
46-
# CI supports colors but Bazel does not detect it.
47-
common --color=yes
38+
# Limit resources for CI runners (ubuntu-latest: 7GB RAM, 2 CPUs)
39+
build --local_ram_resources=4096
40+
build --local_cpu_resources=2
41+
build --jobs=2
42+
build --discard_analysis_cache
43+
build --nokeep_state_after_build
4844
- run: pnpm install --frozen-lockfile
49-
- run: pnpm run build
45+
- name: Build
46+
run: pnpm run build
47+
env:
48+
_JAVA_OPTIONS: -Xms512m -Xmx2g
49+
NODE_OPTIONS: --max-old-space-size=4096
5050
- uses: angular/dev-infra/github-actions/previews/pack-and-upload-artifact@0512a5b9381ccff00c278d7b4b6ee38e5c09654d
5151
with:
5252
workflow-artifact-name: 'adev-preview'

.github/workflows/adev-production-deploy.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ jobs:
2727
disk-cache: ${{ github.workflow }}
2828
repository-cache: true
2929
bazelrc: |
30-
# Print all the options that apply to the build.
31-
# This helps us diagnose which options override others
32-
# (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc)
33-
build --announce_rc
34-
35-
# More details on failures
36-
build --verbose_failures=true
37-
38-
# CI supports colors but Bazel does not detect it.
39-
common --color=yes
30+
# Limit resources for CI runners (ubuntu-latest: 7GB RAM, 2 CPUs)
31+
build --local_ram_resources=4096
32+
build --local_cpu_resources=2
33+
build --jobs=2
34+
build --discard_analysis_cache
35+
build --nokeep_state_after_build
4036
- run: pnpm install --frozen-lockfile
41-
- run: pnpm run build
37+
- name: Build
38+
run: pnpm run build
39+
env:
40+
_JAVA_OPTIONS: -Xms512m -Xmx2g
41+
NODE_OPTIONS: --max-old-space-size=4096
4242
- name: Deploy to Firebase Hosting
4343
uses: FirebaseExtended/action-hosting-deploy@0cbcac4740c2bfb00d632f0b863b57713124eb5a # v0.9.0
4444
with:

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ jobs:
3838
bazelisk-cache: true
3939
disk-cache: ${{ github.workflow }}
4040
repository-cache: true
41+
bazelrc: |
42+
# Limit resources for CI runners (ubuntu-latest: 7GB RAM, 2 CPUs)
43+
build --local_ram_resources=4096
44+
build --local_cpu_resources=2
45+
build --jobs=2
46+
build --discard_analysis_cache
47+
build --nokeep_state_after_build
4148
- run: pnpm install
42-
- run: pnpm run build
49+
- name: Build
50+
run: pnpm run build
51+
env:
52+
_JAVA_OPTIONS: -Xms512m -Xmx2g
53+
NODE_OPTIONS: --max-old-space-size=4096
4354
# build-windows:
4455
# runs-on: windows-latest
4556
# steps:

tools/lib/adev.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { consola } from 'consola';
22
import { $ } from 'execa';
3-
import { buildDir } from './workspace';
3+
import { existsSync } from 'node:fs';
4+
import { buildDir, buildOutputDir } from './workspace';
45

56
const $$ = $({
67
stdin: 'inherit',
@@ -13,6 +14,14 @@ export async function buildAdev() {
1314
const sh = $$({ cwd: buildDir });
1415
await sh`pnpm install --frozen-lockfile`;
1516
await sh`pnpm bazel build //adev:build.production --config=release`;
17+
18+
// Verify build output exists - Bazel may exit with code 0 even when interrupted
19+
if (!existsSync(buildOutputDir)) {
20+
throw new Error(
21+
`Build output directory not found: ${buildOutputDir}\n` +
22+
'Bazel build may have been interrupted or failed silently.'
23+
);
24+
}
1625
}
1726

1827
export function serveAdev() {

0 commit comments

Comments
 (0)