-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
config.ts
278 lines (243 loc) · 6.93 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import Path from 'path';
import os from 'os';
import { REPO_ROOT, kibanaPackageJson, KibanaPackageJson } from '@kbn/repo-info';
import {
Package,
getPackages,
PluginSelector,
PluginPackage,
getPluginPackagesFilter,
} from '@kbn/repo-packages';
import { getVersionInfo, VersionInfo } from './version_info';
import {
PlatformName,
PlatformArchitecture,
ALL_PLATFORMS,
SERVERLESS_PLATFORMS,
} from './platform';
interface Options {
isRelease: boolean;
targetAllPlatforms: boolean;
targetServerlessPlatforms: boolean;
versionQualifier?: string;
dockerContextUseLocalArtifact: boolean | null;
dockerCrossCompile: boolean;
dockerNamespace: string | null;
dockerTag: string | null;
dockerTagQualifier: string | null;
dockerPush: boolean;
withExamplePlugins: boolean;
withTestPlugins: boolean;
downloadFreshNode: boolean;
}
export class Config {
static async create(opts: Options) {
const nodeVersion = kibanaPackageJson.engines?.node;
if (!nodeVersion) {
throw new Error('missing node version in package.json');
}
return new Config(
opts.targetAllPlatforms,
opts.targetServerlessPlatforms,
kibanaPackageJson,
nodeVersion,
REPO_ROOT,
await getVersionInfo({
isRelease: opts.isRelease,
versionQualifier: opts.versionQualifier,
pkg: kibanaPackageJson,
}),
opts.dockerContextUseLocalArtifact,
opts.dockerCrossCompile,
opts.dockerNamespace,
opts.dockerTag,
opts.dockerTagQualifier,
opts.dockerPush,
opts.isRelease,
opts.downloadFreshNode,
{
examples: opts.withExamplePlugins,
testPlugins: opts.withTestPlugins,
}
);
}
private readonly pluginFilter: (pkg: Package) => pkg is PluginPackage;
constructor(
private readonly targetAllPlatforms: boolean,
private readonly targetServerlessPlatforms: boolean,
private readonly pkg: KibanaPackageJson,
private readonly nodeVersion: string,
private readonly repoRoot: string,
private readonly versionInfo: VersionInfo,
private readonly dockerContextUseLocalArtifact: boolean | null,
private readonly dockerCrossCompile: boolean,
private readonly dockerNamespace: string | null,
private readonly dockerTag: string | null,
private readonly dockerTagQualifier: string | null,
private readonly dockerPush: boolean,
public readonly isRelease: boolean,
public readonly downloadFreshNode: boolean,
public readonly pluginSelector: PluginSelector
) {
this.pluginFilter = getPluginPackagesFilter(this.pluginSelector);
}
/**
* Get Kibana's parsed package.json file
*/
getKibanaPkg() {
return this.pkg;
}
/**
* Get the node version required by Kibana
*/
getNodeVersion() {
return this.nodeVersion;
}
/**
* Get the docker tag qualifier
*/
getDockerTag() {
return this.dockerTag;
}
/**
* Get the docker tag qualifier
*/
getDockerTagQualfiier() {
return this.dockerTagQualifier;
}
/**
* Get docker push
*/
getDockerPush() {
return this.dockerPush;
}
/**
* Get docker repository namespace
*/
getDockerNamespace() {
return this.dockerNamespace;
}
/**
* Use a local Kibana distribution when producing a docker context
*/
getDockerContextUseLocalArtifact() {
return this.dockerContextUseLocalArtifact;
}
/**
* Get docker cross compile
*/
getDockerCrossCompile() {
return this.dockerCrossCompile;
}
/**
* Convert an absolute path to a relative path, based from the repo
*/
getRepoRelativePath(absolutePath: string) {
return Path.relative(this.repoRoot, absolutePath);
}
/**
* Resolve a set of relative paths based from the directory of the Kibana repo
*/
resolveFromRepo(...subPaths: string[]) {
return Path.resolve(this.repoRoot, ...subPaths);
}
/**
* Return the list of Platforms we are targeting, if --this-platform flag is
* specified only the platform for this OS will be returned
*/
getTargetPlatforms() {
if (this.targetServerlessPlatforms) {
return SERVERLESS_PLATFORMS;
}
if (this.targetAllPlatforms) {
return ALL_PLATFORMS;
}
return [this.getPlatformForThisOs()];
}
/**
* Return the list of Platforms we need/have node downloads for. We always
* include the linux platform even if we aren't targeting linux so we can
* reliably get the LICENSE file, which isn't included in the windows version
*/
getNodePlatforms() {
if (this.targetServerlessPlatforms) {
return SERVERLESS_PLATFORMS;
}
if (this.targetAllPlatforms) {
return ALL_PLATFORMS;
}
if (process.platform === 'linux' && process.arch === 'x64') {
return [this.getPlatform('linux', 'x64')];
}
return [this.getPlatformForThisOs(), this.getPlatform('linux', 'x64')];
}
getPlatform(name: PlatformName, arch: PlatformArchitecture) {
const selected = ALL_PLATFORMS.find((p) => {
return name === p.getName() && arch === p.getArchitecture();
});
if (!selected) {
throw new Error(`Unable to find platform (${name}) with architecture (${arch})`);
}
return selected;
}
/**
* Get the platform object representing the OS on this machine
*/
getPlatformForThisOs() {
return this.getPlatform(os.platform() as PlatformName, os.arch() as PlatformArchitecture);
}
/**
* Get the version to use for this build
*/
getBuildVersion() {
return this.versionInfo.buildVersion;
}
/**
* Get the build number of this build
*/
getBuildNumber() {
return this.versionInfo.buildNumber;
}
/**
* Get the git sha for this build
*/
getBuildSha() {
return this.versionInfo.buildSha;
}
/**
* Get the first 12 digits of the git sha for this build
*/
getBuildShaShort() {
return this.versionInfo.buildShaShort;
}
/**
* Get the ISO 8601 date for this build
*/
getBuildDate() {
return this.versionInfo.buildDate;
}
/**
* Resolve a set of paths based from the target directory for this build.
*/
resolveFromTarget(...subPaths: string[]) {
return Path.resolve(this.repoRoot, 'target', ...subPaths);
}
getDistPackagesFromRepo() {
return getPackages(this.repoRoot).filter(
(p) =>
(this.pluginSelector.testPlugins || !p.isDevOnly()) &&
(!p.isPlugin() || (this.pluginFilter(p) && !p.isDevOnly()))
);
}
getDistPluginsFromRepo() {
return getPackages(this.repoRoot).filter((p) => !p.isDevOnly() && this.pluginFilter(p));
}
}