Skip to content

Commit 8b145be

Browse files
[build-and-test] Use buildbuddy remote execution for build and test actions. (#1406)
Summary: Uses buildbuddy remote execution to run build and test bazel commands. Uses Github "environments" to access the authorize access to the BB_IO_API_KEY secret. Type of change: /kind test-infra. Test Plan: Tested on my fork. Had @vihangm create a PR, saw that it required me to approve the environment before it would run. Signed-off-by: James Bartlett <jamesbartlett@pixielabs.ai>
1 parent b970c16 commit 8b145be

File tree

5 files changed

+115
-29
lines changed

5 files changed

+115
-29
lines changed

.bazelrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,19 @@ coverage --define PL_COVERAGE=true
228228
coverage --copt -DPL_COVERAGE
229229
coverage --test_tag_filters=-requires_root,-requires_bpf,-no_coverage,-disabled,-no_gcc
230230

231+
232+
try-import %workspace%/bes.bazelrc
231233
# jenkins.bazelrc is copied from ci/jenkins.bazelrc by Jenkins workers during the build.
232234
# The intention is to avoid polluting configurations of bazel for developers.
233235
try-import %workspace%/jenkins.bazelrc
234236
# github.bazelrc is copied from ci/github/bazelrc by the github action workers during the build.
235237
try-import %workspace%/github.bazelrc
236238

237-
# Put your own configurations into user.bazelrc, which is ignored by git.
238-
try-import %workspace%/user.bazelrc
239-
240239
# Import a machine specific bazelrc. This can be used to enable caching.
241240
try-import /etc/bazelrc
242241

243-
try-import %workspace%/bes.bazelrc
242+
# Put your own configurations into user.bazelrc, which is ignored by git.
243+
try-import %workspace%/user.bazelrc
244244

245245
# Tensorflow requires this option
246246
common --experimental_repo_remote_exec
@@ -263,5 +263,6 @@ build:remote --remote_retries=5
263263
build:remote --spawn_strategy=remote,local
264264
build:remote --experimental_remote_cache_compression
265265
build:remote --jobs=100
266+
test:remote --jobs=100
266267
build:remote --nolegacy_important_outputs
267268
build:remote --build_metadata=VISIBILITY=PUBLIC

.github/actions/bazelrc/action.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ inputs:
88
dev:
99
description: 'Whether to use DEV or CI settings for the bazelrc. defaults to dev'
1010
default: 'true'
11+
use_remote_exec:
12+
description: 'Use buildbuddy remote execution'
13+
default: 'false'
14+
BB_API_KEY:
15+
description: 'API key to use for buildbuddy if `use_remote_exec`'
16+
default: ''
1117
runs:
1218
using: "composite"
1319
steps:
@@ -35,3 +41,11 @@ runs:
3541
run: |
3642
echo "build --build_metadata=ROLE=CI" >> github.bazelrc
3743
shell: bash
44+
- name: Add remote execution
45+
if: inputs.use_remote_exec == 'true'
46+
env:
47+
BB_API_KEY: ${{ inputs.BB_API_KEY }}
48+
run: |
49+
echo "build:remote --remote_header=x-buildbuddy-api-key=$BB_API_KEY" >> github.bazelrc
50+
echo "build --config=remote" >> github.bazelrc
51+
shell: bash
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: env-protected-pr
3+
description: Setups actions that run on pull_request_target events, protected by github's deployment environments.
4+
outputs:
5+
env-name:
6+
description: 'name of deployment environment to use'
7+
value: ${{ steps.output.outputs.env-name }}
8+
ref:
9+
description: 'ref to checkout'
10+
value: ${{ steps.output.outputs.ref }}
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Not pull_request_target
15+
# yamllint disable rule:indentation
16+
if: github.event_name != 'pull_request_target'
17+
shell: bash
18+
run:
19+
echo "" > env_name
20+
echo "${{ github.ref }}" >> ref
21+
- name: Member pull_request_target
22+
if: >-
23+
github.event_name == 'pull_request_target' &&
24+
(
25+
github.event.pull_request.author_association == 'OWNER' ||
26+
github.event.pull_request.author_association == 'MEMBER'
27+
)
28+
# yamllint enable rule:indentation
29+
shell: bash
30+
run: |
31+
echo "" > env_name
32+
echo "${{ github.event.pull_request.head.sha }}" >> ref
33+
- name: Require external environment authorization.
34+
# yamllint disable rule:indentation
35+
if: >-
36+
github.event_name == 'pull_request_target' &&
37+
!(
38+
github.event.pull_request.author_association == 'OWNER' ||
39+
github.event.pull_request.author_association == 'MEMBER'
40+
)
41+
# yamllint enable rule:indentation
42+
shell: bash
43+
run: |
44+
echo "pr-actions-approval" > env_name
45+
echo "${{ github.event.pull_request.head.sha }}" >> ref
46+
- name: Set Output
47+
id: output
48+
shell: bash
49+
run: |
50+
echo "env: $(cat env_name)"
51+
echo "ref: $(cat ref)"
52+
echo "env-name=$(cat env_name)" >> $GITHUB_OUTPUT
53+
echo "ref=$(cat ref)" >> $GITHUB_OUTPUT

.github/workflows/build_and_test.yaml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: build-and-test
33
on:
4-
pull_request:
4+
pull_request_target:
55
push:
66
branches:
77
- 'main'
@@ -11,26 +11,43 @@ on:
1111
permissions:
1212
contents: read
1313
jobs:
14+
env-protect-setup:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
env-name: ${{ steps.output.outputs.env-name }}
18+
ref: ${{ steps.output.outputs.ref }}
19+
steps:
20+
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
21+
- id: output
22+
uses: ./.github/actions/env_protected_pr
23+
authorize:
24+
runs-on: ubuntu-latest
25+
needs: env-protect-setup
26+
environment: ${{ needs.env-protect-setup.outputs.env-name }}
27+
steps:
28+
- run: echo "Authorized"
1429
get-dev-image:
30+
needs: authorize
1531
uses: ./.github/workflows/get_image.yaml
1632
with:
1733
image-base-name: "dev_image_with_extras"
1834
clang-tidy:
19-
needs: get-dev-image
20-
runs-on: [self-hosted, nokvm]
35+
runs-on: ubuntu-latest-16-cores
36+
needs: [authorize, env-protect-setup, get-dev-image]
2137
container:
2238
image: ${{ needs.get-dev-image.outputs.image-with-tag }}
23-
volumes:
24-
- /etc/bazelrc:/etc/bazelrc
25-
options: --cpus 16
2639
steps:
2740
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
2841
with:
2942
fetch-depth: 0
43+
ref: ${{ needs.env-protect-setup.outputs.ref }}
3044
- name: Add pwd to git safe dir
3145
run: git config --global --add safe.directory `pwd`
3246
- name: get bazel config
3347
uses: ./.github/actions/bazelrc
48+
with:
49+
use_remote_exec: 'true'
50+
BB_API_KEY: ${{ secrets.BB_IO_API_KEY }}
3451
- name: Save Diff Info
3552
run: ./ci/save_diff_info.sh
3653
- name: Run Clang Tidy
@@ -45,24 +62,23 @@ jobs:
4562
# yamllint enable rule:indentation
4663
code-coverage:
4764
if: github.event_name == 'push'
48-
needs: get-dev-image
49-
runs-on: [self-hosted, nokvm]
65+
needs: [authorize, env-protect-setup, get-dev-image]
66+
runs-on: ubuntu-latest-16-cores
5067
container:
5168
image: ${{ needs.get-dev-image.outputs.image-with-tag }}
52-
volumes:
53-
- /etc/bazelrc:/etc/bazelrc
54-
# Needs to be priviledged to enable IPV6
55-
options: --cpus 16 --privileged
5669
steps:
5770
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
5871
with:
5972
fetch-depth: 0
73+
ref: ${{ needs.env-protect-setup.outputs.ref }}
6074
- name: Add pwd to git safe dir
6175
run: git config --global --add safe.directory `pwd`
6276
- name: get bazel config
6377
uses: ./.github/actions/bazelrc
6478
with:
6579
dev: 'false'
80+
use_remote_exec: 'true'
81+
BB_API_KEY: ${{ secrets.BB_IO_API_KEY }}
6682
- name: Collect and upload coverage
6783
env:
6884
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -71,23 +87,24 @@ jobs:
7187
sysctl -w net.ipv6.conf.lo.disable_ipv6=0
7288
./ci/collect_coverage.sh -u -b main -c "$(git rev-parse HEAD)" -r pixie-io/pixie
7389
generate-matrix:
74-
needs: get-dev-image
75-
runs-on: [self-hosted, nokvm]
90+
needs: [authorize, env-protect-setup, get-dev-image]
91+
runs-on: ubuntu-latest-16-cores
7692
container:
7793
image: ${{ needs.get-dev-image.outputs.image-with-tag }}
78-
volumes:
79-
- /etc/bazelrc:/etc/bazelrc
80-
options: --cpus 16
8194
outputs:
8295
matrix: ${{ steps.set-matrix.outputs.matrix }}
8396
steps:
8497
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
8598
with:
8699
fetch-depth: 0
100+
ref: ${{ needs.env-protect-setup.outputs.ref }}
87101
- name: Add pwd to git safe dir
88102
run: git config --global --add safe.directory `pwd`
89103
- name: get bazel config
90104
uses: ./.github/actions/bazelrc
105+
with:
106+
use_remote_exec: 'true'
107+
BB_API_KEY: ${{ secrets.BB_IO_API_KEY }}
91108
- name: Set matrix
92109
id: set-matrix
93110
shell: bash
@@ -103,22 +120,19 @@ jobs:
103120
bazel_buildables_*
104121
bazel_tests_*
105122
build-and-test:
106-
needs: [get-dev-image, generate-matrix]
107-
runs-on:
108-
- self-hosted
109-
- ${{ matrix.runner }}
123+
needs: [authorize, env-protect-setup, get-dev-image, generate-matrix]
124+
runs-on: ubuntu-latest-16-cores
110125
container:
111126
image: ${{ needs.get-dev-image.outputs.image-with-tag }}
112-
volumes:
113-
- /etc/bazelrc:/etc/bazelrc
114-
- /var/run/docker.sock:/var/run/docker.sock
115127
options: --privileged
116128
if: ${{ needs.generate-matrix.outputs.matrix && (toJson(fromJson(needs.generate-matrix.outputs.matrix)) != '[]') }}
117129
strategy:
118130
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
119131
fail-fast: false
120132
steps:
121133
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
134+
with:
135+
ref: ${{ needs.env-protect-setup.outputs.ref }}
122136
- name: Add pwd to git safe dir
123137
run: git config --global --add safe.directory `pwd`
124138
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
@@ -127,11 +141,15 @@ jobs:
127141
uses: ./.github/actions/bazelrc
128142
with:
129143
dev: 'true'
144+
use_remote_exec: 'true'
145+
BB_API_KEY: ${{ secrets.BB_IO_API_KEY }}
130146
- name: get ci bazel config
131147
if: github.event_name == 'push'
132148
uses: ./.github/actions/bazelrc
133149
with:
134150
dev: 'false'
151+
use_remote_exec: 'true'
152+
BB_API_KEY: ${{ secrets.BB_IO_API_KEY }}
135153
- name: Build ${{ matrix.name }}
136154
shell: bash
137155
# yamllint disable rule:indentation

ci/github/matrix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ elif [[ "${event_name}" == "schedule" ]]; then
5858
build_deps_flags+=("-a" "-b")
5959
extra_bazel_args+=("--runs_per_test=${nightly_regression_test_iterations}")
6060
kernel_versions=( "${all_kernel_versions[@]}" )
61-
elif [[ "${event_name}" == "pull_request" ]]; then
61+
elif [[ "${event_name}" == "pull_request_target" ]] || [[ "${event_name}" == "pull_request" ]]; then
6262
# Ignore bazel dependency tracking and run all targets if #ci:ignore-deps is in the commit message.
6363
if check_tag '#ci:ignore-deps'; then
6464
echo "Found #ci:ignore-deps tag. Building all targets" >&2

0 commit comments

Comments
 (0)