[build] Add support for configurable docker tag (#148603)

This will be used to tag a version with  an abbreviated commit sha
opposed to the current semver style approach.

e.g. `kibana:8.7.0` -> `kibana:abcdef1`

Defaults will remain semver style - this is in support of a testing
pipeline.

## Testing

```
node scripts/build \
  --docker-images \
  --docker-tag="abcdef1" \
  --skip-docker-ubi \
  --skip-docker-cloud \
  --skip-docker-context
```
should produce an image `docker.elastic.co/kibana/kibana:abcdef1`

```
node scripts/build \
  --docker-images \
  --skip-docker-ubi \
  --skip-docker-cloud \
  --skip-docker-context
```
should produce an image `docker.elastic.co/kibana/kibana:8.7.0-SNAPSHOT`
This commit is contained in:
Jon 2023-01-10 11:51:07 -06:00 committed by GitHub
parent 72bd23b740
commit d466349547
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 33 additions and 3 deletions

View file

@ -41,6 +41,7 @@ it('build default and oss dist for current platform, without packages, by defaul
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -75,6 +76,7 @@ it('builds packages if --all-platforms is passed', () => {
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -109,6 +111,7 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -143,6 +146,7 @@ it('limits packages if --deb passed with --all-platforms', () => {
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -178,6 +182,7 @@ it('limits packages if --docker passed with --all-platforms', () => {
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -220,6 +225,7 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,
@ -255,6 +261,7 @@ it('limits packages if --all-platforms passed with --skip-docker-ubuntu', () =>
"dockerContextUseLocalArtifact": null,
"dockerCrossCompile": false,
"dockerPush": false,
"dockerTag": null,
"dockerTagQualifier": null,
"downloadCloudDependencies": true,
"downloadFreshNode": true,

View file

@ -58,6 +58,7 @@ export function readCliArgs(argv: string[]) {
'docker-context-use-local-artifact': null,
'docker-cross-compile': false,
'docker-push': false,
'docker-tag': null,
'docker-tag-qualifier': null,
'version-qualifier': '',
'epr-registry': 'snapshot',
@ -120,6 +121,7 @@ export function readCliArgs(argv: string[]) {
dockerContextUseLocalArtifact: flags['docker-context-use-local-artifact'],
dockerCrossCompile: Boolean(flags['docker-cross-compile']),
dockerPush: Boolean(flags['docker-push']),
dockerTag: flags['docker-tag'],
dockerTagQualifier: flags['docker-tag-qualifier'],
initialize: !Boolean(flags['skip-initialize']),
downloadFreshNode: !Boolean(flags['skip-node-download']),

View file

@ -16,6 +16,7 @@ export interface BuildOptions {
dockerContextUseLocalArtifact: boolean | null;
dockerCrossCompile: boolean;
dockerPush: boolean;
dockerTag: string | null;
dockerTagQualifier: string | null;
downloadFreshNode: boolean;
downloadCloudDependencies: boolean;

View file

@ -35,6 +35,7 @@ const config = new Config(
false,
false,
'',
'',
false,
true
);

View file

@ -32,6 +32,7 @@ const setup = async ({ targetAllPlatforms = true }: { targetAllPlatforms?: boole
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTag: '',
dockerTagQualifier: '',
});
};

View file

@ -21,6 +21,7 @@ interface Options {
versionQualifier?: string;
dockerContextUseLocalArtifact: boolean | null;
dockerCrossCompile: boolean;
dockerTag: string | null;
dockerTagQualifier: string | null;
dockerPush: boolean;
}
@ -32,6 +33,7 @@ export class Config {
versionQualifier,
dockerContextUseLocalArtifact,
dockerCrossCompile,
dockerTag,
dockerTagQualifier,
dockerPush,
}: Options) {
@ -52,6 +54,7 @@ export class Config {
}),
dockerContextUseLocalArtifact,
dockerCrossCompile,
dockerTag,
dockerTagQualifier,
dockerPush,
isRelease
@ -66,6 +69,7 @@ export class Config {
private readonly versionInfo: VersionInfo,
private readonly dockerContextUseLocalArtifact: boolean | null,
private readonly dockerCrossCompile: boolean,
private readonly dockerTag: string | null,
private readonly dockerTagQualifier: string | null,
private readonly dockerPush: boolean,
public readonly isRelease: boolean
@ -85,6 +89,13 @@ export class Config {
return this.nodeVersion;
}
/**
* Get the docker tag qualifier
*/
getDockerTag() {
return this.dockerTag;
}
/**
* Get the docker tag qualifier
*/

View file

@ -49,6 +49,7 @@ const setup = async () => {
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTag: '',
dockerTagQualifier: '',
});

View file

@ -39,6 +39,7 @@ async function setup({ failOnUrl }: { failOnUrl?: string } = {}) {
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTag: '',
dockerTagQualifier: '',
});

View file

@ -42,6 +42,7 @@ async function setup() {
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTag: '',
dockerTagQualifier: '',
});

View file

@ -47,6 +47,7 @@ async function setup(actualShaSums?: Record<string, string>) {
dockerContextUseLocalArtifact: false,
dockerCrossCompile: false,
dockerPush: false,
dockerTag: '',
dockerTagQualifier: '',
});

View file

@ -74,6 +74,7 @@ export async function runDockerGenerator(
];
const dockerPush = config.getDockerPush();
const dockerTag = config.getDockerTag();
const dockerTagQualifier = config.getDockerTagQualfiier();
const dockerCrossCompile = config.getDockerCrossCompile();
const publicArtifactSubdomain = config.isRelease ? 'artifacts' : 'snapshots-no-kpi';
@ -90,6 +91,7 @@ export async function runDockerGenerator(
dockerBuildDir,
dockerTargetFilename,
dockerPush,
dockerTag,
dockerTagQualifier,
dockerCrossCompile,
baseImageName,

View file

@ -15,6 +15,7 @@ export interface TemplateContext {
license: string;
artifactsDir: string;
dockerPush: boolean;
dockerTag: string | null;
dockerTagQualifier: string | null;
dockerCrossCompile: boolean;
imageTag: string;

View file

@ -14,6 +14,7 @@ function generator({
imageTag,
imageFlavor,
dockerPush,
dockerTag,
dockerTagQualifier,
dockerCrossCompile,
version,
@ -21,9 +22,8 @@ function generator({
baseImageName,
architecture,
}: TemplateContext) {
const dockerTargetName = `${imageTag}${imageFlavor}:${version}${
dockerTagQualifier ? '-' + dockerTagQualifier : ''
}`;
const tag = dockerTag ? dockerTag : version + dockerTagQualifier ? '-' + dockerTagQualifier : '';
const dockerTargetName = `${imageTag}${imageFlavor}:${tag}`;
const dockerArchitecture = architecture === 'aarch64' ? 'linux/arm64' : 'linux/amd64';
const dockerBuild = dockerCrossCompile
? `docker buildx build --platform ${dockerArchitecture} -t ${dockerTargetName} -f Dockerfile . || exit 1;`