Skip to content

Commit

Permalink
ci: Use BuildBuddy for Bazel results, remote caching, and remote exec…
Browse files Browse the repository at this point in the history
…ution
  • Loading branch information
SanjayVas committed Oct 8, 2024
1 parent 43b46be commit 14b384c
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 145 deletions.
16 changes: 12 additions & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ build --java_language_version=11
# Pass environment variables.
test --test_env TESTCONTAINERS_RYUK_DISABLED=true

# Disable remote cache upload by default.
build --noremote_upload_local_results
# Configuration for remote cache.
build --noremote_upload_local_results # Do not upload by default
build --remote_download_outputs=toplevel
build --remote_timeout=3600
build:remote-cache --remote_cache=grpcs://world-federation-of-advertisers.buildbuddy.io
build:remote-cache --experimental_remote_cache_compression
build:remote-cache --experimental_remote_cache_compression_threshold=100

# Configuration for continuous integration (CI).
common:ci --lockfile_mode=error
build:ci --compilation_mode=opt
build:ci --host_platform //build/platforms:ubuntu_22_04
common:remote-cache --remote_cache=https://storage.googleapis.com/halo-cmm-build-cache/cross-media-measurement
common:remote-cache --google_default_credentials
build:ci --build_metadata=ROLE=CI
build:ci --config=remote-cache
build:ci --config=results
build:ci --config=remote

# Configuration for GitHub Container Registry
build:ghcr --define container_registry=ghcr.io
Expand All @@ -40,3 +47,4 @@ import %workspace%/container.bazelrc
import %workspace%/maven.bazelrc
import %workspace%/remote.bazelrc
import %workspace%/results.bazelrc
try-import %workspace%/auth.bazelrc
18 changes: 8 additions & 10 deletions .github/workflows/api-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
lint:
name: API lint
runs-on: ubuntu-22.04
permissions:
id-token: write
defaults:
run:
shell: bash
Expand All @@ -41,19 +39,19 @@ jobs:
with:
version: 1.67.2
sha256: 260064fad8c38feae402595b6cefef51d70e72b0b5968359c79ee8f3ad33ab27

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
EOF
- env:
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
build-test:
name: Build and test
runs-on: ubuntu-22.04
permissions:
id-token: write
env:
CLUSTER_LOGS_PATH: cluster-logs
steps:
Expand All @@ -47,18 +45,18 @@ jobs:

- uses: ./.github/actions/free-disk-space

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}
- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
build --remote_upload_local_results
build --define container_registry=localhost:5001
build --define image_repo_prefix=halo
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/configure-aws-duchy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ jobs:
WORKER2_DUCHY_CERT_ID: ${{ vars.WORKER2_DUCHY_CERT_ID }}
run: ./.github/workflows/export-duchy-cert-id.sh

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down
36 changes: 8 additions & 28 deletions .github/workflows/configure-duchy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ jobs:
WORKER2_DUCHY_CERT_ID: ${{ vars.WORKER2_DUCHY_CERT_ID }}
run: ./.github/workflows/export-duchy-cert-id.sh

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down Expand Up @@ -116,27 +124,6 @@ jobs:
build --define duchy_storage_bucket=$STORAGE_BUCKET
EOF
- name: Get Bazel cache params
id: get-cache-params
run: |
cache_path="$(bazelisk info output_base)"
echo "cache-path=${cache_path}" >> "$GITHUB_OUTPUT"
tree_hash="$(git rev-parse HEAD:)"
restore_key="duchy-bazel-"
echo "restore-key=${restore_key}" >> "$GITHUB_OUTPUT"
cache_key="${restore_key}${tree_hash}"
echo "cache-key=${cache_key}" >> "$GITHUB_OUTPUT"
- name: Restore Bazel cache
uses: actions/cache/restore@v4
with:
path: ${{ steps.get-cache-params.outputs.cache-path }}
key: ${{ steps.get-cache-params.outputs.cache-key }}
restore-keys: |
${{ steps.get-cache-params.outputs.restore-key }}
- name: Export BAZEL_BIN
run: echo "BAZEL_BIN=$(bazelisk info bazel-bin)" >> $GITHUB_ENV

Expand All @@ -156,13 +143,6 @@ jobs:
"//src/main/k8s/dev:${DUCHY_NAME}_duchy.tar"
//src/main/k8s/testing/secretfiles:archive
- name: Save Bazel cache
continue-on-error: true
uses: actions/cache/save@v4
with:
path: ${{ steps.get-cache-params.outputs.cache-path }}
key: ${{ steps.get-cache-params.outputs.cache-key }}

- name: Make Kustomization dir
run: mkdir -p "$KUSTOMIZATION_PATH"

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/configure-kingdom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GKE_CONFIG_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/configure-reporting-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GKE_CONFIG_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/configure-reporting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GKE_CONFIG_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/configure-simulators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
workload_identity_provider: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GKE_CONFIG_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/publish-maven-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
publish-artifacts:
name: Publish Maven artifacts
runs-on: ubuntu-22.04
permissions:
id-token: write
steps:
- uses: actions/checkout@v4

Expand All @@ -52,18 +50,18 @@ jobs:
version: 7.1.2
sha256: 8d5c459ab21b411b8be059a8bdf59f0d3eabf9dff943d5eccb80e36e525cc09d

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}
- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
EOF
- name: Get Bazel cache params
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/push-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,28 @@ jobs:
push-images:
runs-on: ubuntu-22.04
permissions:
id-token: write
packages: write
env:
CONTAINER_REGISTRY: ghcr.io
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/free-disk-space

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}

- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
IMAGE_TAG: ${{ inputs.image-tag }}
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
build --define container_registry=$CONTAINER_REGISTRY
build --define image_repo_prefix=$GITHUB_REPOSITORY_OWNER
build --define image_tag=$IMAGE_TAG
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
build-test:
name: Build and test
runs-on: ubuntu-22.04
permissions:
id-token: write
env:
CLUSTER_LOGS_PATH: cluster-logs
steps:
Expand All @@ -33,18 +31,18 @@ jobs:

- uses: ./.github/actions/free-disk-space

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}
- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
EOF
- name: Get Bazel cache params
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/run-k8s-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@ on:
- qa
- head

permissions:
id-token: write

jobs:
run-tests:
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4

# Authenticate to Google Cloud for access to remote cache.
- name: Authenticate to Google Cloud for remote cache
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.BAZEL_BUILD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.BAZEL_BUILD_SERVICE_ACCOUNT }}
- name: Write auth.bazelrc
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat << EOF > auth.bazelrc
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
EOF
- name: Write ~/.bazelrc
env:
Expand All @@ -57,7 +55,6 @@ jobs:
run: |
cat << EOF > ~/.bazelrc
common --config=ci
common --config=remote-cache
build --define kingdom_public_api_target=$KINGDOM_PUBLIC_API_TARGET
build --define mc_name=$MC_NAME
build --define mc_api_key=$MC_API_KEY
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
# Terraform directories
.terraform/

# Authentication credentials
/auth.bazelrc

**/node_modules
Loading

0 comments on commit 14b384c

Please sign in to comment.