-
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.
chore(NA): support bazel and kbn packages in parallel on kbn pm and o…
…n distributable build scripts (#89961) * chore(NA): bazel projects support initial flag on kbn pm * chore(NA): every needed step to build production bazel packages except the final function * chore(NA): include build bazel production projects on kibana distributable build * chore(NA): support bazel packages when creating the package.json * chore(NA): including last changes on kbn pm and build distributable to support both bazel and kbn packages * chore(NA): missing annotation on build bazel packages * chore(NA): changed values on bazelrc common * chore(NA): fix bazel common rc * chore(NA): auto discovery if a kbn package is a Bazel package * chore(NA): last details to make bazel packages to built on distributable scripts * chore(NA): removed wrongly added line to x-pack package.json * chore(NA): apply correct formating * chore(NA): move into bazel bin * chore(NA): merge chnages on kbn pm * chore(NA): correctly setup ignore files for new bazel aggregated folder * chore(NA): merge with last master Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
0938252
commit 23d5ffb
Showing
13 changed files
with
1,413 additions
and
150 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports_files( | ||
[ | ||
"tsconfig.json", | ||
"package.json" | ||
], | ||
visibility = ["//visibility:public"] | ||
) |
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,5 @@ | ||
# Call each package final target | ||
filegroup( | ||
name = "build", | ||
srcs = [], | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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
103 changes: 103 additions & 0 deletions
103
packages/kbn-pm/src/production/build_bazel_production_projects.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,103 @@ | ||
/* | ||
* 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 copy from 'cpy'; | ||
import globby from 'globby'; | ||
import { basename, join, relative, resolve } from 'path'; | ||
|
||
import { buildProject, getProductionProjects } from './build_non_bazel_production_projects'; | ||
import { chmod, isFile, isDirectory } from '../utils/fs'; | ||
import { log } from '../utils/log'; | ||
import { | ||
createProductionPackageJson, | ||
readPackageJson, | ||
writePackageJson, | ||
} from '../utils/package_json'; | ||
import { getBazelProjectsOnly } from '../utils/projects'; | ||
import { Project } from '..'; | ||
|
||
export async function buildBazelProductionProjects({ | ||
kibanaRoot, | ||
buildRoot, | ||
onlyOSS, | ||
}: { | ||
kibanaRoot: string; | ||
buildRoot: string; | ||
onlyOSS?: boolean; | ||
}) { | ||
const projects = await getBazelProjectsOnly(await getProductionProjects(kibanaRoot, onlyOSS)); | ||
|
||
const projectNames = [...projects.values()].map((project) => project.name); | ||
log.info(`Preparing Bazel projects production build for [${projectNames.join(', ')}]`); | ||
|
||
for (const project of projects.values()) { | ||
await buildProject(project); | ||
await copyToBuild(project, kibanaRoot, buildRoot); | ||
await applyCorrectPermissions(project, kibanaRoot, buildRoot); | ||
} | ||
} | ||
|
||
/** | ||
* Copy all the project's files from its Bazel dist directory into the | ||
* project build folder. | ||
* | ||
* When copying all the files into the build, we exclude `node_modules` because | ||
* we want the Kibana build to be responsible for actually installing all | ||
* dependencies. The primary reason for allowing the Kibana build process to | ||
* manage dependencies is that it will "dedupe" them, so we don't include | ||
* unnecessary copies of dependencies. We also exclude every related Bazel build | ||
* files in order to get the most cleaner package module we can in the final distributable. | ||
*/ | ||
async function copyToBuild(project: Project, kibanaRoot: string, buildRoot: string) { | ||
// We want the package to have the same relative location within the build | ||
const relativeProjectPath = relative(kibanaRoot, project.path); | ||
const buildProjectPath = resolve(buildRoot, relativeProjectPath); | ||
|
||
const bazelFilesToExclude = ['!*.params', '!*_mappings.json', '!*_options.optionsvalid.d.ts']; | ||
await copy(['**/*', '!node_modules/**', ...bazelFilesToExclude], buildProjectPath, { | ||
cwd: join(kibanaRoot, 'bazel', 'bin', 'packages', basename(buildProjectPath)), | ||
dot: true, | ||
onlyFiles: true, | ||
parents: true, | ||
} as copy.Options); | ||
|
||
// If a project is using an intermediate build directory, we special-case our | ||
// handling of `package.json`, as the project build process might have copied | ||
// (a potentially modified) `package.json` into the intermediate build | ||
// directory already. If so, we want to use that `package.json` as the basis | ||
// for creating the production-ready `package.json`. If it's not present in | ||
// the intermediate build, we fall back to using the project's already defined | ||
// `package.json`. | ||
const packageJson = (await isFile(join(buildProjectPath, 'package.json'))) | ||
? await readPackageJson(buildProjectPath) | ||
: project.json; | ||
|
||
const preparedPackageJson = createProductionPackageJson(packageJson); | ||
await writePackageJson(buildProjectPath, preparedPackageJson); | ||
} | ||
|
||
async function applyCorrectPermissions(project: Project, kibanaRoot: string, buildRoot: string) { | ||
const relativeProjectPath = relative(kibanaRoot, project.path); | ||
const buildProjectPath = resolve(buildRoot, relativeProjectPath); | ||
const allPluginPaths = await globby([`**/*`], { | ||
onlyFiles: false, | ||
cwd: join(kibanaRoot, 'bazel', 'bin', 'packages', basename(buildProjectPath)), | ||
dot: true, | ||
}); | ||
|
||
for (const pluginPath of allPluginPaths) { | ||
const resolvedPluginPath = resolve(buildRoot, pluginPath); | ||
if (await isFile(resolvedPluginPath)) { | ||
await chmod(resolvedPluginPath, 0o644); | ||
} | ||
|
||
if (await isDirectory(resolvedPluginPath)) { | ||
await chmod(resolvedPluginPath, 0o755); | ||
} | ||
} | ||
} |
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.