forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI] Fix project build & deploy job (elastic#196562)
## Summary In elastic#195581 we've added the option to deploy through the clickable triggers. But in it's current state, it's broken in several aspects. (1) It's not starting on click. Triggers was resulting in a 422 on Buildkite's side, and after digging more into it, this was the error: <img width="1019" alt="Screenshot 2024-10-16 at 16 53 13" src="https://github.com/user-attachments/assets/f602dde9-2cc4-474f-b432-a3d4f9d5ae91"> Apparently, building PRs needs to be enabled on jobs that want to be triggered through the PR bot. (2) It is set up to run regardless of the labels (3) There's no feedback on runs ## Changes This PR: - enables buildability in the pipeline's config - exits early if deploy labels are missing - adds a comment on the PR if a deploy job is started or finished - removes the kibana build step, it's not needed, as we have a step to build the docker image TODO: - [x] Add feedback about a started job (either through a non-required check, or a github comment) - [x] Early exit if a label is missing There are several other builds started right now, because the logic that would trigger a build on changing a draft to ready. To be fixed in elastic/buildkite-pr-bot#78 Tested after manually by enabling the option on the UI, and triggering through the checkbox: https://buildkite.com/elastic/kibana-deploy-project-from-pr/builds/23
- Loading branch information
Showing
5 changed files
with
160 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 70 additions & 51 deletions
121
.buildkite/pipelines/serverless_deployment/project-build-and-deploy-pr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,72 @@ | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
env: | ||
ELASTIC_PR_COMMENTS_ENABLED: 'true' | ||
GITHUB_BUILD_COMMIT_STATUS_ENABLED: 'true' | ||
GITHUB_BUILD_COMMIT_STATUS_CONTEXT: kibana-deploy-project-from-pr | ||
|
||
steps: | ||
- command: .buildkite/scripts/lifecycle/pre_build.sh | ||
label: Pre-Build | ||
timeout_in_minutes: 10 | ||
agents: | ||
machineType: n2-standard-2 | ||
retry: | ||
automatic: | ||
- exit_status: '*' | ||
limit: 1 | ||
|
||
- wait: ~ | ||
|
||
- command: .buildkite/scripts/steps/build_kibana.sh | ||
label: Build Kibana Distribution and Plugins | ||
agents: | ||
machineType: n2-standard-16 | ||
preemptible: true | ||
key: build | ||
if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''" | ||
timeout_in_minutes: 90 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 3 | ||
|
||
- wait: ~ | ||
|
||
- command: .buildkite/scripts/steps/artifacts/docker_image.sh | ||
label: 'Build Project Image' | ||
key: build_project_image | ||
agents: | ||
machineType: n2-standard-16 | ||
preemptible: true | ||
timeout_in_minutes: 60 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 3 | ||
|
||
- wait: ~ | ||
|
||
- command: .buildkite/scripts/steps/serverless/deploy.sh | ||
label: 'Deploy Project' | ||
agents: | ||
machineType: n2-standard-4 | ||
preemptible: true | ||
timeout_in_minutes: 10 | ||
- group: 'Project Deployment' | ||
if: "build.env('GITHUB_PR_LABELS') =~ /ci:project-deploy-(elasticsearch|observability|security)/" | ||
|
||
steps: | ||
- command: .buildkite/scripts/lifecycle/pre_build.sh | ||
label: Pre-Build | ||
timeout_in_minutes: 10 | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
machineType: n2-standard-2 | ||
retry: | ||
automatic: | ||
- exit_status: '*' | ||
limit: 1 | ||
|
||
- command: | | ||
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts "PR Project deployment started at: $BUILDKITE_BUILD_URL" | ||
label: Comment with job URL | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
machineType: n2-standard-2 | ||
timeout_in_minutes: 5 | ||
- wait: ~ | ||
|
||
- command: .buildkite/scripts/steps/artifacts/docker_image.sh | ||
label: 'Build Project Image' | ||
key: build_project_image | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
machineType: n2-standard-16 | ||
preemptible: true | ||
timeout_in_minutes: 60 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 3 | ||
|
||
- wait: ~ | ||
- command: .buildkite/scripts/steps/serverless/deploy.sh | ||
label: 'Deploy Project' | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
machineType: n2-standard-4 | ||
preemptible: true | ||
timeout_in_minutes: 10 | ||
|
||
- wait: ~ | ||
|
||
- command: | | ||
ts-node .buildkite/scripts/lifecycle/comment_on_pr.ts "Project deployed, see credentials at: $BUILDKITE_BUILD_URL" | ||
label: Comment with job URL | ||
agents: | ||
provider: gcp | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
machineType: n2-standard-2 | ||
timeout_in_minutes: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { addComment } from '#pipeline-utils'; | ||
|
||
const ALLOWED_ENV_VARS = [ | ||
'BUILDKITE_BRANCH', | ||
'BUILDKITE_BUILD_ID', | ||
'BUILDKITE_BUILD_NUMBER', | ||
'BUILDKITE_BUILD_URL', | ||
'BUILDKITE_COMMIT', | ||
'BUILDKITE_PIPELINE_NAME', | ||
'BUILDKITE_PIPELINE_SLUG', | ||
'GITHUB_PR_BASE_OWNER', | ||
'GITHUB_PR_BASE_REPO', | ||
'GITHUB_PR_BRANCH', | ||
'GITHUB_PR_HEAD_SHA', | ||
'GITHUB_PR_HEAD_USER', | ||
'GITHUB_PR_LABELS', | ||
'GITHUB_PR_NUMBER', | ||
'GITHUB_PR_OWNER', | ||
'GITHUB_PR_REPO', | ||
'GITHUB_PR_TARGET_BRANCH', | ||
'GITHUB_PR_TRIGGERED_SHA', | ||
'GITHUB_PR_TRIGGER_USER', | ||
'GITHUB_PR_USER', | ||
]; | ||
const DEFAULT_MESSAGE_TEMPLATE = | ||
'🚀 Buildkite job started for PR #${GITHUB_PR_NUMBER}: ${BUILDKITE_BUILD_URL}'; | ||
|
||
export function commentOnPR() { | ||
const messageTemplate = | ||
process.argv.slice(2)?.join(' ') || | ||
process.env.JOB_START_COMMENT_TEMPLATE || | ||
DEFAULT_MESSAGE_TEMPLATE; | ||
if (messageTemplate === DEFAULT_MESSAGE_TEMPLATE) { | ||
console.log('No message template provided, using default message'); | ||
} else { | ||
console.log(`Using message template: ${messageTemplate}`); | ||
} | ||
|
||
const message = messageTemplate.replace(/\${([^}]+)}/g, (_, envVar) => { | ||
if (ALLOWED_ENV_VARS.includes(envVar)) { | ||
return process.env[envVar] || ''; | ||
} else { | ||
return '${' + envVar + '}'; | ||
} | ||
}); | ||
|
||
return addComment(message); | ||
} | ||
|
||
if (require.main === module) { | ||
commentOnPR().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
} |