Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 9190601

Browse files
committed
feat: support building centos/debian Docker images in multiplatform format (#1091)
* chore: copy Centos+Systemd Dockerfile from origin See https://github.com/CentOS/CentOS-Dockerfiles/tree/master/systemd/centos7 * chore: copy debian+systemd Dockerfile from origin See https://github.com/alehaa/docker-debian-systemd * chore: add script to build&push ARCH-based images for centos and debian * chore: add script to push the multiplatform manifest for centos and debian This script leverages infra's tool to write the manifest, which needs to be ran right after the images have been built and pushed. Therefore, the tool will write the manifest for both platforms (AMD/ARM), inspecting the existing platform-specific repositories, combining them into the target. FYI, the '-ARCH' placeholder will be replaced with the values in the '--platforms' argument * chore: add regular pipeline to build the docker images * fix: default arch variable value * chore: abstract image name from file system * chore: couple agent's base box with stack platform
1 parent c0ab061 commit 9190601

8 files changed

Lines changed: 345 additions & 0 deletions

File tree

.ci/build-docker-images.groovy

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env groovy
2+
3+
@Library('apm@current') _
4+
5+
pipeline {
6+
agent { label 'ubuntu-20' }
7+
environment {
8+
REPO = 'e2e-testing'
9+
BASE_DIR = "src/github.com/elastic/${env.REPO}"
10+
DOCKER_REGISTRY = 'docker.elastic.co'
11+
DOCKER_REGISTRY_SECRET = 'secret/observability-team/ci/docker-registry/prod'
12+
HOME = "${env.WORKSPACE}"
13+
NOTIFY_TO = credentials('notify-to')
14+
PIPELINE_LOG_LEVEL = 'INFO'
15+
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
16+
}
17+
options {
18+
timeout(time: 1, unit: 'HOURS')
19+
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
20+
timestamps()
21+
ansiColor('xterm')
22+
disableResume()
23+
durabilityHint('PERFORMANCE_OPTIMIZED')
24+
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
25+
quietPeriod(10)
26+
}
27+
triggers {
28+
cron 'H H(0-5) * * 1-5'
29+
}
30+
stages {
31+
stage('Checkout') {
32+
steps {
33+
deleteDir()
34+
gitCheckout(basedir: "${BASE_DIR}",
35+
branch: "${params.BRANCH_REFERENCE}",
36+
repo: "https://github.com/elastic/${REPO}.git",
37+
credentialsId: "${JOB_GIT_CREDENTIALS}"
38+
)
39+
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
40+
}
41+
}
42+
stage('Build AMD Docker images'){
43+
agent { label 'ubuntu-20 && immutable && docker' }
44+
environment {
45+
HOME = "${env.WORKSPACE}/${BASE_DIR}"
46+
}
47+
steps {
48+
deleteDir()
49+
unstash 'source'
50+
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
51+
dir("${BASE_DIR}") {
52+
withEnv(["ARCH=amd64"]) {
53+
sh(label: 'Build AMD images', script: '.ci/scripts/build-docker-images.sh')
54+
}
55+
}
56+
}
57+
}
58+
stage('Build ARM Docker images'){
59+
agent { label 'arm && immutable && docker' }
60+
environment {
61+
HOME = "${env.WORKSPACE}/${BASE_DIR}"
62+
}
63+
steps {
64+
deleteDir()
65+
unstash 'source'
66+
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
67+
dir("${BASE_DIR}") {
68+
withEnv(["ARCH=arm64"]) {
69+
sh(label: 'Build ARM images', script: '.ci/scripts/build-docker-images.sh')
70+
}
71+
}
72+
}
73+
}
74+
stage('Push multiplatform manifest'){
75+
agent { label 'ubuntu-20 && immutable && docker' }
76+
environment {
77+
HOME = "${env.WORKSPACE}/${BASE_DIR}"
78+
}
79+
steps {
80+
deleteDir()
81+
unstash 'source'
82+
dockerLogin(secret: "${DOCKER_ELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
83+
dir("${BASE_DIR}") {
84+
sh(label: 'Push multiplatform manifest', script: '.ci/scripts/push-multiplatform-manifest.sh')
85+
}
86+
}
87+
}
88+
}
89+
post {
90+
cleanup {
91+
notifyBuildResult()
92+
}
93+
}
94+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM centos:7
2+
3+
ENV container docker
4+
5+
LABEL maintainer="manuel.delapena@elastic.co"
6+
7+
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
8+
rm -f /lib/systemd/system/multi-user.target.wants/*;\
9+
rm -f /etc/systemd/system/*.wants/*;\
10+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
11+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
12+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
13+
rm -f /lib/systemd/system/basic.target.wants/*;\
14+
rm -f /lib/systemd/system/anaconda.target.wants/*;
15+
16+
VOLUME [ "/sys/fs/cgroup" ]
17+
18+
CMD ["/usr/sbin/init"]
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# This file is part of docker-debian-systemd.
2+
#
3+
# Copyright (c)
4+
# 2018-2019 Alexander Haase <ahaase@alexhaase.de>
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
24+
# This image bases on the regular Debian image. By default the 'latest' tag
25+
# (pointing to the current stable release) of the parent image will be used.
26+
# However, an alternate parent tag may be set by defining the 'TAG' build
27+
# argument to a specific Debian release, e.g. 'stretch' or 'buster'.
28+
ARG TAG=latest
29+
FROM debian:${TAG}
30+
LABEL maintainer="manuel.delapena@elastic.co"
31+
32+
# Configure the debconf frontend.
33+
#
34+
# This image doesn't include whiptail, dialog, nor the readline perl module.
35+
# Therefore, the debconf frontend will be set to 'teletype' to avoid error
36+
# messages about no dialog frontend could be found.
37+
RUN echo 'debconf debconf/frontend select teletype' | debconf-set-selections
38+
39+
40+
# Install the necessary packages.
41+
#
42+
# In addition to the regular Debian base image, a BASIC set of packages from the
43+
# Debian minimal configuration will be installed. After all packages have been
44+
# installed, the apt caches and some log files will be removed to minimize the
45+
# image.
46+
#
47+
# NOTE: An upgrade will be performed to include updates and security fixes of
48+
# installed packages that received updates in the Debian repository after
49+
# the upstream image has been created.
50+
#
51+
# NOTE: No syslog daemon will be installed, as systemd's journald should fit
52+
# most needs. Please file an issue if you think this should be changed.
53+
RUN apt-get update
54+
RUN apt-get dist-upgrade -y
55+
RUN apt-get install -y --no-install-recommends \
56+
systemd \
57+
systemd-sysv \
58+
cron \
59+
anacron
60+
61+
RUN apt-get clean
62+
RUN rm -rf \
63+
/var/lib/apt/lists/* \
64+
/var/log/alternatives.log \
65+
/var/log/apt/history.log \
66+
/var/log/apt/term.log \
67+
/var/log/dpkg.log
68+
69+
70+
# Configure systemd.
71+
#
72+
# For running systemd inside a Docker container, some additional tweaks are
73+
# required. For a detailed list see:
74+
#
75+
# https://developers.redhat.com/blog/2016/09/13/ \
76+
# running-systemd-in-a-non-privileged-container/
77+
#
78+
# Additional tweaks will be applied in the final image below.
79+
80+
# To avoid ugly warnings when running this image on a host running systemd, the
81+
# following units will be masked.
82+
#
83+
# NOTE: This will not remove ALL warnings in all Debian releases, but seems to
84+
# work for stretch.
85+
RUN systemctl mask -- \
86+
dev-hugepages.mount \
87+
sys-fs-fuse-connections.mount
88+
89+
# The machine-id should be generated when creating the container. This will be
90+
# done automatically if the file is not present, so let's delete it.
91+
RUN rm -f \
92+
/etc/machine-id \
93+
/var/lib/dbus/machine-id
94+
95+
96+
97+
98+
# Build the final image.
99+
#
100+
# To get a minimal image without deleted files in intermediate layers, the
101+
# contents of the image previously built will be copied into a second version of
102+
# the parent image.
103+
#
104+
# NOTE: This method requires buildkit, as the differ of buildkit will copy
105+
# changed files only and we'll get a minimal image with just the changed
106+
# files in a single new layer.
107+
#
108+
# NOTE: All settings related to the image's environment (e.g. CMD, ENV and
109+
# VOLUME settings) need to be set in the following image definition to be
110+
# used by child images and containers.
111+
112+
FROM debian:${TAG}
113+
COPY --from=0 / /
114+
115+
116+
# Configure systemd.
117+
#
118+
# For running systemd inside a Docker container, some additional tweaks are
119+
# required. Some of them have already been applied above.
120+
#
121+
# The 'container' environment variable tells systemd that it's running inside a
122+
# Docker container environment.
123+
ENV container docker
124+
125+
# A different stop signal is required, so systemd will initiate a shutdown when
126+
# running 'docker stop <container>'.
127+
STOPSIGNAL SIGRTMIN+3
128+
129+
# The host's cgroup filesystem need's to be mounted (read-only) in the
130+
# container. '/run', '/run/lock' and '/tmp' need to be tmpfs filesystems when
131+
# running the container without 'CAP_SYS_ADMIN'.
132+
#
133+
# NOTE: For running Debian stretch, 'CAP_SYS_ADMIN' still needs to be added, as
134+
# stretch's version of systemd is not recent enough. Buster will run just
135+
# fine without 'CAP_SYS_ADMIN'.
136+
VOLUME [ "/sys/fs/cgroup", "/run", "/run/lock", "/tmp" ]
137+
138+
# As this image should run systemd, the default command will be changed to start
139+
# the init system. CMD will be preferred in favor of ENTRYPOINT, so one may
140+
# override it when creating the container to e.g. to run a bash console instead.
141+
CMD [ "/sbin/init" ]

.ci/jobs/build-docker-images.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
- job:
3+
name: Beats/build-docker-images
4+
display-name: E2E Tests Docker images
5+
description: Job to pre-build docker images used in E2E tests.
6+
view: Beats
7+
project-type: pipeline
8+
parameters:
9+
- string:
10+
name: BRANCH_REFERENCE
11+
default: master
12+
description: the Git branch specifier
13+
pipeline-scm:
14+
script-path: .ci/build-docker-images.groovy
15+
scm:
16+
- git:
17+
url: git@github.com:elastic/e2e-testint.git
18+
refspec: +refs/heads/*:refs/remotes/origin/*
19+
wipe-workspace: true
20+
name: origin
21+
shallow-clone: true
22+
credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba
23+
reference-repo: /var/lib/jenkins/.git-references/e2e-testing.git
24+
branches:
25+
- $BRANCH_REFERENCE
26+
triggers:
27+
- timed: 'H H(0-5) * * 1-5'

.ci/scripts/build-docker-images.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
## Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
## or more contributor license agreements. Licensed under the Elastic License;
5+
## you may not use this file except in compliance with the Elastic License.
6+
7+
set -euxo pipefail
8+
9+
ARCH="${ARCH:-amd64}"
10+
11+
readonly ELASTIC_REGISTRY="docker.elastic.co"
12+
readonly OBSERVABILITY_CI_REGISTRY="${ELASTIC_REGISTRY}/observability-ci"
13+
14+
main() {
15+
_build_and_push "centos-systemd"
16+
_build_and_push "debian-systemd"
17+
}
18+
19+
_build_and_push() {
20+
local image="${1}"
21+
22+
local platformSpecificImage="${OBSERVABILITY_CI_REGISTRY}/${image}-${ARCH}:latest"
23+
24+
docker build -t ${platformSpecificImage} .ci/docker/${image}
25+
26+
docker push ${platformSpecificImage}
27+
}
28+
29+
main "$@"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
## Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
## or more contributor license agreements. Licensed under the Elastic License;
5+
## you may not use this file except in compliance with the Elastic License.
6+
7+
set -euxo pipefail
8+
9+
readonly ELASTIC_REGISTRY="docker.elastic.co"
10+
readonly MANIFEST_TOOL_IMAGE="${ELASTIC_REGISTRY}/infra/manifest-tool:latest"
11+
readonly OBSERVABILITY_CI_REGISTRY="${ELASTIC_REGISTRY}/observability-ci"
12+
13+
main() {
14+
_push_multiplatform_manifest "centos-systemd"
15+
_push_multiplatform_manifest "debian-systemd"
16+
}
17+
18+
_push_multiplatform_manifest() {
19+
local image="${1}"
20+
21+
local fqn="${OBSERVABILITY_CI_REGISTRY}/${image}:latest"
22+
# the '-ARCH' placeholder will be replaced with the values in the '--platforms' argument
23+
local templateFqn="${OBSERVABILITY_CI_REGISTRY}/${image}-ARCH:latest"
24+
25+
docker run --rm \
26+
--mount src=${HOME}/.docker,target=/docker-config,type=bind \
27+
${MANIFEST_TOOL_IMAGE} --docker-cfg "/docker-config" \
28+
push from-args \
29+
--platforms linux/amd64,linux/arm64 \
30+
--template ${templateFqn} \
31+
--target ${fqn}
32+
}
33+
34+
main "$@"

cli/config/compose/services/centos-systemd/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
image: centos/systemd:${centos_systemdTag:-latest}
55
container_name: ${centos_systemdContainerName}
66
entrypoint: "/usr/sbin/init"
7+
platform: ${stackPlatform:-linux/amd64}
78
privileged: true
89
volumes:
910
- ${centos_systemdAgentBinarySrcPath:-.}:${centos_systemdAgentBinaryTargetPath:-/tmp}

cli/config/compose/services/debian-systemd/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
image: alehaa/debian-systemd:${debian_systemdTag:-stretch}
55
container_name: ${debian_systemdContainerName}
66
entrypoint: "/sbin/init"
7+
platform: ${stackPlatform:-linux/amd64}
78
privileged: true
89
volumes:
910
- ${debian_systemdAgentBinarySrcPath:-.}:${debian_systemdAgentBinaryTargetPath:-/tmp}

0 commit comments

Comments
 (0)