[8.x] [CI] Allow using elastic-images-qa through PR label or env var (#216878) (#217141)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[CI] Allow using `elastic-images-qa` through PR label or env var
(#216878)](https://github.com/elastic/kibana/pull/216878)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Alex
Szabo","email":"alex.szabo@elastic.co"},"sourceCommit":{"committedDate":"2025-04-04T08:05:30Z","message":"[CI]
Allow using `elastic-images-qa` through PR label or env var
(#216878)\n\n## Summary\nCurrently, if you'd like to test something on
Kibana's VM image, you'd\nhave to build a VM image to -qa, then rewrite
all references to\n`elastic-images-qa` for the PR jobs; once done with
testing, we'd undo\nthe changes to `elastic-images-prod`.\n\nThis is a
helpful tool for us to test with WIP VM images, we'd be able\nto add a
label to the PR, and it would automatically grab the QA images,\nwithout
any temporary commits.\n\nJobs in
https://buildkite.com/elastic/kibana-pull-request/builds/289599\nhave
ran with an elastic-qa image.
","sha":"9f8503e0b34f1c3f79232f04869f0a3ca6ebd2a1","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","backport:prev-minor","backport:prev-major","ci:use-qa-image","v9.1.0"],"title":"[CI]
Allow using `elastic-images-qa` through PR label or env
var","number":216878,"url":"https://github.com/elastic/kibana/pull/216878","mergeCommit":{"message":"[CI]
Allow using `elastic-images-qa` through PR label or env var
(#216878)\n\n## Summary\nCurrently, if you'd like to test something on
Kibana's VM image, you'd\nhave to build a VM image to -qa, then rewrite
all references to\n`elastic-images-qa` for the PR jobs; once done with
testing, we'd undo\nthe changes to `elastic-images-prod`.\n\nThis is a
helpful tool for us to test with WIP VM images, we'd be able\nto add a
label to the PR, and it would automatically grab the QA images,\nwithout
any temporary commits.\n\nJobs in
https://buildkite.com/elastic/kibana-pull-request/builds/289599\nhave
ran with an elastic-qa image.
","sha":"9f8503e0b34f1c3f79232f04869f0a3ca6ebd2a1"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216878","number":216878,"mergeCommit":{"message":"[CI]
Allow using `elastic-images-qa` through PR label or env var
(#216878)\n\n## Summary\nCurrently, if you'd like to test something on
Kibana's VM image, you'd\nhave to build a VM image to -qa, then rewrite
all references to\n`elastic-images-qa` for the PR jobs; once done with
testing, we'd undo\nthe changes to `elastic-images-prod`.\n\nThis is a
helpful tool for us to test with WIP VM images, we'd be able\nto add a
label to the PR, and it would automatically grab the QA images,\nwithout
any temporary commits.\n\nJobs in
https://buildkite.com/elastic/kibana-pull-request/builds/289599\nhave
ran with an elastic-qa image.
","sha":"9f8503e0b34f1c3f79232f04869f0a3ca6ebd2a1"}}]}] BACKPORT-->

Co-authored-by: Alex Szabo <alex.szabo@elastic.co>
This commit is contained in:
Kibana Machine 2025-04-04 12:20:54 +02:00 committed by GitHub
parent 289ca83711
commit 1dee2ee963
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 21 deletions

View file

@ -9,31 +9,34 @@
// eslint-disable-next-line @kbn/eslint/no_unsafe_js_yaml
import { dump } from 'js-yaml';
import { BuildkiteClient, BuildkiteCommandStep } from './buildkite';
import { BuildkiteClient, BuildkiteAgentTargetingRule } from './buildkite';
type AgentImageConfig = BuildkiteCommandStep['agents'];
const ELASTIC_IMAGES_QA_PROJECT = 'elastic-images-qa';
const ELASTIC_IMAGES_PROD_PROJECT = 'elastic-images-prod';
const DEFAULT_AGENT_IMAGE_CONFIG: AgentImageConfig = {
// constrain AgentImageConfig to the type that doesn't have the `queue` property
const DEFAULT_AGENT_IMAGE_CONFIG: BuildkiteAgentTargetingRule = {
provider: 'gcp',
image: 'family/kibana-ubuntu-2004',
imageProject: 'elastic-images-prod',
imageProject: ELASTIC_IMAGES_PROD_PROJECT,
};
const FIPS_AGENT_IMAGE_CONFIG: AgentImageConfig = {
const FIPS_AGENT_IMAGE_CONFIG: BuildkiteAgentTargetingRule = {
provider: 'gcp',
image: 'family/kibana-fips-ubuntu-2004',
imageProject: 'elastic-images-prod',
imageProject: ELASTIC_IMAGES_PROD_PROJECT,
};
const GITHUB_PR_LABELS = process.env.GITHUB_PR_LABELS ?? '';
const FTR_ENABLE_FIPS_AGENT = process.env.FTR_ENABLE_FIPS_AGENT?.toLowerCase() === 'true';
const USE_QA_IMAGE_FOR_PR = process.env.USE_QA_IMAGE_FOR_PR?.match(/(1|true)/i);
// Narrow the return type with overloads
function getAgentImageConfig(): AgentImageConfig;
function getAgentImageConfig(): BuildkiteAgentTargetingRule;
function getAgentImageConfig(options: { returnYaml: true }): string;
function getAgentImageConfig({ returnYaml = false } = {}): string | AgentImageConfig {
function getAgentImageConfig({ returnYaml = false } = {}): string | BuildkiteAgentTargetingRule {
const bk = new BuildkiteClient();
let config: AgentImageConfig;
let config: BuildkiteAgentTargetingRule;
if (FTR_ENABLE_FIPS_AGENT || GITHUB_PR_LABELS.includes('ci:enable-fips-agent')) {
config = FIPS_AGENT_IMAGE_CONFIG;
@ -47,6 +50,10 @@ function getAgentImageConfig({ returnYaml = false } = {}): string | AgentImageCo
config = DEFAULT_AGENT_IMAGE_CONFIG;
}
if (USE_QA_IMAGE_FOR_PR || GITHUB_PR_LABELS.includes('ci:use-qa-image')) {
config.imageProject = ELASTIC_IMAGES_QA_PROJECT;
}
if (returnYaml) {
return dump({ agents: config });
}

View file

@ -39,6 +39,19 @@ export type BuildkiteStep =
| BuildkiteTriggerStep
| BuildkiteWaitStep;
export interface BuildkiteAgentQueue {
queue: string;
}
export interface BuildkiteAgentTargetingRule {
provider?: string;
image?: string;
imageProject?: string;
machineType?: string;
minCpuPlatform?: string;
preemptible?: boolean;
}
export interface BuildkiteCommandStep {
command: string;
label: string;
@ -46,18 +59,7 @@ export interface BuildkiteCommandStep {
concurrency?: number;
concurrency_group?: string;
concurrency_method?: 'eager' | 'ordered';
agents:
| {
queue: string;
}
| {
provider?: string;
image?: string;
imageProject?: string;
machineType?: string;
minCpuPlatform?: string;
preemptible?: boolean;
};
agents: BuildkiteAgentQueue | BuildkiteAgentTargetingRule;
timeout_in_minutes?: number;
key?: string;
cancel_on_build_failing?: boolean;