Skip to content

Commit

Permalink
[build] Add flag for using a local Kibana artifact in the Docker cont…
Browse files Browse the repository at this point in the history
…ext (#129375)

* [build] Add flag for using a local Kibana artifact in the Docker context

Currently Docker contexts always install a Kibana distribution from  an
http endpoint.  These endpoints are only available after a release has
been published, making pre-release testing difficult.

This adds a flag to use a local Kibana artifact, with the intention of
verifying the Docker contexts with release artifacts prior to publishing
the release.

* fix types
  • Loading branch information
jbudz authored Apr 4, 2022
1 parent 0e490e7 commit 4182523
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ it('build default and oss dist for current platform, without packages, by defaul
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": false,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -68,6 +69,7 @@ it('builds packages if --all-platforms is passed', () => {
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": true,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -100,6 +102,7 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": true,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -132,6 +135,7 @@ it('limits packages if --deb passed with --all-platforms', () => {
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": false,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -165,6 +169,7 @@ it('limits packages if --docker passed with --all-platforms', () => {
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": false,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -205,6 +210,7 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": false,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down Expand Up @@ -238,6 +244,7 @@ it('limits packages if --all-platforms passed with --skip-docker-ubuntu', () =>
"createGenericFolders": true,
"createPlatformFolders": true,
"createRpmPackage": true,
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTagQualifier": null,
Expand Down
3 changes: 3 additions & 0 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function readCliArgs(argv: string[]) {
'skip-os-packages',
'rpm',
'deb',
'docker-context-use-local-artifact',
'docker-cross-compile',
'docker-images',
'docker-push',
Expand Down Expand Up @@ -53,6 +54,7 @@ export function readCliArgs(argv: string[]) {
rpm: null,
deb: null,
'docker-images': null,
'docker-context-use-local-artifact': null,
'docker-cross-compile': false,
'docker-push': false,
'docker-tag-qualifier': null,
Expand Down Expand Up @@ -114,6 +116,7 @@ export function readCliArgs(argv: string[]) {
const buildOptions: BuildOptions = {
isRelease: Boolean(flags.release),
versionQualifier: flags['version-qualifier'],
dockerContextUseLocalArtifact: flags['docker-context-use-local-artifact'],
dockerCrossCompile: Boolean(flags['docker-cross-compile']),
dockerPush: Boolean(flags['docker-push']),
dockerTagQualifier: flags['docker-tag-qualifier'],
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Tasks from './tasks';

export interface BuildOptions {
isRelease: boolean;
dockerContextUseLocalArtifact: boolean | null;
dockerCrossCompile: boolean;
dockerPush: boolean;
dockerTagQualifier: string | null;
Expand Down
33 changes: 17 additions & 16 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ if (showHelp) {
build the Kibana distributable
options:
--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 packages}
--deb {dim Only build the deb packages}
--docker-images {dim Only build the Docker images}
--docker-cross-compile {dim Produce arm64 and amd64 Docker images}
--docker-contexts {dim Only build the Docker build contexts}
--skip-docker-ubi {dim Don't build the docker ubi image}
--skip-docker-ubuntu {dim Don't build the docker ubuntu 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}
--verbose,-v {dim Turn on verbose logging}
--no-debug {dim Turn off debug logging}
--epr-registry {dim Specify the EPR registry to use for Fleet packages, 'production' or 'snapshot'}
--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 packages}
--deb {dim Only build the deb packages}
--docker-images {dim Only build the Docker images}
--docker-context-use-local-artifact {dim Use a local artifact when building the Docker context}
--docker-cross-compile {dim Produce arm64 and amd64 Docker images}
--docker-contexts {dim Only build the Docker build contexts}
--skip-docker-ubi {dim Don't build the docker ubi image}
--skip-docker-ubuntu {dim Don't build the docker ubuntu 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}
--verbose,-v {dim Turn on verbose logging}
--no-debug {dim Turn off debug logging}
--epr-registry {dim Specify the EPR registry to use for Fleet packages, 'production' or 'snapshot'}
`) + '\n'
);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/lib/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const config = new Config(
buildVersion: '8.0.0',
},
false,
false,
'',
false,
true
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const setup = async ({ targetAllPlatforms = true }: { targetAllPlatforms?: boole
return await Config.create({
isRelease: true,
targetAllPlatforms,
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTagQualifier: '',
Expand Down
11 changes: 11 additions & 0 deletions src/dev/build/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Options {
isRelease: boolean;
targetAllPlatforms: boolean;
versionQualifier?: string;
dockerContextUseLocalArtifact: boolean | null;
dockerCrossCompile: boolean;
dockerTagQualifier: string | null;
dockerPush: boolean;
Expand All @@ -36,6 +37,7 @@ export class Config {
isRelease,
targetAllPlatforms,
versionQualifier,
dockerContextUseLocalArtifact,
dockerCrossCompile,
dockerTagQualifier,
dockerPush,
Expand All @@ -53,6 +55,7 @@ export class Config {
versionQualifier,
pkg,
}),
dockerContextUseLocalArtifact,
dockerCrossCompile,
dockerTagQualifier,
dockerPush,
Expand All @@ -66,6 +69,7 @@ export class Config {
private readonly nodeVersion: string,
private readonly repoRoot: string,
private readonly versionInfo: VersionInfo,
private readonly dockerContextUseLocalArtifact: boolean | null,
private readonly dockerCrossCompile: boolean,
private readonly dockerTagQualifier: string | null,
private readonly dockerPush: boolean,
Expand Down Expand Up @@ -100,6 +104,13 @@ export class Config {
return this.dockerPush;
}

/**
* Use a local Kibana distribution when producing a docker context
*/
getDockerContextUseLocalArtifact() {
return this.dockerContextUseLocalArtifact;
}

/**
* Get docker cross compile
*/
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/lib/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const setup = async () => {
isRelease: true,
targetAllPlatforms: true,
versionQualifier: '-SNAPSHOT',
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTagQualifier: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function setup({ failOnUrl }: { failOnUrl?: string } = {}) {
const config = await Config.create({
isRelease: true,
targetAllPlatforms: true,
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTagQualifier: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async function setup() {
const config = await Config.create({
isRelease: true,
targetAllPlatforms: true,
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTagQualifier: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function setup(actualShaSums?: Record<string, string>) {
const config = await Config.create({
isRelease: true,
targetAllPlatforms: true,
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTagQualifier: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function bundleDockerFiles(config: Config, log: ToolingLog, scope:
const dockerFilesDirName = `kibana${scope.imageFlavor}-${scope.version}-docker-build-context`;
const dockerFilesBuildDir = resolve(scope.dockerBuildDir, dockerFilesDirName);
const dockerFilesOutputDir = config.resolveFromTarget(`${dockerFilesDirName}.tar.gz`);
const dockerContextUseLocalArtifact = config.getDockerContextUseLocalArtifact();

// Create dockerfiles dir inside docker build dir
await mkdirp(dockerFilesBuildDir);
Expand All @@ -32,7 +33,8 @@ export async function bundleDockerFiles(config: Config, log: ToolingLog, scope:
resolve(dockerFilesBuildDir, dockerfileTemplate.name),
dockerfileTemplate.generator({
...scope,
usePublicArtifact: true,
usePublicArtifact:
dockerContextUseLocalArtifact !== null ? !dockerContextUseLocalArtifact : true,
})
);

Expand Down

0 comments on commit 4182523

Please sign in to comment.