Skip to content

Commit e7a1728

Browse files
committed
reduce the MCO image size
1 parent 6d48b64 commit e7a1728

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

Dockerfile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.22 AS
33
ARG TAGS=""
44
WORKDIR /go/src/github.com/openshift/machine-config-operator
55
COPY . .
6-
# FIXME once we can depend on a new enough host that supports globs for COPY,
7-
# just use that. For now we work around this by copying a tarball.
8-
ENV GOCACHE="/go/rhel9/.cache"
9-
ENV GOMODCACHE="/go/rhel9/pkg/mod"
10-
RUN make install DESTDIR=./instroot-rhel9 && tar -C instroot-rhel9 -cf instroot-rhel9.tar .
6+
RUN make install DESTDIR=./instroot-rhel9
117

128
# Add a RHEL 8 builder to compile the RHEL 8 compatible binaries
139
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.24-openshift-4.22 AS rhel8-builder
1410
ARG TAGS=""
1511
WORKDIR /go/src/github.com/openshift/machine-config-operator
1612
# Copy the RHEL 8 machine-config-daemon binary and rename
1713
COPY . .
18-
ENV GOCACHE="/go/rhel8/.cache"
19-
ENV GOMODCACHE="/go/rhel8/pkg/mod"
20-
RUN make install DESTDIR=./instroot-rhel8 && tar -C instroot-rhel8 -cf instroot-rhel8.tar .
14+
RUN make install DESTDIR=./instroot-rhel8
2115

