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.
[Ops] Buildkite job for serverless deployment (elastic#170655)
## Summary Connected to: elastic/kibana-operations#18 Pre-requisite for: elastic/kibana-operations#30 You can test the current assistant from the branch: https://buildkite.com/elastic/kibana-serverless-release-1/builds?branch=buildkite-job-for-deployment - use `DRY_RUN=1` in the runtime params to not trigger an actual release :) This PR creates the contents of a Buildkite job to assist the Kibana Serverless Release initiation process at the very beginning and lay some groundwork for further additions to the release management. At the end of the day, we would like to create a tag deploy@<timestamp> which will be picked up by another job that listens to these tags: https://buildkite.com/elastic/kibana-serverless-release. However, several parts of the preparation for release require manual research, collecting information about target releases, running scripts, etc. Any further addition to what would be useful for someone wanting to start a release could be contained here. Furthermore, we could also trigger downstream jobs from here. e.g.: https://buildkite.com/elastic/kibana-serverless-release is currently set up to listen for a git tag, but we may as well just trigger the job after we've created a tag. Check out an example run at: https://buildkite.com/elastic/kibana-serverless-release-1/builds/72 (visible only if you're a member of @ elastic/kibana-release-operators) Missing features compared to the git action: - [x] Slack notification about the started deploy - [x] full "useful links" section Missing features: - [x] there's a bit of useful context that should be integrated to the display of the FTR results (*) - [x] skip listing and analysis if a commit sha is passed in env (*) - Currently, we display the next FTR test suite that ran after the merge of the PR. However, the next FTR that will contain the changes, and show useful info related to the changeset is ONLY in the FTR that's ran after the first successful onMerge after the merge commit. Meaning: if main is failing when the change is merged, an FTR suite won't pick up the change right after. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Thomas Watson <[email protected]> Co-authored-by: Thomas Watson <[email protected]>
- Loading branch information
1 parent
a27f10e
commit 1208a8e
Showing
19 changed files
with
1,452 additions
and
7 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
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,24 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { execSync } from 'child_process'; | ||
|
||
const getKibanaDir = (() => { | ||
let kibanaDir: string | undefined; | ||
return () => { | ||
if (!kibanaDir) { | ||
kibanaDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }) | ||
.toString() | ||
.trim(); | ||
} | ||
|
||
return kibanaDir; | ||
}; | ||
})(); | ||
|
||
export { getKibanaDir }; |
33 changes: 33 additions & 0 deletions
33
.buildkite/pipelines/serverless_deployment/create_deployment_tag.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## Creates deploy@<timestamp> tag on Kibana | ||
|
||
agents: | ||
queue: kibana-default | ||
|
||
steps: | ||
- label: "List potential commits" | ||
commands: | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state initialize | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state collect_commits | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/list_commit_candidates.ts 25 | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state wait_for_selection | ||
key: select_commit | ||
|
||
- wait: ~ | ||
|
||
- label: "Collect commit info" | ||
commands: | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state collect_commit_info | ||
- bash .buildkite/scripts/serverless/create_deploy_tag/collect_commit_info.sh | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state wait_for_confirmation | ||
key: collect_data | ||
depends_on: select_commit | ||
|
||
- wait: ~ | ||
|
||
- label: ":ship: Create Deploy Tag" | ||
commands: | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state create_deploy_tag | ||
- bash .buildkite/scripts/serverless/create_deploy_tag/create_deploy_tag.sh | ||
- ts-node .buildkite/scripts/serverless/create_deploy_tag/release_wizard_messaging.ts --state tag_created | ||
env: | ||
DRY_RUN: $DRY_RUN |
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
16 changes: 16 additions & 0 deletions
16
.buildkite/scripts/serverless/create_deploy_tag/collect_commit_info.sh
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,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# SO migration comparison lives in the Kibana dev app code, needs bootstrapping | ||
.buildkite/scripts/bootstrap.sh | ||
|
||
echo "--- Collecting commit info" | ||
ts-node .buildkite/scripts/serverless/create_deploy_tag/collect_commit_info.ts | ||
|
||
cat << EOF | buildkite-agent pipeline upload | ||
steps: | ||
- block: "Confirm deployment" | ||
prompt: "Are you sure you want to deploy to production? (dry run: ${DRY_RUN:-false})" | ||
depends_on: collect_data | ||
EOF |
96 changes: 96 additions & 0 deletions
96
.buildkite/scripts/serverless/create_deploy_tag/collect_commit_info.ts
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,96 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { COMMIT_INFO_CTX, exec } from './shared'; | ||
import { | ||
toGitCommitExtract, | ||
getCurrentQARelease, | ||
getSelectedCommitHash, | ||
getCommitByHash, | ||
makeCommitInfoHtml, | ||
} from './info_sections/commit_info'; | ||
import { | ||
getArtifactBuild, | ||
getOnMergePRBuild, | ||
getQAFBuildContainingCommit, | ||
makeBuildkiteBuildInfoHtml, | ||
} from './info_sections/build_info'; | ||
import { | ||
compareSOSnapshots, | ||
makeSOComparisonBlockHtml, | ||
makeSOComparisonErrorHtml, | ||
} from './info_sections/so_snapshot_comparison'; | ||
import { makeUsefulLinksHtml } from './info_sections/useful_links'; | ||
|
||
async function main() { | ||
const previousSha = await getCurrentQARelease(); | ||
const selectedSha = getSelectedCommitHash(); | ||
|
||
// Current commit info | ||
const previousCommit = await getCommitByHash(previousSha); | ||
const previousCommitInfo = toGitCommitExtract(previousCommit); | ||
addBuildkiteInfoSection(makeCommitInfoHtml('Current commit on QA:', previousCommitInfo)); | ||
|
||
// Target commit info | ||
const selectedCommit = await getCommitByHash(selectedSha); | ||
const selectedCommitInfo = toGitCommitExtract(selectedCommit); | ||
addBuildkiteInfoSection(makeCommitInfoHtml('Target commit to deploy:', selectedCommitInfo)); | ||
|
||
// Buildkite build info | ||
const buildkiteBuild = await getOnMergePRBuild(selectedSha); | ||
const nextBuildContainingCommit = await getQAFBuildContainingCommit( | ||
selectedSha, | ||
selectedCommitInfo.date! | ||
); | ||
const artifactBuild = await getArtifactBuild(selectedSha); | ||
addBuildkiteInfoSection( | ||
makeBuildkiteBuildInfoHtml('Relevant build info:', { | ||
'Merge build': buildkiteBuild, | ||
'Artifact container build': artifactBuild, | ||
'Next QAF test build containing this commit': nextBuildContainingCommit, | ||
}) | ||
); | ||
|
||
// Save Object migration comparison | ||
const comparisonResult = compareSOSnapshots(previousSha, selectedSha); | ||
if (comparisonResult) { | ||
addBuildkiteInfoSection(makeSOComparisonBlockHtml(comparisonResult)); | ||
} else { | ||
addBuildkiteInfoSection(makeSOComparisonErrorHtml()); | ||
} | ||
|
||
// Useful links | ||
addBuildkiteInfoSection( | ||
makeUsefulLinksHtml('Useful links:', { | ||
previousCommitHash: previousSha, | ||
selectedCommitHash: selectedSha, | ||
}) | ||
); | ||
} | ||
|
||
function addBuildkiteInfoSection(html: string) { | ||
exec(`buildkite-agent annotate --append --style 'info' --context '${COMMIT_INFO_CTX}'`, { | ||
input: html + '<br />', | ||
}); | ||
} | ||
|
||
main() | ||
.then(() => { | ||
console.log('Commit-related information added.'); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}) | ||
.finally(() => { | ||
// When running locally, we can see what calls were made to execSync to debug | ||
if (!process.env.CI) { | ||
// @ts-ignore | ||
console.log(exec.calls); | ||
} | ||
}); |
Oops, something went wrong.