Skip to content

Commit cb94251

Browse files
authored
[8.16] [ci] Click to deploy cloud (#205623) (#208045)
# Backport This will backport the following commits from `main` to `8.16`: - [[ci] Click to deploy cloud (#205623)](#205623) <!--- Backport version: 9.6.4 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Alex Szabo","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-23T09:26:03Z","message":"[ci] Click to deploy cloud (#205623)\n\n## Summary\nSimilar to https://github.com/elastic/kibana/pull/195581\n\nAdds a pipeline that builds Kibana and starts cloud deployment without\ngoing through the CI test suites (as in normal pull-request pipeline\nruns). It can be useful if a developer would like to save time/compute\non re-building/re-testing the whole project before deploying to the\ncloud.\n\nAdded labels (`ci:cloud-deploy / ci:cloud-redeploy`) are required\nsimilarly to the usual CI flow.\n\nRelated to: https://github.com/elastic/kibana-operations/issues/121","sha":"e36833b3a60b62f794f47951f5ceae842d6c44b3","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","v9.0.0","backport:all-open"],"title":"[ci] Click to deploy cloud","number":205623,"url":"https://github.com/elastic/kibana/pull/205623","mergeCommit":{"message":"[ci] Click to deploy cloud (#205623)\n\n## Summary\nSimilar to https://github.com/elastic/kibana/pull/195581\n\nAdds a pipeline that builds Kibana and starts cloud deployment without\ngoing through the CI test suites (as in normal pull-request pipeline\nruns). It can be useful if a developer would like to save time/compute\non re-building/re-testing the whole project before deploying to the\ncloud.\n\nAdded labels (`ci:cloud-deploy / ci:cloud-redeploy`) are required\nsimilarly to the usual CI flow.\n\nRelated to: https://github.com/elastic/kibana-operations/issues/121","sha":"e36833b3a60b62f794f47951f5ceae842d6c44b3"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205623","number":205623,"mergeCommit":{"message":"[ci] Click to deploy cloud (#205623)\n\n## Summary\nSimilar to https://github.com/elastic/kibana/pull/195581\n\nAdds a pipeline that builds Kibana and starts cloud deployment without\ngoing through the CI test suites (as in normal pull-request pipeline\nruns). It can be useful if a developer would like to save time/compute\non re-building/re-testing the whole project before deploying to the\ncloud.\n\nAdded labels (`ci:cloud-deploy / ci:cloud-redeploy`) are required\nsimilarly to the usual CI flow.\n\nRelated to: https://github.com/elastic/kibana-operations/issues/121","sha":"e36833b3a60b62f794f47951f5ceae842d6c44b3"}}]}] BACKPORT-->
1 parent 6c64d5b commit cb94251

File tree

9 files changed

+451
-6
lines changed

9 files changed

+451
-6
lines changed

.buildkite/package-lock.json

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

.buildkite/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"globby": "^11.1.0",
1616
"js-yaml": "^4.1.0",
1717
"minimatch": "^5.0.1",
18+
"minimist": "^1.2.8",
1819
"tslib": "*"
1920
},
2021
"devDependencies": {
2122
"@types/chai": "^4.3.3",
2223
"@types/js-yaml": "^4.0.9",
2324
"@types/minimatch": "^3.0.5",
25+
"@types/minimist": "^1.2.5",
2426
"@types/mocha": "^10.0.1",
2527
"@types/node": "^15.12.2",
2628
"chai": "^4.3.10",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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-deploy-cloud-from-pr
6+
description: 'Builds Kibana and initiates a Kibana cloud deployment from a PR'
7+
links:
8+
- url: 'https://buildkite.com/elastic/kibana-deploy-cloud-from-pr'
9+
title: Pipeline link
10+
spec:
11+
type: buildkite-pipeline
12+
system: buildkite
13+
owner: 'group:kibana-operations'
14+
implementation:
15+
apiVersion: buildkite.elastic.dev/v1
16+
kind: Pipeline
17+
metadata:
18+
name: kibana / deploy cloud from PR
19+
description: 'Builds Kibana and initiates a Kibana cloud deployment from a PR'
20+
spec:
21+
env:
22+
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'false'
23+
24+
allow_rebuilds: false
25+
branch_configuration: main
26+
default_branch: main
27+
repository: elastic/kibana
28+
pipeline_file: .buildkite/pipelines/build_pr_and_deploy_cloud.yml
29+
provider_settings:
30+
build_pull_requests: true
31+
prefix_pull_request_fork_branch_names: false
32+
skip_pull_request_builds_for_existing_commits: true
33+
trigger_mode: none
34+
cancel_intermediate_builds: true
35+
teams:
36+
kibana-operations:
37+
access_level: MANAGE_BUILD_AND_READ
38+
appex-qa:
39+
access_level: MANAGE_BUILD_AND_READ
40+
kibana-tech-leads:
41+
access_level: MANAGE_BUILD_AND_READ
42+
everyone:
43+
access_level: BUILD_AND_READ
44+
tags:
45+
- kibana

.buildkite/pipeline-utils/github/github.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import { Octokit, RestEndpointMethodTypes } from '@octokit/rest';
1111

12+
export const KIBANA_COMMENT_SIGIL = 'kbn-message-context';
13+
1214
const github = new Octokit({
1315
auth: process.env.GITHUB_TOKEN,
1416
});
@@ -93,6 +95,76 @@ export const doAnyChangesMatch = async (
9395
return anyFilesMatchRequired;
9496
};
9597

98+
export function addComment(
99+
comment: string,
100+
owner = process.env.GITHUB_PR_BASE_OWNER,
101+
repo = process.env.GITHUB_PR_BASE_REPO,
102+
prNumber: undefined | string | number = process.env.GITHUB_PR_NUMBER
103+
) {
104+
if (!owner || !repo || !prNumber) {
105+
throw Error(
106+
"Couldn't retrieve Github PR info from environment variables in order to add a comment"
107+
);
108+
}
109+
110+
return github.issues.createComment({
111+
owner,
112+
repo,
113+
issue_number: typeof prNumber === 'number' ? prNumber : parseInt(prNumber, 10),
114+
body: comment,
115+
});
116+
}
117+
118+
export async function upsertComment(
119+
messageOpts: {
120+
commentBody: string;
121+
commentContext: string;
122+
clearPrevious: boolean;
123+
},
124+
owner = process.env.GITHUB_PR_BASE_OWNER,
125+
repo = process.env.GITHUB_PR_BASE_REPO,
126+
prNumber: undefined | string | number = process.env.GITHUB_PR_NUMBER
127+
) {
128+
const { commentBody, commentContext, clearPrevious } = messageOpts;
129+
if (!owner || !repo || !prNumber) {
130+
throw Error(
131+
"Couldn't retrieve Github PR info from environment variables in order to add a comment"
132+
);
133+
}
134+
if (!commentContext) {
135+
throw Error('Comment context is required when updating a comment');
136+
}
137+
138+
const commentMarker = `<!-- ${KIBANA_COMMENT_SIGIL}:${commentContext} -->`;
139+
const body = `${commentMarker}\n${commentBody}`;
140+
141+
const existingComment = (
142+
await github.paginate(github.issues.listComments, {
143+
owner,
144+
repo,
145+
issue_number: typeof prNumber === 'number' ? prNumber : parseInt(prNumber, 10),
146+
})
147+
).find((comment) => comment.body?.includes(commentMarker));
148+
149+
if (!existingComment) {
150+
return addComment(body, owner, repo, prNumber);
151+
} else if (clearPrevious) {
152+
await github.issues.deleteComment({
153+
owner,
154+
repo,
155+
comment_id: existingComment.id,
156+
});
157+
return addComment(body, owner, repo, prNumber);
158+
} else {
159+
return github.issues.updateComment({
160+
owner,
161+
repo,
162+
comment_id: existingComment.id,
163+
body,
164+
});
165+
}
166+
}
167+
96168
export function getGithubClient() {
97169
return github;
98170
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
env:
2+
ELASTIC_PR_COMMENTS_ENABLED: 'true'
3+
ELASTIC_GITHUB_BUILD_COMMIT_STATUS_ENABLED: 'true'
4+
GITHUB_BUILD_COMMIT_STATUS_CONTEXT: kibana-deploy-cloud-from-pr
5+
6+
steps:
7+
- group: 'Cloud Deployment'
8+
if: "build.env('GITHUB_PR_LABELS') =~ /(ci:cloud-deploy|ci:cloud-redeploy)/"
9+
10+
steps:
11+
- command: .buildkite/scripts/lifecycle/pre_build.sh
12+
label: Pre-Build
13+
timeout_in_minutes: 10
14+
agents:
15+
provider: gcp
16+
image: family/kibana-ubuntu-2004
17+
imageProject: elastic-images-prod
18+
machineType: n2-standard-2
19+
retry:
20+
automatic:
21+
- exit_status: '*'
22+
limit: 1
23+
24+
- command: |
25+
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts \
26+
--message "PR Cloud deployment started at: $BUILDKITE_BUILD_URL" \
27+
--context "cloud-deploy-job" \
28+
--clear-previous
29+
label: Comment with job URL
30+
agents:
31+
provider: gcp
32+
image: family/kibana-ubuntu-2004
33+
imageProject: elastic-images-prod
34+
machineType: n2-standard-2
35+
timeout_in_minutes: 5
36+
37+
- command: .buildkite/scripts/steps/build_kibana.sh
38+
label: Build Kibana Distribution
39+
agents:
40+
provider: gcp
41+
image: family/kibana-ubuntu-2004
42+
imageProject: elastic-images-prod
43+
machineType: n2-standard-8
44+
preemptible: true
45+
diskSizeGb: 125
46+
if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''"
47+
timeout_in_minutes: 90
48+
retry:
49+
automatic:
50+
- exit_status: '-1'
51+
limit: 3
52+
53+
- wait: ~
54+
55+
- command: .buildkite/scripts/steps/cloud/build_and_deploy.sh
56+
label: 'Build and Deploy to Cloud'
57+
agents:
58+
provider: gcp
59+
image: family/kibana-ubuntu-2004
60+
imageProject: elastic-images-prod
61+
machineType: n2-standard-2
62+
preemptible: true
63+
timeout_in_minutes: 30
64+
retry:
65+
automatic:
66+
- exit_status: '-1'
67+
limit: 3
68+
69+
- wait: ~
70+
71+
- command: |
72+
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts \
73+
--message "Cloud deployment initiated, see credentials at: $BUILDKITE_BUILD_URL" \
74+
--context "cloud-deploy-job" \
75+
--clear-previous
76+
label: Comment with job URL
77+
agents:
78+
provider: gcp
79+
image: family/kibana-ubuntu-2004
80+
imageProject: elastic-images-prod
81+
machineType: n2-standard-2
82+
timeout_in_minutes: 5
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
env:
2+
ELASTIC_PR_COMMENTS_ENABLED: 'true'
3+
ELASTIC_GITHUB_BUILD_COMMIT_STATUS_ENABLED: 'true'
4+
GITHUB_BUILD_COMMIT_STATUS_CONTEXT: kibana-deploy-project-from-pr
5+
6+
steps:
7+
- group: 'Project Deployment'
8+
if: "build.env('GITHUB_PR_LABELS') =~ /ci:project-deploy-(elasticsearch|observability|security)/"
9+
10+
steps:
11+
- command: .buildkite/scripts/lifecycle/pre_build.sh
12+
label: Pre-Build
13+
timeout_in_minutes: 10
14+
agents:
15+
provider: gcp
16+
image: family/kibana-ubuntu-2004
17+
imageProject: elastic-images-prod
18+
machineType: n2-standard-2
19+
retry:
20+
automatic:
21+
- exit_status: '*'
22+
limit: 1
23+
24+
- command: |
25+
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts \
26+
--message "PR Project deployment started at: $BUILDKITE_BUILD_URL" \
27+
--context "project-deploy-job" \
28+
--clear-previous
29+
label: Comment with job URL
30+
agents:
31+
provider: gcp
32+
image: family/kibana-ubuntu-2004
33+
imageProject: elastic-images-prod
34+
machineType: n2-standard-2
35+
timeout_in_minutes: 5
36+
37+
- wait: ~
38+
39+
- command: .buildkite/scripts/steps/artifacts/docker_image.sh
40+
label: 'Build Project Image'
41+
key: build_project_image
42+
agents:
43+
provider: gcp
44+
image: family/kibana-ubuntu-2004
45+
imageProject: elastic-images-prod
46+
machineType: n2-standard-16
47+
preemptible: true
48+
timeout_in_minutes: 60
49+
retry:
50+
automatic:
51+
- exit_status: '-1'
52+
limit: 3
53+
54+
- wait: ~
55+
- command: .buildkite/scripts/steps/serverless/deploy.sh
56+
label: 'Deploy Project'
57+
agents:
58+
provider: gcp
59+
image: family/kibana-ubuntu-2004
60+
imageProject: elastic-images-prod
61+
machineType: n2-standard-4
62+
preemptible: true
63+
timeout_in_minutes: 10
64+
65+
- wait: ~
66+
67+
- command: |
68+
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts \
69+
--message "Project deployed, see credentials at: $BUILDKITE_BUILD_URL" \
70+
--context "project-deploy-job" \
71+
--clear-previous
72+
label: Comment with job URL
73+
agents:
74+
provider: gcp
75+
image: family/kibana-ubuntu-2004
76+
imageProject: elastic-images-prod
77+
machineType: n2-standard-2
78+
timeout_in_minutes: 5

0 commit comments

Comments
 (0)