Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PURIFY][BUILD] Remove isOss flag and defaults to oss build #245

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/dev/build/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dev/build

Build the default and OSS distributables of OpenSearch Dashboards.
Build the distributables of OpenSearch Dashboards.

# Quick Start

Expand All @@ -12,8 +12,8 @@ node scripts/build --help
# build a release version
node scripts/build --release

# reuse already downloaded node executables, turn on debug logging, and only build the default distributable
node scripts/build --skip-node-download --debug --no-oss
# reuse already downloaded node executables, turn on debug logging
node scripts/build --skip-node-download --debug
```

# Fixing out of memory issues
Expand All @@ -30,7 +30,7 @@ NODE_OPTIONS="--max-old-space-size=4096" node scripts/build --release

The majority of this logic is extracted from the grunt build that has existed forever, and is designed to maintain the general structure grunt provides including tasks and config. The [build_distributables.js] file defines which tasks are run.

**Task**: [tasks/\*] define individual parts of the build. Each task is an object with a `run()` method, a `description` property, and optionally a `global` property. They are executed with the runner either once (if they are global) or once for each build. Non-global/local tasks are called once for each build, meaning they will be called twice be default, once for the OSS build and once for the default build and receive a build object as the third argument to `run()` which can be used to determine paths and properties for that build.
**Task**: [tasks/\*] define individual parts of the build. Each task is an object with a `run()` method, a `description` property, and optionally a `global` property. They are executed with the runner either once (if they are global) or once for each build. Non-global/local tasks are called once for each build, meaning they will be called twice be default, once for the build and receive a build object as the third argument to `run()` which can be used to determine paths and properties for that build.

**Config**: [lib/config.js] defines the config used to execute tasks. It is mostly used to determine absolute paths to specific locations, and to get access to the Platforms.

Expand Down
12 changes: 0 additions & 12 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ it('build default and oss dist for current platform, without packages, by defaul
expect(readCliArgs(['node', 'scripts/build'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
Expand All @@ -60,8 +58,6 @@ it('builds packages if --all-platforms is passed', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": true,
"createDockerPackage": true,
Expand All @@ -83,8 +79,6 @@ it('limits packages if --rpm passed with --all-platforms', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--rpm'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
Expand All @@ -106,8 +100,6 @@ it('limits packages if --deb passed with --all-platforms', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--deb'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": true,
"createDockerPackage": false,
Expand All @@ -130,8 +122,6 @@ it('limits packages if --docker passed with --all-platforms', () => {
.toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": true,
Expand All @@ -154,8 +144,6 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
.toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": true,
Expand Down
5 changes: 0 additions & 5 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export function readCliArgs(argv: string[]) {
const unknownFlags: string[] = [];
const flags = getopts(argv, {
boolean: [
'oss',
'no-oss',
'skip-archives',
'skip-os-packages',
'rpm',
Expand All @@ -54,7 +52,6 @@ export function readCliArgs(argv: string[]) {
rpm: null,
deb: null,
docker: null,
oss: null,
'version-qualifier': '',
},
unknown: (flag) => {
Expand Down Expand Up @@ -100,8 +97,6 @@ export function readCliArgs(argv: string[]) {
const buildOptions: BuildOptions = {
isRelease: Boolean(flags.release),
versionQualifier: flags['version-qualifier'],
buildOssDist: flags.oss !== false,
buildDefaultDist: !flags.oss,
downloadFreshNode: !Boolean(flags['skip-node-download']),
createArchives: !Boolean(flags['skip-archives']),
createRpmPackage: isOsPackageDesired('rpm'),
Expand Down
4 changes: 0 additions & 4 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import * as Tasks from './tasks';

export interface BuildOptions {
isRelease: boolean;
buildOssDist: boolean;
buildDefaultDist: boolean;
downloadFreshNode: boolean;
createArchives: boolean;
createRpmPackage: boolean;
Expand All @@ -44,8 +42,6 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
const run = createRunner({
config,
log,
buildDefaultDist: options.buildDefaultDist,
buildOssDist: options.buildOssDist,
});

/**
Expand Down
2 changes: 0 additions & 2 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ if (showHelp) {
build the OpenSearch Dashboards distributable

options:
--oss {dim Only produce the OSS distributable of OpenSearch Dashboards}
--no-oss {dim Only produce the default distributable of OpenSearch Dashboards}
--skip-archives {dim Don't produce tar/zip archives}
--skip-os-packages {dim Don't produce rpm/deb/docker packages}
--all-platforms {dim Produce archives for all platforms, not just this one}
Expand Down
46 changes: 15 additions & 31 deletions src/dev/build/lib/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,68 +54,52 @@ beforeEach(() => {
jest.clearAllMocks();
});

const ossBuild = new Build(config, true);
const defaultBuild = new Build(config, false);

describe('#isOss()', () => {
it('returns true for oss', () => {
expect(ossBuild.isOss()).toBe(true);
});

it('returns false for default build', () => {
expect(defaultBuild.isOss()).toBe(false);
});
});
const build = new Build(config);

describe('#getName()', () => {
it('returns opensearch-dashboards for default build', () => {
expect(defaultBuild.getName()).toBe('opensearch-dashboards');
});

it('returns opensearch-dashboards-oss for oss', () => {
expect(ossBuild.getName()).toBe('opensearch-dashboards-oss');
it('returns opensearch-dashboards for build', () => {
expect(build.getName()).toBe('opensearch-dashboards');
});
});

describe('#getLogTag()', () => {
it('returns string with build name in it', () => {
expect(defaultBuild.getLogTag()).toContain(defaultBuild.getName());
expect(ossBuild.getLogTag()).toContain(ossBuild.getName());
expect(build.getLogTag()).toContain(build.getName());
});
});

describe('#resolvePath()', () => {
it('uses passed config to resolve a path relative to the repo', () => {
expect(ossBuild.resolvePath('bar')).toMatchInlineSnapshot(
`<absolute path>/build/opensearch-dashboards-oss/bar`
expect(build.resolvePath('bar')).toMatchInlineSnapshot(
`<absolute path>/build/opensearch-dashboards/bar`
);
});

it('passes all arguments to config.resolveFromRepo()', () => {
expect(defaultBuild.resolvePath('bar', 'baz', 'box')).toMatchInlineSnapshot(
expect(build.resolvePath('bar', 'baz', 'box')).toMatchInlineSnapshot(
`<absolute path>/build/opensearch-dashboards/bar/baz/box`
);
});
});

describe('#resolvePathForPlatform()', () => {
it('uses config.resolveFromRepo(), config.getBuildVersion(), and platform.getBuildName() to create path', () => {
expect(ossBuild.resolvePathForPlatform(linuxPlatform, 'foo', 'bar')).toMatchInlineSnapshot(
`<absolute path>/build/oss/opensearch-dashboards-8.0.0-linux-x86_64/foo/bar`
expect(build.resolvePathForPlatform(linuxPlatform, 'foo', 'bar')).toMatchInlineSnapshot(
`<absolute path>/build/opensearch-dashboards-8.0.0-linux-x86_64/foo/bar`
);
});
});

describe('#getPlatformArchivePath()', () => {
it('creates correct path for different platforms', () => {
expect(ossBuild.getPlatformArchivePath(linuxPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-oss-8.0.0-linux-x86_64.tar.gz`
expect(build.getPlatformArchivePath(linuxPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-linux-x86_64.tar.gz`
);
expect(ossBuild.getPlatformArchivePath(linuxArmPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-oss-8.0.0-linux-aarch64.tar.gz`
expect(build.getPlatformArchivePath(linuxArmPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-linux-aarch64.tar.gz`
);
expect(ossBuild.getPlatformArchivePath(windowsPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-oss-8.0.0-windows-x86_64.zip`
expect(build.getPlatformArchivePath(windowsPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-windows-x86_64.zip`
);
});
});
14 changes: 3 additions & 11 deletions src/dev/build/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ import { Config } from './config';
import { Platform } from './platform';

export class Build {
private name = this.oss ? 'opensearch-dashboards-oss' : 'opensearch-dashboards';
private logTag = this.oss
? chalk`{magenta [opensearch-dashboards-oss]}`
: chalk`{cyan [ opensearch-dashboards ]}`;
private name = 'opensearch-dashboards';

constructor(private config: Config, private oss: boolean) {}

isOss() {
return !!this.oss;
}
constructor(private config: Config) {}

resolvePath(...args: string[]) {
return this.config.resolveFromRepo('build', this.name, ...args);
Expand All @@ -41,7 +34,6 @@ export class Build {
resolvePathForPlatform(platform: Platform, ...args: string[]) {
return this.config.resolveFromRepo(
'build',
this.oss ? 'oss' : 'default',
`opensearch-dashboards-${this.config.getBuildVersion()}-${platform.getBuildName()}`,
...args
);
Expand All @@ -60,6 +52,6 @@ export class Build {
}

getLogTag() {
return this.logTag;
return chalk`{cyan [ opensearch-dashboards ]}`;
}
}
Loading