Skip to content

Commit 2fd65fb

Browse files
[On-Week] Automate chromium linux builds for reporting in Kibana (elastic#212674)
## Summary Closes elastic#38277 This PR ~attempts to take a stab at automating~ automates the process for building the linux headless chromium used for reporting within Kibana. The Idea here is that one would simply only need create an issue within the Kibana project that will then trigger the build for chromium, we'll be leveraging GitHub actions for this, the Github workflow defined only kicks in when an issue is created with the label `trigger-chromium-build`, when such an issue is created, the body of the issue is analysed; there's an expectation that the body would contain a fenced codeblock of type json that specifies the property `puppeteer_version`, if this is found this value is read and, we then trigger a build on buildkite passing along this value, in the case where there are multiple fenced code blocks specifying the expected property `puppeteer_version` we leave a message that the issue body be modified, also if the expected label was added but the expected property is not found we also leave a message prompting that the expected property be provided. Once the build has commenced a message containing the link to the build would be provided as initial feedback to the user, also on completion another message is provided to the user, that provides a link to the PR containing all the required changes to update puppeteer to the version specified. ~It's also worth pointing out that this PR also, modifies the source for `win`, `mac` chromium binaries to leverage the [JSON API endpoint](https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints) provided by Google to get the required binaries for chromium headless in a deterministic way, which in turns is part of what makes this automation possible.~ ## How to test this - If you'd love to test the Github action too without the PR being merging in just yet, you should consider setting up [act](https://github.com/nektos/act), alongside it's companion [vscode extension](https://sanjulaganepola.github.io/github-local-actions-docs/) , we'll then want to create a payload file providing similar data that github would return for our workflow trigger, more info about setting this up [here](https://sanjulaganepola.github.io/github-local-actions-docs/usage/settings/#payloads). The payload file we'd want would be something along the following lines; ```json { "action": "labeled", "label":{ "name": "trigger-chromium-build" }, "issue": { "number": 1, "title": "Issue 1", "author_association": "MEMBER", "labels": [ { "name": "trigger-chromium-build" } ], "body": "\n## Random text \n\n ~~~json\n{\n \"puppeteer_version\": \"24.6.1\" \n}\n~~~\n~~~json\n{\n \"some_random_value\": \"23.0.1\" \n}\n~~~" } } ``` - To test the actual build process it can be initiated through this specific pipeline https://buildkite.com/elastic/kibana-migration-pipeline-staging by creating a custom build on `pull/212674/head` (this pull request) with the env variable similar to this ``` TESTED_PIPELINE_PATH=.buildkite/pipelines/chromium_linux_build/build_chromium.yml PUPPETEER_VERSION=24.6.1 GITHUB_ISSUE_NUMBER=212732 GITHUB_ISSUE_BASE_OWNER=elastic GITHUB_ISSUE_BASE_REPO=kibana GITHUB_ISSUE_TRIGGER_USER=eokoneyo ``` PS: Issue elastic#212732 is an issue that's been created to test providing feedback to the user about the build process, re-triggering a build on an existing issue updates the comments in place. <!-- ### Where to go from here? - Ideas and thoughts welcome --> <!-- ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --> --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 0acd88e commit 2fd65fb

File tree

14 files changed

+3631
-22
lines changed

14 files changed

+3631
-22
lines changed

.buildkite/package-lock.json

Lines changed: 2598 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.buildkite/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@octokit/rest": "^18.10.0",
14+
"adm-zip": "^0.5.16",
1415
"axios": "^1.8.3",
1516
"globby": "^11.1.0",
1617
"js-yaml": "^4.1.0",
@@ -21,11 +22,14 @@
2122
"devDependencies": {
2223
"@types/chai": "^4.3.3",
2324
"@types/js-yaml": "^4.0.9",
25+
"@types/jscodeshift": "^0.12.0",
2426
"@types/minimatch": "^3.0.5",
2527
"@types/minimist": "^1.2.5",
2628
"@types/mocha": "^10.0.1",
2729
"@types/node": "^15.12.2",
2830
"chai": "^4.3.10",
31+
"chai-snapshot-tests": "^0.6.0",
32+
"jscodeshift": "^17.1.2",
2933
"mocha": "^11.0.1",
3034
"nock": "^12.0.2",
3135
"ts-node": "^10.9.2",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/rre.schema.json
2+
apiVersion: backstage.io/v1alpha1
3+
kind: Resource
4+
metadata:
5+
name: bk-kibana-chromium-linux-build
6+
description: Create chromium linux builds for the Kibana Reporting feature
7+
links:
8+
- title: Pipeline link
9+
url: https://buildkite.com/elastic/kibana-chromium-linux-build
10+
spec:
11+
type: buildkite-pipeline
12+
owner: group:response-ops
13+
system: buildkite
14+
implementation:
15+
apiVersion: buildkite.elastic.dev/v1
16+
kind: Pipeline
17+
metadata:
18+
name: kibana / Chromium Linux Build
19+
description: Creates headless Chromium Linux builds
20+
spec:
21+
env:
22+
SLACK_NOTIFICATIONS_CHANNEL: "#kibana-alerting"
23+
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: "false"
24+
repository: elastic/kibana
25+
branch_configuration: main
26+
default_branch: main
27+
pipeline_file: ".buildkite/pipelines/chromium_linux_build/build_chromium.yml"
28+
provider_settings:
29+
trigger_mode: none
30+
teams:
31+
kibana-operations:
32+
access_level: MANAGE_BUILD_AND_READ
33+
appex-sharedux:
34+
access_level: MANAGE_BUILD_AND_READ
35+
response-ops:
36+
access_level: MANAGE_BUILD_AND_READ
37+
everyone:
38+
access_level: READ_ONLY
39+
tags:
40+
- kibana

.buildkite/pipeline-resource-definitions/locations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-artifacts-staging.yml
1515
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-artifacts-trigger.yml
1616
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-chrome-forward-testing.yml
17+
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-chromium-linux-build.yml
1718
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-codeql.yml
1819
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-console-definitions-sync.yml
1920
- https://github.com/elastic/kibana/blob/main/.buildkite/pipeline-resource-definitions/kibana-coverage-daily.yml
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
env:
2+
GITHUB_PR_TARGET_BRANCH: 'main' # common utils needs this value to be set
3+
4+
steps:
5+
- command: |
6+
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts \
7+
--message "Linux headless chromium build started at: $BUILDKITE_BUILD_URL" \
8+
--context "chromium-linux-build-job-start" \
9+
--issue-number $GITHUB_ISSUE_NUMBER \
10+
--repository $GITHUB_ISSUE_BASE_REPO \
11+
--repository-owner $GITHUB_ISSUE_BASE_OWNER \
12+
--clear-previous
13+
label: Comment with job URL on issue
14+
agents:
15+
provider: gcp
16+
image: family/kibana-ubuntu-2004
17+
imageProject: elastic-images-prod
18+
machineType: n2-standard-2
19+
timeout_in_minutes: 5
20+
21+
- command: |
22+
.buildkite/scripts/pipelines/chromium_linux_build/chromium_version.sh
23+
label: Infer chromium version for puppeteer version
24+
key: infer_chromium_version
25+
agents:
26+
provider: gcp
27+
image: family/kibana-ubuntu-2004
28+
imageProject: elastic-images-prod
29+
machineType: n2-standard-2
30+
timeout_in_minutes: 5
31+
32+
- command: "PLATFORM_VARIANT={{matrix}} .buildkite/scripts/pipelines/chromium_linux_build/build.sh"
33+
label: "Build {{matrix}} linux headless chromium"
34+
depends_on: "infer_chromium_version"
35+
key: build_chromium
36+
env:
37+
DEBIAN_FRONTEND: noninteractive
38+
agents:
39+
image: family/kibana-ubuntu-2004
40+
imageProject: elastic-images-prod
41+
provider: gcp
42+
machineType: c2d-highcpu-112
43+
diskSizeGb: 275
44+
matrix:
45+
- "x64"
46+
- "arm64"
47+
48+
- command: node .buildkite/scripts/pipelines/chromium_linux_build/issue_feedback/entry.js
49+
label: provided feedback to issue created to update puppeteer
50+
depends_on: "build_chromium"
51+
env:
52+
KIBANA_MACHINE_USERNAME: kibanamachine
53+
KIBANA_MACHINE_EMAIL: 42973632+kibanamachine@users.noreply.github.com
54+
agents:
55+
provider: gcp
56+
image: family/kibana-ubuntu-2004
57+
imageProject: elastic-images-prod
58+
machineType: n2-standard-2
59+
timeout_in_minutes: 30

.buildkite/scripts/common/activate_service_account.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ if [[ -z "$EMAIL" ]]; then
7676
"ci-artifacts.kibana.dev")
7777
EMAIL="kibana-ci-access-artifacts@$GCLOUD_EMAIL_POSTFIX"
7878
;;
79+
"kibana-ci-access-chromium-blds")
80+
EMAIL="kibana-ci-access-chromium-blds@$GCLOUD_EMAIL_POSTFIX"
81+
;;
7982
*)
8083
EMAIL="$BUCKET_NAME@$GCLOUD_EMAIL_POSTFIX"
8184
;;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
CHROMIUM_COMMIT_HASH=$(buildkite-agent meta-data get "chromium_commit_hash")
6+
7+
echo "---Preparing to build Chromium of commit hash: $CHROMIUM_COMMIT_HASH"
8+
9+
BUILD_ROOT_DIR="$HOME/chromium"
10+
11+
KIBANA_CHECKOUT_DIR="$(pwd)"
12+
13+
BUILD_SCRIPT="$KIBANA_CHECKOUT_DIR/x-pack/build_chromium"
14+
15+
# Create a dedicated working directory outside of the default buildkite working directory.
16+
mkdir "$BUILD_ROOT_DIR" && cd "$BUILD_ROOT_DIR"
17+
18+
ARTIFACT_STAGING_STORAGE_BUCKET="gs://headless_shell_staging"
19+
ARTIFACT_PROD_STORAGE_BUCKET="gs://headless_shell"
20+
21+
ARTIFACT_QUERY="chromium-${CHROMIUM_COMMIT_HASH:0:7}-.*_$PLATFORM_VARIANT"
22+
23+
## impersonate service account that has access to our storage bucket
24+
"$KIBANA_CHECKOUT_DIR/.buildkite/scripts/common/activate_service_account.sh" "kibana-ci-access-chromium-blds"
25+
26+
# Query to determine if expected build artifact from a prior build exists,
27+
# the build.py script uploads the build artifact to the staging bucket
28+
artifacts=$(gsutil ls "$ARTIFACT_STAGING_STORAGE_BUCKET" | grep "$ARTIFACT_QUERY" || true)
29+
30+
if [[ -z "$artifacts" ]]; then
31+
echo "No files found matching the query: $ARTIFACT_QUERY"
32+
33+
echo "---Chromium build does not exist in the bucket, proceeding with the build"
34+
35+
# Install the required packages for building chromium
36+
sudo apt-get update && \
37+
sudo apt-get install -y curl git build-essential pkg-config gcc gperf python3 && \
38+
sudo rm -rf /var/lib/apt/lists/*
39+
40+
BUILD_SCRIPT_SYMLINK="$BUILD_ROOT_DIR/build_scripts"
41+
42+
# link existing build_chromium directory from kibana
43+
ln -s "$BUILD_SCRIPT" "$BUILD_SCRIPT_SYMLINK"
44+
45+
# Allow our scripts to use depot_tools commands
46+
export PATH=$BUILD_ROOT_DIR/depot_tools:$PATH
47+
48+
# Install the OS packages, configure the environment, download the chromium source (56GB)
49+
python3 "$BUILD_SCRIPT_SYMLINK/init.py"
50+
51+
echo "---Building $PLATFORM_VARIANT Chromium of commit hash: $CHROMIUM_COMMIT_HASH"
52+
53+
# Run the build script with the path to the chromium src directory, the git commit hash
54+
python3 "$BUILD_SCRIPT_SYMLINK/build.py" "$CHROMIUM_COMMIT_HASH" "$PLATFORM_VARIANT"
55+
56+
echo "---Upload build artefact to prod storage bucket"
57+
58+
gsutil cp "$BUILD_ROOT_DIR/chromium/src/out/headless/chromium-*" "$ARTIFACT_PROD_STORAGE_BUCKET"
59+
60+
echo "---Persisting build artefact to buildkite for following steps"
61+
62+
buildkite-agent artifact upload "$BUILD_ROOT_DIR/chromium/src/out/headless/chromium-*"
63+
64+
else
65+
echo "$artifacts" | while read -r file; do
66+
gsutil cp "$file" .
67+
done
68+
69+
shopt -s nullglob
70+
files=("chromium-*")
71+
shopt -u nullglob
72+
73+
if [ ${#files[@]} -gt 0 ]; then
74+
echo "---Chromium build already exists in the bucket, skipping build"
75+
# Upload the existing build artifact to buildkite so it can be used in the next steps,
76+
# and accessible without necessarily having access to the storage bucket itself
77+
buildkite-agent artifact upload "chromium-*"
78+
fi
79+
fi
80+
81+
echo "---Build completed"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
source .buildkite/scripts/common/util.sh
6+
.buildkite/scripts/bootstrap.sh
7+
8+
echo "---Attempting to compute chromium version for provided puppeteer version"
9+
10+
CHROMIUM_VERSION_OUTPUT=$(node scripts/chromium_version $PUPPETEER_VERSION)
11+
12+
echo "$CHROMIUM_VERSION_OUTPUT" | grep -i "chromium commit" | awk '{print $5}' | buildkite-agent meta-data set "chromium_commit_hash"
13+
echo "$CHROMIUM_VERSION_OUTPUT" | grep -i "chrome version" | awk '{print $5}' | buildkite-agent meta-data set "chromium_version"
14+
echo "$CHROMIUM_VERSION_OUTPUT" | grep -i "chromium revision" | awk '{print $5}' | buildkite-agent meta-data set "chromium_revision"

.buildkite/scripts/pipelines/chromium_linux_build/issue_feedback/__snapshots__/transform_path_file.test.ts.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)