-
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 use-locators-2
- Loading branch information
Showing
58 changed files
with
3,008 additions
and
542 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,5 @@ elastic-agent-* | |
fleet-server-* | ||
elastic-agent.yml | ||
fleet-server.yml | ||
|
||
/x-pack/plugins/fleet/server/bundled_packages |
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,36 @@ | ||
/* | ||
|
||
Packages in this file are considered "bundled" and are installed as part of Fleet's setup process. Each entry points to a valid version name | ||
avaiable in the Elastic Package Registry service, and must include a sha-512 checksum of the `.zip` archive for the given package. | ||
|
||
You may opt in to using the "snapshot" environment of the EPR service by passing the `--use-epr-snapshot-registry` flag to `yarn build`. This will | ||
cause the package archive download to pull from the "spapshot" environment instead of the "production" environment. Be aware that not all packages | ||
exist in the snapshot environment, so you may have errors when fetching package versions. It's recommended to alter this file to contain _only_ the | ||
packages you're testing when using the snapshot environment. | ||
|
||
These files don't include any kind of checksum, but they should eventually include a package signature as introduced in https://github.com/elastic/elastic-package/issues/583 | ||
in order to verify package integrity. | ||
*/ | ||
|
||
[ | ||
{ | ||
"name": "apm", | ||
"version": "8.0.0" | ||
}, | ||
{ | ||
"name": "elastic_agent", | ||
"version": "1.3.0" | ||
}, | ||
{ | ||
"name": "endpoint", | ||
"version": "1.4.1" | ||
}, | ||
{ | ||
"name": "fleet_server", | ||
"version": "1.1.0" | ||
}, | ||
{ | ||
"name": "synthetics", | ||
"version": "0.9.0" | ||
} | ||
] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import axios from 'axios'; | ||
import JSON5 from 'json5'; | ||
|
||
// @ts-expect-error untyped internal module used to prevent axios from using xhr adapter in tests | ||
import AxiosHttpAdapter from 'axios/lib/adapters/http'; | ||
|
||
import { ToolingLog } from '@kbn/dev-utils'; | ||
import { closeSync, openSync, writeSync } from 'fs'; | ||
import { dirname } from 'path'; | ||
import { readCliArgs } from '../args'; | ||
|
||
import { Task, read, mkdirp } from '../lib'; | ||
|
||
const BUNDLED_PACKAGES_DIR = 'x-pack/plugins/fleet/server/bundled_packages'; | ||
|
||
interface FleetPackage { | ||
name: string; | ||
version: string; | ||
} | ||
|
||
export const BundleFleetPackages: Task = { | ||
description: 'Bundling fleet packages', | ||
|
||
async run(config, log, build) { | ||
log.info('Fetching fleet packages from package registry'); | ||
log.indent(4); | ||
|
||
// Support the `--use-snapshot-epr` command line argument to fetch from the snapshot registry | ||
// in development or test environments | ||
const { buildOptions } = readCliArgs(process.argv); | ||
const eprUrl = buildOptions?.useSnapshotEpr | ||
? 'https://epr-snapshot.elastic.co' | ||
: 'https://epr.elastic.co'; | ||
|
||
const configFilePath = config.resolveFromRepo('fleet_packages.json'); | ||
const fleetPackages = (await read(configFilePath)) || '[]'; | ||
|
||
await Promise.all( | ||
JSON5.parse(fleetPackages).map(async (fleetPackage: FleetPackage) => { | ||
const archivePath = `${fleetPackage.name}-${fleetPackage.version}.zip`; | ||
const archiveUrl = `${eprUrl}/epr/${fleetPackage.name}/${fleetPackage.name}-${fleetPackage.version}.zip`; | ||
|
||
const destination = build.resolvePath(BUNDLED_PACKAGES_DIR, archivePath); | ||
|
||
try { | ||
await downloadPackageArchive({ log, url: archiveUrl, destination }); | ||
} catch (error) { | ||
log.warning(`Failed to download bundled package archive ${archivePath}`); | ||
log.warning(error); | ||
} | ||
}) | ||
); | ||
}, | ||
}; | ||
|
||
/** | ||
* We need to skip the checksum process on Fleet's bundled packages for now because we can't reliably generate | ||
* a consistent checksum for the `.zip` file returned from the EPR service. This download process should be updated | ||
* to verify packages using the proposed package signature field provided in https://github.com/elastic/elastic-package/issues/583 | ||
*/ | ||
async function downloadPackageArchive({ | ||
log, | ||
url, | ||
destination, | ||
}: { | ||
log: ToolingLog; | ||
url: string; | ||
destination: string; | ||
}) { | ||
log.info(`Downloading bundled package from ${url}`); | ||
|
||
await mkdirp(dirname(destination)); | ||
const file = openSync(destination, 'w'); | ||
|
||
try { | ||
const response = await axios.request({ | ||
url, | ||
responseType: 'stream', | ||
adapter: AxiosHttpAdapter, | ||
}); | ||
|
||
await new Promise((resolve, reject) => { | ||
response.data.on('data', (chunk: Buffer) => { | ||
writeSync(file, chunk); | ||
}); | ||
|
||
response.data.on('error', reject); | ||
response.data.on('end', resolve); | ||
}); | ||
} catch (error) { | ||
log.warning(`Error downloading bundled package from ${url}`); | ||
log.warning(error); | ||
} finally { | ||
closeSync(file); | ||
} | ||
} |
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
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
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.