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

De-Couple Dashboards linux building process #795

Merged
merged 3 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"test:ftr:runner": "node scripts/functional_test_runner",
"test:coverage": "grunt test:coverage",
"checkLicenses": "node scripts/check_licenses --dev",
"build-platform": "node scripts/build",
ananzh marked this conversation as resolved.
Show resolved Hide resolved
"build": "node scripts/build --all-platforms",
"start": "node scripts/opensearch_dashboards --dev",
"debug": "node --nolazy --inspect scripts/opensearch_dashboards --dev",
Expand Down
90 changes: 90 additions & 0 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,83 @@ it('build dist for current platform, without packages, by default', () => {
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": false,
"versionQualifier": "",
},
"log": <ToolingLog>,
"showHelp": false,
"unknownFlags": Array [],
}
`);
});

it('build dist for linux x64 platform, without packages, if --linux-x64 is passed', () => {
expect(readCliArgs(['node', 'scripts/build-platform'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": false,
"versionQualifier": "",
},
"log": <ToolingLog>,
"showHelp": false,
"unknownFlags": Array [],
}
`);
});

it('build dist for linux x64 platform, without packages, if --linux-arm64 is passed', () => {
expect(readCliArgs(['node', 'scripts/build-platform'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": false,
"versionQualifier": "",
},
"log": <ToolingLog>,
"showHelp": false,
"unknownFlags": Array [],
}
`);
});

it('build dist for linux x64 platform, without packages, if --darwin-x64 is passed', () => {
expect(readCliArgs(['node', 'scripts/build-platform'])).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": false,
"versionQualifier": "",
},
Expand All @@ -71,8 +146,11 @@ it('builds packages if --all-platforms is passed', () => {
"createDockerPackage": true,
"createDockerUbiPackage": true,
"createRpmPackage": true,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
Expand All @@ -92,8 +170,11 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": true,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
Expand All @@ -113,8 +194,11 @@ it('limits packages if --deb passed with --all-platforms', () => {
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
Expand All @@ -135,8 +219,11 @@ it('limits packages if --docker passed with --all-platforms', () => {
"createDockerPackage": true,
"createDockerUbiPackage": true,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
Expand All @@ -157,8 +244,11 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"createDockerPackage": true,
"createDockerUbiPackage": false,
"createRpmPackage": false,
"darwinX64": false,
"downloadFreshNode": true,
"isRelease": false,
"linuxArm64": false,
"linuxX64": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
Expand Down
6 changes: 6 additions & 0 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export function readCliArgs(argv: string[]) {
'verbose',
'debug',
'all-platforms',
'linux-x64',
'linux-arm64',
'darwin-x64',
'verbose',
'quiet',
'silent',
Expand Down Expand Up @@ -111,6 +114,9 @@ export function readCliArgs(argv: string[]) {
createDebPackage: isOsPackageDesired('deb'),
createDockerPackage: isOsPackageDesired('docker'),
createDockerUbiPackage: isOsPackageDesired('docker') && !Boolean(flags['skip-docker-ubi']),
darwinX64: Boolean(flags['darwin-x64']),
ananzh marked this conversation as resolved.
Show resolved Hide resolved
linuxArm64: Boolean(flags['linux-arm64']),
linuxX64: Boolean(flags['linux-x64']),
targetAllPlatforms: Boolean(flags['all-platforms']),
};

Expand Down
3 changes: 3 additions & 0 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export interface BuildOptions {
createDockerUbiPackage: boolean;
versionQualifier: string | undefined;
targetAllPlatforms: boolean;
darwinX64: boolean;
linuxArm64: boolean;
linuxX64: boolean;
}

export async function buildDistributables(log: ToolingLog, options: BuildOptions) {
Expand Down
3 changes: 3 additions & 0 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if (showHelp) {
--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}
--linux-x64 {dim Produce archives for only linux x64 platform}
ananzh marked this conversation as resolved.
Show resolved Hide resolved
--linux-arm64 {dim Produce archives for only linux arm64 platform}
--darwin-x64 {dim Produce archives for only darwin x64 platform}
--rpm {dim Only build the rpm package}
--deb {dim Only build the deb package}
--docker {dim Only build the docker image}
Expand Down
15 changes: 9 additions & 6 deletions src/dev/build/lib/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ expect.addSnapshotSerializer(createAbsolutePathSerializer());

const config = new Config(
true,
false,
false,
false,
{
version: '8.0.0',
version: '1.0.0',
tmarkley marked this conversation as resolved.
Show resolved Hide resolved
engines: {
node: '*',
},
Expand All @@ -49,7 +52,7 @@ const config = new Config(
{
buildNumber: 1234,
buildSha: 'abcd1234',
buildVersion: '8.0.0',
buildVersion: '1.0.0',
},
true
);
Expand Down Expand Up @@ -93,21 +96,21 @@ describe('#resolvePath()', () => {
describe('#resolvePathForPlatform()', () => {
it('uses config.resolveFromRepo(), config.getBuildVersion(), and platform.getBuildName() to create path', () => {
expect(build.resolvePathForPlatform(linuxPlatform, 'foo', 'bar')).toMatchInlineSnapshot(
`<absolute path>/build/opensearch-dashboards-8.0.0-linux-x64/foo/bar`
`<absolute path>/build/opensearch-dashboards-1.0.0-linux-x64/foo/bar`
);
});
});

describe('#getPlatformArchivePath()', () => {
it('creates correct path for different platforms', () => {
expect(build.getPlatformArchivePath(linuxPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-linux-x64.tar.gz`
`<absolute path>/target/opensearch-dashboards-1.0.0-linux-x64.tar.gz`
);
expect(build.getPlatformArchivePath(linuxArmPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-linux-arm64.tar.gz`
`<absolute path>/target/opensearch-dashboards-1.0.0-linux-arm64.tar.gz`
);
expect(build.getPlatformArchivePath(windowsPlatform)).toMatchInlineSnapshot(
`<absolute path>/target/opensearch-dashboards-8.0.0-windows-x64.zip`
`<absolute path>/target/opensearch-dashboards-1.0.0-windows-x64.zip`
);
});
});
104 changes: 102 additions & 2 deletions src/dev/build/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,23 @@ const versionInfo = jest.requireMock('./version_info').getVersionInfo();

expect.addSnapshotSerializer(createAbsolutePathSerializer());

const setup = async ({ targetAllPlatforms = true }: { targetAllPlatforms?: boolean } = {}) => {
const setup = async ({
targetAllPlatforms = true,
darwinX64 = false,
ananzh marked this conversation as resolved.
Show resolved Hide resolved
linuxArm64 = false,
linuxX64 = false,
}: {
targetAllPlatforms?: boolean;
darwinX64?: boolean;
linuxArm64?: boolean;
linuxX64?: boolean;
} = {}) => {
return await Config.create({
isRelease: true,
targetAllPlatforms,
darwinX64,
linuxArm64,
linuxX64,
});
};

Expand Down Expand Up @@ -89,6 +102,39 @@ describe('#resolveFromRepo()', () => {
});
});

describe('#hasSpecifiedPlatform', () => {
it('return true if darwin x64 is specified', async () => {
const config = await setup({
targetAllPlatforms: false,
darwinX64: true,
});
expect(config.hasSpecifiedPlatform() === true);
});

it('return true if linux arm64 is specified', async () => {
const config = await setup({
targetAllPlatforms: false,
linuxArm64: true,
});
expect(config.hasSpecifiedPlatform() === true);
});

it('return true if linux x64 is specified', async () => {
const config = await setup({
targetAllPlatforms: false,
linuxX64: true,
});
expect(config.hasSpecifiedPlatform() === true);
});

it('return false if no platform is specified', async () => {
const config = await setup({
targetAllPlatforms: true,
});
expect(config.hasSpecifiedPlatform() === false);
});
});

describe('#getPlatform()', () => {
it('throws error when platform does not exist', async () => {
const config = await setup();
Expand Down Expand Up @@ -118,7 +164,7 @@ describe('#getPlatform()', () => {
});

describe('#getTargetPlatforms()', () => {
it('returns an array of all platform objects', async () => {
it('returns an array of all platform objects if config.targetAllPlatforms is true', async () => {
const config = await setup();
expect(
config
Expand All @@ -135,6 +181,60 @@ describe('#getTargetPlatforms()', () => {
`);
});

it('returns just darwin x64 platform when darwinX64 = true', async () => {
const config = await setup({
targetAllPlatforms: false,
darwinX64: true,
});

expect(
config
.getTargetPlatforms()
.map((p) => p.getNodeArch())
.sort()
).toMatchInlineSnapshot(`
Array [
"linux-x64",
]
`);
});

it('returns just linux x64 platform when linuxX64 = true', async () => {
const config = await setup({
targetAllPlatforms: false,
linuxX64: true,
});

expect(
config
.getTargetPlatforms()
.map((p) => p.getNodeArch())
.sort()
).toMatchInlineSnapshot(`
Array [
"darwin-x64",
]
`);
});

it('returns just linux arm64 platform when linuxArm64 = true', async () => {
const config = await setup({
targetAllPlatforms: false,
linuxArm64: true,
});

expect(
config
.getTargetPlatforms()
.map((p) => p.getNodeArch())
.sort()
).toMatchInlineSnapshot(`
Array [
"linux-arm64",
]
`);
});

it('returns just this platform when targetAllPlatforms = false', async () => {
const config = await setup({
targetAllPlatforms: false,
Expand Down
Loading