2216
FROM registry.ci.openshift.org/ocp/4.22:base-rhel9
2317
ARG TAGS=""
@@ -36,18 +30,21 @@ RUN if [ "${TAGS}" = "fcos" ]; then \
3630
sed -i '/- name: rhel-coreos-10/,+3 s/^/#/' /manifests/* && \
3731
# rewrite image names for scos
3832
sed -i 's/rhel-coreos/stream-coreos/g' /manifests/*; fi && \
39-
dnf --setopt=keepcache=true -y install 'nmstate >= 2.2.10' && \
40-
if ! rpm -q util-linux; then dnf install --setopt=keepcache=true -y util-linux; fi && \
33+
dnf -y install 'nmstate >= 2.2.10' && \
34+
if ! rpm -q util-linux; then dnf install -y util-linux; fi && \
4135
# We also need to install fuse-overlayfs and cpp for Buildah to work correctly.
42-
if ! rpm -q buildah; then dnf install --setopt=keepcache=true -y buildah fuse-overlayfs cpp --exclude container-selinux; fi && \
36+
if ! rpm -q buildah; then dnf install -y buildah fuse-overlayfs cpp --exclude container-selinux; fi && \
4337
# Create the build user which will be used for doing OS image builds. We
4438
# use the username "build" and the uid 1000 since this matches what is in
4539
# the official Buildah image.
4640
# Conditional checks if "build" user does not exist before adding user.
47-
if ! id -u "build" >/dev/null 2>&1; then useradd --uid 1000 build; fi
48-
# Copy the binaries *after* we install nmstate so we don't invalidate our cache for local builds.
49-
COPY --from=rhel9-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel9.tar /tmp/instroot-rhel9.tar
50-
RUN cd / && tar xf /tmp/instroot-rhel9.tar && rm -f /tmp/instroot-rhel9.tar
41+
if ! id -u "build" >/dev/null 2>&1; then useradd --uid 1000 build; fi && \
42+
dnf clean all && \
43+
rm -rf /var/cache/dnf/*
44+
# Copy the binaries directly from their build stages into their final location.
45+
# Do this after package installation to avoid invalidating state for faster
46+
# local builds.
47+
COPY --from=rhel9-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel9/usr/bin/* /usr/bin/
5148
# Copy the RHEL 8 machine-config-daemon binary and rename
5249
COPY --from=rhel8-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel8/usr/bin/machine-config-daemon /usr/bin/machine-config-daemon.rhel8
5350
COPY templates /etc/mcc/templates

Dockerfile.rhel7

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@ FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.22 AS
44
ARG TAGS=""
55
WORKDIR /go/src/github.com/openshift/machine-config-operator
66
COPY . .
7-
# FIXME once we can depend on a new enough host that supports globs for COPY,
8-
# just use that. For now we work around this by copying a tarball.
9-
ENV GOCACHE="/go/rhel9/.cache"
10-
ENV GOMODCACHE="/go/rhel9/pkg/mod"
11-
RUN make install DESTDIR=./instroot-rhel9 && tar -C instroot-rhel9 -cf instroot-rhel9.tar .
7+
RUN make install DESTDIR=./instroot-rhel9
128

139
# Add a RHEL 8 builder to compile the RHEL 8 compatible binaries
1410
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.24-openshift-4.22 AS rhel8-builder
1511
ARG TAGS=""
1612
WORKDIR /go/src/github.com/openshift/machine-config-operator
1713
# Copy the RHEL 8 machine-config-daemon binary and rename
1814
COPY . .
19-
ENV GOCACHE="/go/rhel8/.cache"
20-
ENV GOMODCACHE="/go/rhel8/pkg/mod"
21-
RUN make install DESTDIR=./instroot-rhel8 && tar -C instroot-rhel8 -cf instroot-rhel8.tar .
15+
RUN make install DESTDIR=./instroot-rhel8
2216

2317
FROM registry.ci.openshift.org/ocp/4.22:base-rhel9
2418
ARG TAGS=""
@@ -37,18 +31,21 @@ RUN if [ "${TAGS}" = "fcos" ]; then \
3731
sed -i '/- name: rhel-coreos-10/,+3 s/^/#/' /manifests/* && \
3832
# rewrite image names for scos
3933
sed -i 's/rhel-coreos/stream-coreos/g' /manifests/*; fi && \
40-
dnf --setopt=keepcache=true -y install 'nmstate >= 2.2.10' && \
41-
if ! rpm -q util-linux; then dnf install --setopt=keepcache=true -y util-linux; fi && \
34+
dnf -y install 'nmstate >= 2.2.10' && \
35+
if ! rpm -q util-linux; then dnf install -y util-linux; fi && \
4236
# We also need to install fuse-overlayfs and cpp for Buildah to work correctly.
43-
if ! rpm -q buildah; then dnf install --setopt=keepcache=true -y buildah fuse-overlayfs cpp --exclude container-selinux; fi && \
37+
if ! rpm -q buildah; then dnf install -y buildah fuse-overlayfs cpp --exclude container-selinux; fi && \
4438
# Create the build user which will be used for doing OS image builds. We
4539
# use the username "build" and the uid 1000 since this matches what is in
4640
# the official Buildah image.
4741
# Conditional checks if "build" user does not exist before adding user.
48-
if ! id -u "build" >/dev/null 2>&1; then useradd --uid 1000 build; fi
49-
# Copy the binaries *after* we install nmstate so we don't invalidate our cache for local builds.
50-
COPY --from=rhel9-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel9.tar /tmp/instroot-rhel9.tar
51-
RUN cd / && tar xf /tmp/instroot-rhel9.tar && rm -f /tmp/instroot-rhel9.tar
42+
if ! id -u "build" >/dev/null 2>&1; then useradd --uid 1000 build; fi && \
43+
dnf clean all && \
44+
rm -rf /var/cache/dnf/*
45+
# Copy the binaries directly from their build stages into their final location.
46+
# Do this after package installation to avoid invalidating state for faster
47+
# local builds.
48+
COPY --from=rhel9-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel9/usr/bin/* /usr/bin/
5249
# Copy the RHEL 8 machine-config-daemon binary and rename
5350
COPY --from=rhel8-builder /go/src/github.com/openshift/machine-config-operator/instroot-rhel8/usr/bin/machine-config-daemon /usr/bin/machine-config-daemon.rhel8
5451
COPY templates /etc/mcc/templates

0 commit comments

Comments
 (0)