Skip to content

Commit 0b25317

Browse files
committed
fix(ci): allow sandbox network access for Algolia during SSR prerendering
origin's .bazelrc disables Bazel sandbox network access by default (--nosandbox_default_allow_network), which makes the adev SSR bundling step fail (RetryError: Unreachable hosts) because it needs to reach Algolia during prerendering. This is a known issue also hit by angular/angular-ja; this mirrors their fix. - CI: add --sandbox_default_allow_network and CI resource limits to the Bazel config in ci.yml and adev-staging-deploy.yml - Local: add a root .bazelrc (general Bazel diagnostics) and an optional .bazelrc.user.example (macOS network workaround via --spawn_strategy=local); tools/lib/common.mjs now propagates both into build/.bazelrc.user on every build, since Bazel only reads .bazelrc.user from its own workspace root
1 parent 7daab57 commit 0b25317

6 files changed

Lines changed: 62 additions & 10 deletions

File tree

.bazelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Print all the options that apply to the build.
2+
# This helps us diagnose which options override others
3+
# (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc)
4+
build --announce_rc
5+
6+
# More details on failures
7+
build --verbose_failures=true
8+
9+
# CI supports colors but Bazel does not detect it.
10+
common --color=yes

.bazelrc.user.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Local development settings for macOS
2+
# Copy this file to .bazelrc.user to enable these settings.
3+
# macOS sandbox blocks network access during prerendering (Algolia API calls).
4+
# Use local spawn strategy to allow network access.
5+
build --spawn_strategy=local

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,22 @@ jobs:
3131
disk-cache: true
3232
repository-cache: true
3333
bazelrc: |
34-
# Print all the options that apply to the build.
35-
# This helps us diagnose which options override others
36-
# (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc)
37-
build --announce_rc
34+
# Limit resources for CI runners (ubuntu-latest: 7GB RAM, 2 CPUs)
35+
build --local_ram_resources=4096
36+
build --local_cpu_resources=2
37+
build --jobs=2
38+
build --discard_analysis_cache
39+
build --nokeep_state_after_build
3840
39-
# More details on failures
40-
build --verbose_failures=true
41-
42-
# CI supports colors but Bazel does not detect it.
43-
common --color=yes
41+
# Allow network access in sandbox for Algolia API calls during SSR prerendering.
42+
build --sandbox_default_allow_network
4443
- name: Install Dependencies
4544
run: npm ci
4645
- name: Build Docs
4746
run: npm run build
47+
env:
48+
_JAVA_OPTIONS: -Xms512m -Xmx2g
49+
NODE_OPTIONS: --max-old-space-size=4096
4850
- name: Deploy to Firebase Hosting
4951
uses: FirebaseExtended/action-hosting-deploy@v0
5052
with:

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ jobs:
2727
bazelisk-cache: true
2828
disk-cache: true
2929
repository-cache: true
30+
bazelrc: |
31+
# Limit resources for CI runners (ubuntu-latest: 7GB RAM, 2 CPUs)
32+
build --local_ram_resources=4096
33+
build --local_cpu_resources=2
34+
build --jobs=2
35+
build --discard_analysis_cache
36+
build --nokeep_state_after_build
37+
# Allow network access in sandbox for Algolia API calls during SSR prerendering.
38+
build --sandbox_default_allow_network
3039
- name: Install Dependencies
3140
run: npm ci
3241
- name: Build Docs
33-
run: npm run build
42+
run: npm run build
43+
env:
44+
_JAVA_OPTIONS: -Xms512m -Xmx2g
45+
NODE_OPTIONS: --max-old-space-size=4096

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/build
33
/tmp
44

5+
# Personal local Bazel overrides (see .bazelrc.user.example)
6+
.bazelrc.user
7+
58
# Node
69
/node_modules
710
npm-debug.log

tools/lib/common.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { watch } from 'chokidar';
2+
import { appendFile, readFile } from 'node:fs/promises';
23
import { resolve } from 'node:path';
34
import { $, cd, chalk, glob, within } from 'zx';
45
import { initDir, cpRf, exists } from './fileutiles.mjs';
@@ -19,6 +20,25 @@ export async function resetBuildDir({ init = false }) {
1920
await initDir(outDir);
2021
console.log(chalk.cyan('copying origin files to build directory...'));
2122
await cpRf(resolve(rootDir, 'origin'), outDir);
23+
await applyRootBazelrc();
24+
}
25+
}
26+
27+
/**
28+
* Propagates this repo's own .bazelrc, plus the personal .bazelrc.user (see
29+
* .bazelrc.user.example) if present, into the build directory as .bazelrc.user.
30+
* Bazel only reads .bazelrc.user from its own workspace root (build/), not from this repo's
31+
* root, and build/ is recreated on every run, so both must be copied in each time.
32+
*/
33+
async function applyRootBazelrc() {
34+
const dest = resolve(outDir, '.bazelrc.user');
35+
await cpRf(resolve(rootDir, '.bazelrc'), dest);
36+
37+
const userBazelrc = resolve(rootDir, '.bazelrc.user');
38+
if (await exists(userBazelrc)) {
39+
console.log(chalk.cyan('applying local .bazelrc.user overrides...'));
40+
const content = await readFile(userBazelrc, 'utf-8');
41+
await appendFile(dest, '\n' + content);
2242
}
2343
}
2444

0 commit comments

Comments
 (0)