Skip to content

Commit

Permalink
[build/docker] Replace CentOS base image with Ubuntu (#119520)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jbudz and kibanamachine committed Dec 28, 2021
1 parent 92c32a5 commit 6f7b2df
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
18 changes: 9 additions & 9 deletions src/dev/build/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ it('build default and oss dist for current platform, without packages, by defaul
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": false,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": false,
"createDockerUbuntu": false,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand All @@ -55,10 +55,10 @@ it('builds packages if --all-platforms is passed', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": true,
"createDockerCentOS": true,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand All @@ -82,10 +82,10 @@ it('limits packages if --rpm passed with --all-platforms', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": false,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": false,
"createDockerUbuntu": false,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand All @@ -109,10 +109,10 @@ it('limits packages if --deb passed with --all-platforms', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": true,
"createDockerCentOS": false,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": false,
"createDockerUbuntu": false,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand All @@ -137,10 +137,10 @@ it('limits packages if --docker passed with --all-platforms', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": true,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand Down Expand Up @@ -172,10 +172,10 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": true,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": false,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand All @@ -193,17 +193,17 @@ 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']))
it('limits packages if --all-platforms passed with --skip-docker-ubuntu', () => {
expect(readCliArgs(['node', 'scripts/build', '--all-platforms', '--skip-docker-ubuntu']))
.toMatchInlineSnapshot(`
Object {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": true,
"createDockerCentOS": false,
"createDockerCloud": false,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": false,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
Expand Down
6 changes: 3 additions & 3 deletions src/dev/build/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function readCliArgs(argv: string[]) {
'docker-images',
'skip-docker-contexts',
'skip-docker-ubi',
'skip-docker-centos',
'skip-docker-ubuntu',
'docker-cloud',
'release',
'skip-node-download',
Expand Down Expand Up @@ -102,8 +102,8 @@ export function readCliArgs(argv: string[]) {
createExamplePlugins: Boolean(flags['example-plugins']),
createRpmPackage: isOsPackageDesired('rpm'),
createDebPackage: isOsPackageDesired('deb'),
createDockerCentOS:
isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-centos']),
createDockerUbuntu:
isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-ubuntu']),
createDockerCloud: isOsPackageDesired('docker-images') && Boolean(flags['docker-cloud']),
createDockerUBI: isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-ubi']),
createDockerContexts: !Boolean(flags['skip-docker-contexts']),
Expand Down
8 changes: 4 additions & 4 deletions src/dev/build/build_distributables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface BuildOptions {
createRpmPackage: boolean;
createDebPackage: boolean;
createDockerUBI: boolean;
createDockerCentOS: boolean;
createDockerUbuntu: boolean;
createDockerCloud: boolean;
createDockerContexts: boolean;
versionQualifier: string | undefined;
Expand Down Expand Up @@ -119,9 +119,9 @@ export async function buildDistributables(log: ToolingLog, options: BuildOptions
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.createDockerUbuntu) {
// control w/ --docker-images or --skip-docker-ubuntu or --skip-os-packages
await run(Tasks.CreateDockerUbuntu);
}

if (options.createDockerCloud) {
Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (showHelp) {
--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}
--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}
Expand Down
8 changes: 6 additions & 2 deletions src/dev/build/tasks/os_packages/create_os_package_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ export const CreateRpmPackage: Task = {
};

const dockerBuildDate = new Date().toISOString();
export const CreateDockerCentOS: Task = {
description: 'Creating Docker CentOS image',
export const CreateDockerUbuntu: Task = {
description: 'Creating Docker Ubuntu image',

async run(config, log, build) {
await runDockerGenerator(config, log, build, {
architecture: 'x64',
context: false,
image: true,
ubuntu: true,
dockerBuildDate,
});
await runDockerGenerator(config, log, build, {
architecture: 'aarch64',
context: false,
image: true,
ubuntu: true,
dockerBuildDate,
});
},
Expand All @@ -90,12 +92,14 @@ export const CreateDockerCloud: Task = {
architecture: 'x64',
context: false,
cloud: true,
ubuntu: true,
image: true,
});
await runDockerGenerator(config, log, build, {
architecture: 'aarch64',
context: false,
cloud: true,
ubuntu: true,
image: true,
});
},
Expand Down
7 changes: 5 additions & 2 deletions src/dev/build/tasks/os_packages/docker_generator/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export async function runDockerGenerator(
context: boolean;
image: boolean;
ubi?: boolean;
ubuntu?: boolean;
ironbank?: boolean;
cloud?: boolean;
dockerBuildDate?: string;
}
) {
// UBI var config
const baseOSImage = flags.ubi ? 'docker.elastic.co/ubi8/ubi-minimal:latest' : 'centos:8';
let baseOSImage = '';
if (flags.ubuntu) baseOSImage = 'ubuntu:20.04';
if (flags.ubi) baseOSImage = 'docker.elastic.co/ubi8/ubi-minimal:latest';
const ubiVersionTag = 'ubi8';

let imageFlavor = '';
Expand Down Expand Up @@ -85,6 +87,7 @@ export async function runDockerGenerator(
baseOSImage,
dockerBuildDate,
ubi: flags.ubi,
ubuntu: flags.ubuntu,
cloud: flags.cloud,
metricbeatTarball,
filebeatTarball,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface TemplateContext {
dockerBuildDate: string;
usePublicArtifact?: boolean;
ubi?: boolean;
ubuntu?: boolean;
cloud?: boolean;
metricbeatTarball?: string;
filebeatTarball?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ FROM {{{baseOSImage}}} AS builder
{{#ubi}}
RUN {{packageManager}} install -y findutils tar gzip
{{/ubi}}
{{#ubuntu}}
RUN {{packageManager}} update && DEBIAN_FRONTEND=noninteractive {{packageManager}} install -y curl
{{/ubuntu}}

{{#usePublicArtifact}}
RUN cd /tmp && \
Expand Down Expand Up @@ -55,18 +58,28 @@ FROM {{{baseOSImage}}}
EXPOSE 5601

{{#ubi}}
# https://github.com/rpm-software-management/microdnf/issues/50
RUN mkdir -p /run/user/$(id -u)
{{/ubi}}

RUN for iter in {1..10}; do \
{{packageManager}} update --setopt=tsflags=nodocs -y && \
{{packageManager}} install --setopt=tsflags=nodocs -y \
fontconfig freetype shadow-utils nss {{#ubi}}findutils{{/ubi}} && \
fontconfig freetype shadow-utils nss findutils && \
{{packageManager}} clean all && exit_code=0 && break || exit_code=$? && echo "{{packageManager}} error: retry $iter in 10s" && \
sleep 10; \
done; \
(exit $exit_code)
{{/ubi}}
{{#ubuntu}}
RUN for iter in {1..10}; do \
export DEBIAN_FRONTEND=noninteractive && \
{{packageManager}} update && \
{{packageManager}} upgrade -y && \
{{packageManager}} install -y --no-install-recommends \
fontconfig fonts-liberation libnss3 libfontconfig1 ca-certificates curl && \
{{packageManager}} clean && \
rm -rf /var/lib/apt/lists/* && exit_code=0 && break || exit_code=$? && echo "{{packageManager}} error: retry $iter in 10s" && \
sleep 10; \
done; \
(exit $exit_code)
{{/ubuntu}}

# Add an init process, check the checksum to make sure it's a match
RUN set -e ; \
Expand Down Expand Up @@ -163,7 +176,7 @@ ENTRYPOINT ["/bin/tini", "--"]
CMD ["/app/kibana.sh"]
# Generate a stub command that will be overwritten at runtime
RUN mkdir /app && \
echo -e '#!/bin/sh\nexec /usr/local/bin/kibana-docker' > /app/kibana.sh && \
echo -e '#!/bin/bash\nexec /usr/local/bin/kibana-docker' > /app/kibana.sh && \
chmod 0555 /app/kibana.sh
{{/cloud}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function generator(options: TemplateContext) {
const dir = options.ironbank ? 'ironbank' : 'base';
const template = readFileSync(resolve(__dirname, dir, './Dockerfile'));
return Mustache.render(template.toString(), {
packageManager: options.ubi ? 'microdnf' : 'yum',
packageManager: options.ubi ? 'microdnf' : 'apt-get',
...options,
});
}
Expand Down

0 comments on commit 6f7b2df

Please sign in to comment.