|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Only run in remote (Claude Code on the web) environments |
| 5 | +if [ "${CLAUDE_CODE_REMOTE:-}" != "true" ]; then |
| 6 | + exit 0 |
| 7 | +fi |
| 8 | + |
| 9 | +INSTALL_DIR="/usr/local/bin" |
| 10 | +PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 11 | +DISTDIR="${PROJECT_DIR}/.bazel-distdir" |
| 12 | + |
| 13 | +mkdir -p "$DISTDIR" |
| 14 | + |
| 15 | +# Install Bazelisk (provides the `bazel` command) |
| 16 | +if ! command -v bazel &>/dev/null; then |
| 17 | + echo "Installing Bazelisk..." |
| 18 | + BAZELISK_VERSION="v1.25.0" |
| 19 | + curl -fsSL "https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-linux-amd64" \ |
| 20 | + -o "${INSTALL_DIR}/bazel" |
| 21 | + chmod +x "${INSTALL_DIR}/bazel" |
| 22 | + echo "Bazelisk installed successfully" |
| 23 | +fi |
| 24 | + |
| 25 | +# Install ibazel (incremental Bazel) |
| 26 | +if ! command -v ibazel &>/dev/null; then |
| 27 | + echo "Installing ibazel..." |
| 28 | + IBAZEL_VERSION="v0.25.3" |
| 29 | + curl -fsSL "https://github.com/bazelbuild/bazel-watcher/releases/download/${IBAZEL_VERSION}/ibazel_linux_amd64" \ |
| 30 | + -o "${INSTALL_DIR}/ibazel" |
| 31 | + chmod +x "${INSTALL_DIR}/ibazel" |
| 32 | + echo "ibazel installed successfully" |
| 33 | +fi |
| 34 | + |
| 35 | +# Create custom Java truststore for Bazel's embedded JDK |
| 36 | +# The remote environment uses a TLS-inspecting proxy whose CA is in the system |
| 37 | +# trust store but not in Bazel's embedded JDK truststore. |
| 38 | +CUSTOM_CACERTS="${DISTDIR}/cacerts" |
| 39 | +PROXY_CA="/usr/local/share/ca-certificates/swp-ca-production.crt" |
| 40 | + |
| 41 | +if [ ! -f "$CUSTOM_CACERTS" ] && [ -f "$PROXY_CA" ]; then |
| 42 | + echo "Creating custom truststore with proxy CA..." |
| 43 | + |
| 44 | + # Prime Bazel installation to get its embedded JDK |
| 45 | + bazel version >/dev/null 2>&1 |
| 46 | + |
| 47 | + BAZEL_INSTALL="$(bazel info install_base 2>/dev/null)" |
| 48 | + BAZEL_CACERTS="${BAZEL_INSTALL}/embedded_tools/jdk/lib/security/cacerts" |
| 49 | + |
| 50 | + if [ -f "$BAZEL_CACERTS" ]; then |
| 51 | + cp "$BAZEL_CACERTS" "$CUSTOM_CACERTS" |
| 52 | + keytool -importcert -keystore "$CUSTOM_CACERTS" -storepass changeit \ |
| 53 | + -noprompt -alias "anthropic-proxy-ca" -file "$PROXY_CA" >/dev/null 2>&1 |
| 54 | + echo "Custom truststore created with proxy CA" |
| 55 | + fi |
| 56 | +fi |
| 57 | + |
| 58 | +# Generate user.bazelrc for the remote proxy environment |
| 59 | +# - Disable Bzlmod (this project uses WORKSPACE, not MODULE.bazel) |
| 60 | +# - Use distdir for pre-downloaded dependencies |
| 61 | +# - Enable proxy auth for JDK HTTPS tunneling |
| 62 | +# - Use custom truststore with proxy's TLS inspection CA |
| 63 | +BAZELRC="${PROJECT_DIR}/user.bazelrc" |
| 64 | +if [ ! -f "$BAZELRC" ]; then |
| 65 | + cat > "$BAZELRC" << EOF |
| 66 | +# Auto-generated by Claude Code session-start hook for remote environments |
| 67 | +# This file is gitignored - see .bazelrc try-import |
| 68 | +common --noenable_bzlmod |
| 69 | +build --distdir=.bazel-distdir |
| 70 | +fetch --distdir=.bazel-distdir |
| 71 | +query --distdir=.bazel-distdir |
| 72 | +
|
| 73 | +# Enable proxy auth for HTTPS tunneling (disabled by default in JDK) |
| 74 | +startup --host_jvm_args=-Djdk.http.auth.tunneling.disabledSchemes= |
| 75 | +startup --host_jvm_args=-Djdk.http.auth.proxying.disabledSchemes= |
| 76 | +
|
| 77 | +# Use custom truststore that includes the proxy's TLS inspection CA |
| 78 | +startup --host_jvm_args=-Djavax.net.ssl.trustStore=${DISTDIR}/cacerts |
| 79 | +startup --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit |
| 80 | +EOF |
| 81 | + echo "Created user.bazelrc with proxy-friendly settings" |
| 82 | +fi |
| 83 | + |
| 84 | +# Pre-download Bazel WORKSPACE dependencies into distdir |
| 85 | +"${PROJECT_DIR}/scripts/bazel_fetch_deps.sh" |
| 86 | + |
| 87 | +echo "Session startup complete: bazel and ibazel are available" |
0 commit comments