Skip to content

Commit 569bd4b

Browse files
committed
[CI] Add preferCached for docker-startup commands (elastic#244766)
## Summary Add `preferCached` as an option in the test util for starting docker images, turn it on for all EPR image pulls, in order to prevent costly docker pulls in FTRs/integration tests. After elastic#244517 we still have a small temporal zone in between an agent being provisioned and the tests being ran, where a promotion would trigger a docker pull, that depletes disk space, it also would make pulls slow, and potentially time out tests. This PR suggests, we should always use the cached variant (for EPR at least). With this, the above risk zone is no longer causing pulls, it's just that we are still testing the previously promoted and cached image, probably not risky. (cherry picked from commit 5336f0d)
1 parent a061701 commit 569bd4b

17 files changed

Lines changed: 39 additions & 11 deletions

File tree

src/platform/packages/private/kbn-journeys/journey/journey_ftr_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export function makeFtrConfigProvider(
107107
args: dockerArgs,
108108
waitForLogLine: 'package manifests loaded',
109109
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
110+
preferCached: true,
110111
},
111112
}),
112113

src/platform/packages/shared/kbn-scout/src/config/schema/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const dockerServerSchema = () =>
5353
image: requiredWhenEnabled(Joi.string()),
5454
port: requiredWhenEnabled(Joi.number()),
5555
portInContainer: requiredWhenEnabled(Joi.number()),
56+
preferCached: Joi.boolean().optional(),
5657
waitForLogLine: Joi.alternatives(Joi.object().instance(RegExp), Joi.string()).optional(),
5758
waitForLogLineTimeoutMs: Joi.number().integer().optional(),
5859
waitFor: Joi.func().optional(),

src/platform/packages/shared/kbn-scout/src/config/serverless/serverless.base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const defaultConfig: ScoutServerConfig = {
6363
args: dockerArgs,
6464
waitForLogLine: 'package manifests loaded',
6565
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
66+
preferCached: true,
6667
},
6768
}),
6869
esTestCluster: {

src/platform/packages/shared/kbn-scout/src/config/stateful/base.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export const defaultConfig: ScoutServerConfig = {
6767
port: dockerRegistryPort,
6868
args: dockerArgs,
6969
waitForLogLine: 'package manifests loaded',
70-
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
70+
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
71+
preferCached: true,
7172
},
7273
}),
7374
esTestCluster: {

src/platform/packages/shared/kbn-test/src/functional_test_runner/lib/config/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const dockerServerSchema = () =>
7171
image: requiredWhenEnabled(Joi.string()),
7272
port: requiredWhenEnabled(Joi.number()),
7373
portInContainer: requiredWhenEnabled(Joi.number()),
74+
preferCached: Joi.boolean().optional(),
7475
waitForLogLine: Joi.alternatives(Joi.object().instance(RegExp), Joi.string()).optional(),
7576
waitForLogLineTimeoutMs: Joi.number().integer().optional(),
7677
waitFor: Joi.func().optional(),

src/platform/packages/shared/kbn-test/src/functional_test_runner/lib/docker_servers/define_docker_servers_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface DockerServerSpec {
1414
portInContainer: number;
1515
port: number;
1616
image: string;
17+
preferCached?: boolean;
1718
waitForLogLine?: RegExp | string;
1819
waitForLogLineTimeoutMs?: number;
1920
/** a function that should return an observable that will allow the tests to execute as soon as it emits anything */

src/platform/packages/shared/kbn-test/src/functional_test_runner/lib/docker_servers/docker_servers_service.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ export class DockerServersService {
106106
const { image, name, waitFor, waitForLogLine, waitForLogLineTimeoutMs } = server;
107107

108108
// pull image from registry
109-
log.info(`[docker:${name}] pulling docker image "${image}"`);
110-
await execa('docker', ['pull', image]);
109+
if (server.preferCached && (await this.isImageAvailableLocally(image))) {
110+
log.info(`[docker:${name}] skipping pull of docker image "${image}"`);
111+
} else {
112+
log.info(`[docker:${name}] pulling docker image "${image}"`);
113+
await execa('docker', ['pull', image]);
114+
}
111115

112116
// run the image that we just pulled
113117
const containerId = await this.dockerRun(server);
@@ -208,6 +212,15 @@ export class DockerServersService {
208212
).toPromise();
209213
}
210214

215+
private async isImageAvailableLocally(imageUrl: string) {
216+
try {
217+
const { stdout } = await execa('docker', ['images', '-q', imageUrl]);
218+
return stdout.trim().length > 0;
219+
} catch {
220+
return false;
221+
}
222+
}
223+
211224
private async startServers() {
212225
if (this.disabled) {
213226
return;

x-pack/platform/plugins/shared/fleet/server/integration_tests/helpers/docker_registry_helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import pRetry from 'p-retry';
1818
const BEFORE_SETUP_TIMEOUT = 30 * 60 * 1000; // 30 minutes;
1919

2020
const DOCKER_START_TIMEOUT = 6 * 60 * 1000; // 6 minutes
21-
// This image comes from the latest successful build of https://buildkite.com/elastic/kibana-package-registry-promote
21+
// This image comes from the latest successful build of https://buildkite.com/elastic/kibana-package-registry-verify-and-promote
2222
// which is promoted after acceptance tests succeed against docker.elastic.co/package-registry/distribution:lite
2323
const DOCKER_IMAGE =
2424
process.env.FLEET_PACKAGE_REGISTRY_DOCKER_IMAGE ||

x-pack/platform/test/api_integration_deployment_agnostic/default_configs/feature_flag.serverless.config.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function createServerlessFeatureFlagTestConfig<T extends DeploymentAgnost
9494
port: dockerRegistryPort,
9595
args: dockerArgs,
9696
waitForLogLine: 'package manifests loaded',
97-
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
97+
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
98+
preferCached: true,
9899
},
99100
}),
100101
esTestCluster: {

x-pack/platform/test/api_integration_deployment_agnostic/default_configs/feature_flag.stateful.config.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export function createStatefulFeatureFlagTestConfig<T extends DeploymentAgnostic
9898
port: dockerRegistryPort,
9999
args: dockerArgs,
100100
waitForLogLine: 'package manifests loaded',
101-
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
101+
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
102+
preferCached: true,
102103
},
103104
}),
104105
testFiles: options.testFiles,

0 commit comments

Comments
 (0)