Skip to content

Commit

Permalink
[build/docker] Add support for centos ARM builds (elastic#84831)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Tyler Smalley <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2021
1 parent fd2e9d0 commit 2572cd2
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 69 deletions.
68 changes: 53 additions & 15 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ it('build default and oss dist for current platform, without packages, by defaul
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createDockerCentOS": false,
"createDockerContexts": false,
"createDockerUBI": false,
"createRpmPackage": false,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -53,8 +54,9 @@ it('builds packages if --all-platforms is passed', () => {
"buildOssDist": true,
"createArchives": true,
"createDebPackage": true,
"createDockerPackage": true,
"createDockerUbiPackage": true,
"createDockerCentOS": true,
"createDockerContexts": true,
"createDockerUBI": true,
"createRpmPackage": true,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -76,8 +78,9 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createDockerCentOS": false,
"createDockerContexts": false,
"createDockerUBI": false,
"createRpmPackage": true,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -99,8 +102,9 @@ it('limits packages if --deb passed with --all-platforms', () => {
"buildOssDist": true,
"createArchives": true,
"createDebPackage": true,
"createDockerPackage": false,
"createDockerUbiPackage": false,
"createDockerCentOS": false,
"createDockerContexts": false,
"createDockerUBI": false,
"createRpmPackage": false,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -115,16 +119,17 @@ it('limits packages if --deb passed with --all-platforms', () => {
});

it('limits packages if --docker passed with --all-platforms', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--docker']))
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--docker-images']))
.toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": true,
"createDockerUbiPackage": true,
"createDockerCentOS": true,
"createDockerContexts": false,
"createDockerUBI": true,
"createRpmPackage": false,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -139,16 +144,24 @@ it('limits packages if --docker passed with --all-platforms', () => {
});

it('limits packages if --docker passed with --skip-docker-ubi and --all-platforms', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--docker', '--skip-docker-ubi']))
.toMatchInlineSnapshot(`
expect(
readCliArgs([
'node',
'scripts/build',
'--all-platforms',
'--docker-images',
'--skip-docker-ubi',
])
).toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": false,
"createDockerPackage": true,
"createDockerUbiPackage": false,
"createDockerCentOS": true,
"createDockerContexts": false,
"createDockerUBI": false,
"createRpmPackage": false,
"downloadFreshNode": true,
"isRelease": false,
Expand All @@ -161,3 +174,28 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
}
`);
});

it('limits packages if --all-platforms passed with --skip-docker-centos', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--skip-docker-centos']))
.toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"buildDefaultDist": true,
"buildOssDist": true,
"createArchives": true,
"createDebPackage": true,
"createDockerCentOS": false,
"createDockerContexts": true,
"createDockerUBI": true,
"createRpmPackage": true,
"downloadFreshNode": true,
"isRelease": false,
"targetAllPlatforms": true,
"versionQualifier": "",
},
"log": <ToolingLog>,
"showHelp": false,
"unknownFlags": Array [],
}
`);
});
22 changes: 16 additions & 6 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export function readCliArgs(argv: string[]) {
'skip-os-packages',
'rpm',
'deb',
'docker',
'docker-images',
'docker-contexts',
'skip-docker-ubi',
'skip-docker-centos',
'release',
'skip-node-download',
'verbose',
Expand All @@ -42,7 +44,8 @@ export function readCliArgs(argv: string[]) {
debug: true,
rpm: null,
deb: null,
docker: null,
'docker-images': null,
'docker-contexts': null,
oss: null,
'version-qualifier': '',
},
Expand All @@ -69,7 +72,7 @@ export function readCliArgs(argv: string[]) {

// In order to build a docker image we always need
// to generate all the platforms
if (flags.docker) {
if (flags['docker-images'] || flags['docker-contexts']) {
flags['all-platforms'] = true;
}

Expand All @@ -79,7 +82,12 @@ export function readCliArgs(argv: string[]) {
}

// build all if no flags specified
if (flags.rpm === null && flags.deb === null && flags.docker === null) {
if (
flags.rpm === null &&
flags.deb === null &&
flags['docker-images'] === null &&
flags['docker-contexts'] === null
) {
return true;
}

Expand All @@ -95,8 +103,10 @@ export function readCliArgs(argv: string[]) {
createArchives: !Boolean(flags['skip-archives']),
createRpmPackage: isOsPackageDesired('rpm'),
createDebPackage: isOsPackageDesired('deb'),
createDockerPackage: isOsPackageDesired('docker'),
createDockerUbiPackage: isOsPackageDesired('docker') && !Boolean(flags['skip-docker-ubi']),
createDockerCentOS:
isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-centos']),
createDockerUBI: isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-ubi']),
createDockerContexts: isOsPackageDesired('docker-contexts'),
targetAllPlatforms: Boolean(flags['all-platforms']),
};

Expand Down
24 changes: 16 additions & 8 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export interface BuildOptions {
createArchives: boolean;
createRpmPackage: boolean;
createDebPackage: boolean;
createDockerPackage: boolean;
createDockerUbiPackage: boolean;
createDockerUBI: boolean;
createDockerCentOS: boolean;
createDockerContexts: boolean;
versionQualifier: string | undefined;
targetAllPlatforms: boolean;
}
Expand Down Expand Up @@ -95,12 +96,19 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
// control w/ --rpm or --skip-os-packages
await run(Tasks.CreateRpmPackage);
}
if (options.createDockerPackage) {
// control w/ --docker or --skip-docker-ubi or --skip-os-packages
await run(Tasks.CreateDockerPackage);
if (options.createDockerUbiPackage) {
await run(Tasks.CreateDockerUbiPackage);
}
if (options.createDockerUBI) {
// control w/ --docker-images or --skip-docker-ubi or --skip-os-packages
await run(Tasks.CreateDockerUBI);
}

if (options.createDockerCentOS) {
// control w/ --docker-images or --skip-docker-centos or --skip-os-packages
await run(Tasks.CreateDockerCentOS);
}

if (options.createDockerContexts) {
// control w/ --docker-contexts or --skip-os-packages
await run(Tasks.CreateDockerContexts);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ 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}
--rpm {dim Only build the rpm package}
--deb {dim Only build the deb package}
--docker {dim Only build the docker image}
--rpm {dim Only build the rpm packages}
--deb {dim Only build the deb packages}
--docker-images {dim Only build the Docker images}
--docker-contexts {dim Only build the Docker build contexts}
--skip-docker-ubi {dim Don't build the docker ubi image}
--skip-docker-centos {dim Don't build the docker centos image}
--release {dim Produce a release-ready distributable}
--version-qualifier {dim Suffix version with a qualifier}
--skip-node-download {dim Reuse existing downloads of node.js}
Expand Down
54 changes: 45 additions & 9 deletions src/dev/build/tasks/os_packages/create_os_package_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Task } from '../../lib';
import { runFpm } from './run_fpm';
import { runDockerGenerator, runDockerGeneratorForUBI } from './docker_generator';
import { runDockerGenerator } from './docker_generator';

export const CreateDebPackage: Task = {
description: 'Creating deb package',
Expand Down Expand Up @@ -49,20 +49,56 @@ export const CreateRpmPackage: Task = {
},
};

export const CreateDockerPackage: Task = {
description: 'Creating docker package',
export const CreateDockerCentOS: Task = {
description: 'Creating Docker CentOS image',

async run(config, log, build) {
// Builds Docker targets for default and oss
await runDockerGenerator(config, log, build);
await runDockerGenerator(config, log, build, {
ubi: false,
context: false,
architecture: 'x64',
image: true,
});
await runDockerGenerator(config, log, build, {
ubi: false,
context: false,
architecture: 'aarch64',
image: true,
});
},
};

export const CreateDockerUbiPackage: Task = {
description: 'Creating docker ubi package',
export const CreateDockerUBI: Task = {
description: 'Creating Docker UBI image',

async run(config, log, build) {
// Builds Docker target default with ubi7 base image
await runDockerGeneratorForUBI(config, log, build);
if (!build.isOss()) {
await runDockerGenerator(config, log, build, {
ubi: true,
context: false,
architecture: 'x64',
image: true,
});
}
},
};

export const CreateDockerContexts: Task = {
description: 'Creating Docker build contexts',

async run(config, log, build) {
await runDockerGenerator(config, log, build, {
ubi: false,
context: true,
image: false,
});

if (!build.isOss()) {
await runDockerGenerator(config, log, build, {
ubi: true,
context: true,
image: false,
});
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export async function bundleDockerFiles(config: Config, log: ToolingLog, scope:
log.info(
`Generating kibana${scope.imageFlavor}${scope.ubiImageFlavor} docker build context bundle`
);

const dockerFilesDirName = `kibana${scope.imageFlavor}${scope.ubiImageFlavor}-${scope.version}-docker-build-context`;
const dockerFilesBuildDir = resolve(scope.dockerBuildDir, dockerFilesDirName);
const dockerFilesOutputDir = config.resolveFromTarget(`${dockerFilesDirName}.tar.gz`);
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/tasks/os_packages/docker_generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Public License, v 1.
*/

export { runDockerGenerator, runDockerGeneratorForUBI } from './run';
export { runDockerGenerator } from './run';
Loading

0 comments on commit 2572cd2

Please sign in to comment.