Skip to content

Commit b179a39

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 58afc1e commit b179a39

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
@@ -87,6 +87,7 @@ export function makeFtrConfigProvider(
8787
args: dockerArgs,
8888
waitForLogLine: 'package manifests loaded',
8989
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
90+
preferCached: true,
9091
},
9192
}),
9293

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
@@ -105,8 +105,12 @@ export class DockerServersService {
105105
const { image, name, waitFor, waitForLogLine, waitForLogLineTimeoutMs } = server;
106106

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

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

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

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
@@ -101,7 +101,8 @@ export function createServerlessFeatureFlagTestConfig<T extends DeploymentAgnost
101101
port: dockerRegistryPort,
102102
args: dockerArgs,
103103
waitForLogLine: 'package manifests loaded',
104-
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
104+
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
105+
preferCached: true,
105106
},
106107
}),
107108
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
@@ -97,7 +97,8 @@ export function createStatefulFeatureFlagTestConfig<T extends DeploymentAgnostic
9797
port: dockerRegistryPort,
9898
args: dockerArgs,
9999
waitForLogLine: 'package manifests loaded',
100-
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes
100+
waitForLogLineTimeoutMs: 60 * 6 * 1000, // 6 minutes,
101+
preferCached: true,
101102
},
102103
}),
103104
testFiles: options.testFiles,

0 commit comments

Comments
 (0)