-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDockerfile.keepalived
More file actions
53 lines (45 loc) · 2.36 KB
/
Dockerfile.keepalived
File metadata and controls
53 lines (45 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
FROM nvcr.io/nvidia/doca/canonical:ubuntu24.04
USER root
ARG PACKAGES="keepalived iproute2 curl"
ARG ubuntu_mirror=http://archive.ubuntu.com/ubuntu/
RUN find /etc/apt/sources.list* -type f -exec sed -i \
-e "s|http://archive.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
-e "s|http://ports.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
-e "s|http://security.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" '{}' \;
# Install packages and track what was added for source code download
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get upgrade -y -qq && \
dpkg -l | awk '/^ii/{print $2}' | sort > /initial-dpkg-list.txt && \
apt-get install -y -qq --no-install-recommends ${PACKAGES} && \
dpkg -l | awk '/^ii/{print $2}' | sort > /after-dpkg-list.txt
# Download source code for apt packages (compliance requirement)
# Starting from Ubuntu 24.04 shifted to the new deb822 format for source management
# Enable `deb-src` to be able to fetch sources using `apt-get source`
ARG PACKAGE_SOURCES
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
test "${PACKAGE_SOURCES}" = "false" || ( \
mkdir /src && \
cd /src && \
sed -i 's/^# deb-src/deb-src/g' /etc/apt/sources.list /etc/apt/sources.list.d/* && \
sed -i 's/^Types: deb$/Types: deb deb-src/g' /etc/apt/sources.list.d/*.sources && \
apt-get update && \
apt-get source --download-only ${PACKAGES} && \
comm -23 --nocheck-order /after-dpkg-list.txt /initial-dpkg-list.txt | xargs -r apt-get source --download-only && \
rm -f /initial-dpkg-list.txt /after-dpkg-list.txt && \
cd / && \
tar -cf source-code.tar /src && \
rm -rf /src \
)
# Create user for track_script in keepalived.conf
# This user is referenced in the keepalived configuration generated by the init container
RUN useradd -r -s /usr/sbin/nologin keepalived_script
WORKDIR /root
# Run keepalived in foreground with logging to stdout
# Config is mounted at /usr/local/etc/keepalived/keepalived.conf by DaemonSet init container
# -n: foreground mode (required for container)
# -l: log to stdout (Kubernetes best practice)
# -f: specify config file path
CMD ["keepalived", "-n", "-l", "-f", "/usr/local/etc/keepalived/keepalived.conf"]