-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added serverless publish OAS pipeline
- Loading branch information
1 parent
f921f70
commit e872694
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
.buildkite/pipeline-resource-definitions/kibana-publish-serverless-oas.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,65 @@ | ||
### | ||
# For more information on authoring pipeline definitions, | ||
# follow the guides at https://docs.elastic.dev/ci/getting-started-with-buildkite-at-elastic | ||
### | ||
# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/rre.schema.json | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Resource | ||
metadata: | ||
# This will be the URL slug in Backstage UI as: | ||
# https://backstage.elastic.dev/catalog/default/resource/bk-kibana-your-pipeline-name | ||
# bk-pipeline-<pipeline-name-slugified> | ||
name: bk-kibana-publish-serverless-oas | ||
# This will be displayed in the Backstage UI | ||
description: 'Push OAS docs for a serverless release to bump.sh' | ||
links: | ||
# These are relevant links to your pipeline that will be listed in the Backstage UI | ||
# The URL slug here is the .spec.implementation.metadata.name field slugified | ||
- url: 'https://buildkite.com/elastic/kibana-publish-serverless-oas' | ||
title: Pipeline link | ||
spec: | ||
type: buildkite-pipeline | ||
system: buildkite | ||
# The owner team's github group name in the format 'group:<github-group-name>' | ||
owner: 'group:kibana-core' | ||
implementation: | ||
apiVersion: buildkite.elastic.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
# <context / pipeline name> - this will be displayed in the Buildkite UI as title | ||
# and this will be slugified to form the URL in the Backstage UI | ||
name: kibana / publish-serverless-oas | ||
# This will appear as description on the Buildkite UI | ||
description: 'Push OAS docs for a serverless release to bump.sh' | ||
spec: | ||
# Environment variables that will be set for the pipeline | ||
env: | ||
# Slack channel to send notifications to, if ELASTIC_SLACK_NOTIFICATIONS_ENABLED = 'true' | ||
# SLACK_NOTIFICATIONS_CHANNEL: '#team-slack-channel-name' | ||
# ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'true' | ||
|
||
allow_rebuilds: false | ||
branch_configuration: main | ||
default_branch: main | ||
repository: elastic/kibana | ||
# Point to a pipeline implementation, detailing the pipeline steps to run | ||
pipeline_file: .buildkite/pipelines/your-pipeline-name.yml | ||
skip_intermediate_builds: false | ||
provider_settings: | ||
prefix_pull_request_fork_branch_names: false | ||
skip_pull_request_builds_for_existing_commits: true | ||
trigger_mode: none | ||
# Teams and their access levels to the pipeline, | ||
# please keep [kibana-operations, appex-qa, kibana-tech-leads] as MANAGE_BUILD_AND_READ | ||
# and [everyone] as BUILD_AND_READ | ||
teams: | ||
kibana-operations: | ||
access_level: MANAGE_BUILD_AND_READ | ||
appex-qa: | ||
access_level: MANAGE_BUILD_AND_READ | ||
kibana-tech-leads: | ||
access_level: MANAGE_BUILD_AND_READ | ||
everyone: | ||
access_level: BUILD_AND_READ | ||
tags: | ||
- kibana |
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,21 @@ | ||
## Publishes OAS docs to Bump for a given commit | ||
|
||
agents: | ||
image: family/kibana-ubuntu-2004 | ||
imageProject: elastic-images-prod | ||
provider: gcp | ||
machineType: n2-standard-2 | ||
|
||
steps: | ||
- label: "Select commit" | ||
commands: | ||
- ts-node .buildkite/scripts/serverless/publish_oas/select_commit.ts | ||
key: select_commit | ||
|
||
- wait: ~ | ||
|
||
- label: "Deploy commit to bump.sh" | ||
commands: | ||
- bash .buildkite/scripts/serverless/publish_oas/publish_oas_utils.sh | ||
key: deploy_to_bump | ||
depends_on: select_commit |
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 | ||
|
||
source .buildkite/scripts/serverless/publish_oas/publish_oas_utils.sh | ||
|
||
KIBANA_COMMIT_SHA=$(buildkite-agent meta-data get selected-commit-hash) | ||
|
||
if [[ ! -z KIBANA_COMMIT_SHA ]]; then | ||
echo "--- Deploying $KIBANA_COMMIT_SHA to bump.sh"; | ||
git checkout $KIBANA_COMMIT_SHA; | ||
BUMP_KIBANA_DOC_NAME="$(vault_get kibana-bump-sh kibana-serverless-doc-name)" | ||
BUMP_KIBANA_DOC_TOKEN="$(vault_get kibana-bump-sh kibana-serverless-token)" | ||
deploy_to_bump oas_docs/output/kibana.serverless.yaml $BUMP_KIBANA_DOC_NAME $BUMP_KIBANA_DOC_TOKEN main; | ||
else | ||
echo "No Kibana commit SHA provided, not deploying anything to bump.sh"; | ||
exit 1; | ||
fi |
29 changes: 29 additions & 0 deletions
29
.buildkite/scripts/serverless/publish_oas/publish_oas_utils.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,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Install the bump CLI for just this step | ||
npm install -g bump-cli@^2.8.2 | ||
|
||
deploy_to_bump() { | ||
local file_path="${1:-}" | ||
local doc_name="${2:-}" | ||
local doc_token="${3:-}" | ||
local branch="${4:-}" | ||
|
||
echo "Checking diff for doc '$doc_name' against file '$file_path'..." | ||
local result=$(bump diff $file_path --doc $doc_name --token $doc_token --branch $branch --format=json) | ||
## Bump.sh does not respond with JSON when the diff is empty so we need to handle possibly not JSON :'( | ||
local change_count=$(tr '\n' ' '<<<$result | jq -R 'fromjson? | length') | ||
if [[ ! -z $change_count && $change_count -gt 0 ]]; then | ||
echo "Found $change_count changes..." | ||
echo "About to deploy file '$file_path' to doc '$doc_name' on bump.sh..." | ||
bump deploy $file_path \ | ||
--branch $branch \ | ||
--doc $doc_name \ | ||
--token $doc_token ; | ||
echo "" | ||
echo "Note: if there is a warning of unchanged docs we probably have unpublished deployments waiting." | ||
echo "Go to https://bump.sh/elastic/dashboard to see all the docs in the hub." | ||
else | ||
echo "Did not detect changes for '$file_path'; not deploying. Got response: $result" | ||
fi | ||
} |
58 changes: 58 additions & 0 deletions
58
.buildkite/scripts/serverless/publish_oas/select_commit.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,58 @@ | ||
/* | ||
* 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 { getExec } from '../create_deploy_tag/mock_exec'; | ||
import { BuildkiteClient, BuildkiteInputStep, getGithubClient } from '#pipeline-utils'; | ||
|
||
const SELECTED_COMMIT_META_KEY = 'selected-commit'; | ||
|
||
const buildkite = new BuildkiteClient({ exec: getExec(!process.env.CI) }); | ||
const octokit = getGithubClient(); | ||
|
||
async function getCurrentProdReleaseSha() { | ||
const releasesFile = await octokit.request(`GET /repos/{owner}/{repo}/contents/{path}`, { | ||
owner: 'elastic', | ||
repo: 'serverless-gitops', | ||
path: 'services/kibana/versions.yaml', | ||
}); | ||
|
||
// @ts-ignore | ||
const fileContent = Buffer.from(releasesFile.data.content, 'base64').toString('utf8'); | ||
|
||
const sha = fileContent.match(`production-canary-ds-1: "([a-z0-9]+)"`)?.[1]; | ||
|
||
if (!sha) { | ||
throw new Error('Could not find QA hash in current releases file'); | ||
} else { | ||
return sha; | ||
} | ||
} | ||
|
||
async function main() { | ||
const sha = await getCurrentProdReleaseSha(); | ||
const inputStep: BuildkiteInputStep = { | ||
input: 'Select commit to deploy', | ||
prompt: 'Select commit to deploy.', | ||
key: 'select-commit', | ||
fields: [ | ||
{ | ||
text: 'Enter Kibana SHA for the docs to deploy (likely you want the default)', | ||
key: SELECTED_COMMIT_META_KEY, | ||
default: sha, | ||
}, | ||
], | ||
}; | ||
|
||
buildkite.uploadSteps([inputStep]); | ||
} | ||
|
||
main().catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |