[build/docker] Replace CentOS base image with Ubuntu (#118928)

* [build/docker] Replace CentOS base image with Ubuntu

* update snapshots

* cleanup

* DEBIAN_FRONTEND=noninteractive

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jonathan Budzenski 2021-12-17 12:46:33 -06:00 committed by GitHub
parent 6e14dc727d
commit ca98cc682c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 50 additions and 29 deletions

View file

@ -28,7 +28,7 @@ if [[ "${GITHUB_PR_LABELS:-}" == *"ci:deploy-cloud"* ]]; then
--docker-tag-qualifier="$GIT_COMMIT" \
--docker-push \
--skip-docker-ubi \
--skip-docker-centos \
--skip-docker-ubuntu \
--skip-docker-contexts
CLOUD_IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" docker.elastic.co/kibana-ci/kibana-cloud)

View file

@ -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,
@ -58,10 +58,10 @@ it('builds packages if --all-platforms is passed', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": true,
"createDockerCentOS": true,
"createDockerCloud": true,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
@ -88,10 +88,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,
@ -118,10 +118,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,
@ -149,10 +149,10 @@ it('limits packages if --docker passed with --all-platforms', () => {
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": true,
"createDockerCloud": true,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
@ -187,10 +187,10 @@ it('limits packages if --docker passed with --skip-docker-ubi and --all-platform
"buildOptions": Object {
"createArchives": true,
"createDebPackage": false,
"createDockerCentOS": true,
"createDockerCloud": true,
"createDockerContexts": true,
"createDockerUBI": false,
"createDockerUbuntu": true,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,
@ -211,17 +211,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": true,
"createDockerContexts": true,
"createDockerUBI": true,
"createDockerUbuntu": false,
"createExamplePlugins": false,
"createGenericFolders": true,
"createPlatformFolders": true,

View file

@ -26,7 +26,7 @@ export function readCliArgs(argv: string[]) {
'docker-push',
'skip-docker-contexts',
'skip-docker-ubi',
'skip-docker-centos',
'skip-docker-ubuntu',
'skip-docker-cloud',
'release',
'skip-node-download',
@ -109,8 +109,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['skip-docker-cloud']),
createDockerUBI: isOsPackageDesired('docker-images') && !Boolean(flags['skip-docker-ubi']),
createDockerContexts: !Boolean(flags['skip-docker-contexts']),

View file

@ -24,7 +24,7 @@ export interface BuildOptions {
createRpmPackage: boolean;
createDebPackage: boolean;
createDockerUBI: boolean;
createDockerCentOS: boolean;
createDockerUbuntu: boolean;
createDockerCloud: boolean;
createDockerContexts: boolean;
versionQualifier: string | undefined;
@ -126,9 +126,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) {

View file

@ -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}

View file

@ -59,20 +59,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,
});
},
@ -99,12 +101,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,
});
},

View file

@ -32,13 +32,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 = '';
@ -91,6 +93,7 @@ export async function runDockerGenerator(
baseOSImage,
dockerBuildDate,
ubi: flags.ubi,
ubuntu: flags.ubuntu,
cloud: flags.cloud,
metricbeatTarball,
filebeatTarball,

View file

@ -23,6 +23,7 @@ export interface TemplateContext {
dockerBuildDate: string;
usePublicArtifact?: boolean;
ubi?: boolean;
ubuntu?: boolean;
cloud?: boolean;
metricbeatTarball?: string;
filebeatTarball?: string;

View file

@ -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 && \
@ -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 ; \
@ -164,7 +177,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}}

View file

@ -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,
});
}