-
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.
Merge branch 'main' into split-types-from-code-on-kbn-test
- Loading branch information
Showing
14 changed files
with
422 additions
and
231 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
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/fleet/server/integration_tests/docker_registry_helper.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,69 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { spawn } from 'child_process'; | ||
import type { ChildProcess } from 'child_process'; | ||
|
||
import fetch from 'node-fetch'; | ||
|
||
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
export function useDockerRegistry() { | ||
const packageRegistryPort = process.env.FLEET_PACKAGE_REGISTRY_PORT || '8081'; | ||
|
||
if (!packageRegistryPort.match(/^[0-9]{4}/)) { | ||
throw new Error('Invalid FLEET_PACKAGE_REGISTRY_PORT'); | ||
} | ||
|
||
let dockerProcess: ChildProcess | undefined; | ||
async function startDockerRegistryServer() { | ||
const dockerImage = `docker.elastic.co/package-registry/distribution@sha256:de952debe048d903fc73e8a4472bb48bb95028d440cba852f21b863d47020c61`; | ||
|
||
const args = ['run', '--rm', '-p', `${packageRegistryPort}:8080`, dockerImage]; | ||
|
||
dockerProcess = spawn('docker', args, { stdio: 'inherit' }); | ||
|
||
let isExited = dockerProcess.exitCode !== null; | ||
dockerProcess.once('exit', () => { | ||
isExited = true; | ||
}); | ||
|
||
let retries = 0; | ||
while (!isExited && retries++ <= 20) { | ||
try { | ||
const res = await fetch(`http://localhost:${packageRegistryPort}/`); | ||
if (res.status === 200) { | ||
return; | ||
} | ||
} catch (err) { | ||
// swallow errors | ||
} | ||
|
||
await delay(3000); | ||
} | ||
|
||
dockerProcess.kill(); | ||
throw new Error('Unable to setup docker registry'); | ||
} | ||
|
||
async function cleanupDockerRegistryServer() { | ||
if (dockerProcess && !dockerProcess.killed) { | ||
dockerProcess.kill(); | ||
} | ||
} | ||
|
||
beforeAll(async () => { | ||
jest.setTimeout(5 * 60 * 1000); // 5 minutes timeout | ||
await startDockerRegistryServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await cleanupDockerRegistryServer(); | ||
}); | ||
|
||
return `http://localhost:${packageRegistryPort}`; | ||
} |
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
Oops, something went wrong.