|
| 1 | +# Copyright 2021 The Kubernetes Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +ARG BASEIMAGE |
| 16 | + |
| 17 | +FROM $BASEIMAGE AS certs |
| 18 | + |
| 19 | +ENV DEBIAN_FRONTEND=noninteractive |
| 20 | + |
| 21 | +# Install ca-certificates and dependencies |
| 22 | +RUN apt-get update \ |
| 23 | + && apt-get install -y ca-certificates |
| 24 | + |
| 25 | +FROM $BASEIMAGE |
| 26 | + |
| 27 | +ENV DEBIAN_FRONTEND=noninteractive |
| 28 | + |
| 29 | +# Copy only ca-certificates without any dependencies |
| 30 | +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
| 31 | + |
| 32 | +# Smaller package install size. |
| 33 | +COPY excludes /etc/dpkg/dpkg.cfg.d/excludes |
| 34 | + |
| 35 | +# Convenience script for building on this base image. |
| 36 | +COPY clean-install /usr/local/bin/clean-install |
| 37 | + |
| 38 | +# An attempt to fix issues like: |
| 39 | +# ``` |
| 40 | +# Error while loading /usr/sbin/dpkg-split: No such file or directory |
| 41 | +# Error while loading /usr/sbin/dpkg-deb: No such file or directory |
| 42 | +# ``` |
| 43 | +# See: https://github.com/docker/buildx/issues/495 |
| 44 | +RUN ln -s /usr/bin/dpkg-split /usr/sbin/dpkg-split && \ |
| 45 | + ln -s /usr/bin/dpkg-deb /usr/sbin/dpkg-deb && \ |
| 46 | + ln -s /bin/tar /usr/sbin/tar && \ |
| 47 | + ln -s /bin/rm /usr/sbin/rm |
| 48 | + |
| 49 | +# Update system packages. |
| 50 | +RUN apt-get update \ |
| 51 | + && apt-get dist-upgrade -y |
| 52 | + |
| 53 | +# Remove unnecessary packages. |
| 54 | +RUN dpkg --purge --force-remove-essential \ |
| 55 | + bash \ |
| 56 | + e2fsprogs \ |
| 57 | + libss2 \ |
| 58 | + libcom-err2 \ |
| 59 | + libext2fs2 \ |
| 60 | + logsave \ |
| 61 | + ncurses-base \ |
| 62 | + ncurses-bin \ |
| 63 | + tzdata \ |
| 64 | + && apt-get autoremove --purge -y |
| 65 | + |
| 66 | +# No-op stubs replace some unnecessary binaries that may be depended on in the install process (in |
| 67 | +# particular we don't run an init process). |
| 68 | +WORKDIR /usr/local/bin |
| 69 | +RUN touch noop && \ |
| 70 | + chmod 555 noop && \ |
| 71 | + ln -s noop runlevel && \ |
| 72 | + ln -s noop invoke-rc.d && \ |
| 73 | + ln -s noop update-rc.d |
| 74 | +WORKDIR / |
| 75 | + |
| 76 | +# Cleanup cached and unnecessary files. |
| 77 | +RUN apt-get autoremove -y && \ |
| 78 | + apt-get clean -y && \ |
| 79 | + tar -czf /usr/share/copyrights.tar.gz /usr/share/common-licenses /usr/share/doc/*/copyright && \ |
| 80 | + rm -rf \ |
| 81 | + /usr/share/doc \ |
| 82 | + /usr/share/man \ |
| 83 | + /usr/share/info \ |
| 84 | + /usr/share/locale \ |
| 85 | + /var/lib/apt/lists/* \ |
| 86 | + /var/log/* \ |
| 87 | + /var/cache/debconf/* \ |
| 88 | + /usr/share/common-licenses* \ |
| 89 | + /usr/share/bash-completion \ |
| 90 | + ~/.bashrc \ |
| 91 | + ~/.profile \ |
| 92 | + /etc/systemd \ |
| 93 | + /lib/lsb \ |
| 94 | + /lib/udev \ |
| 95 | + /usr/lib/x86_64-linux-gnu/gconv/IBM* \ |
| 96 | + /usr/lib/x86_64-linux-gnu/gconv/EBC* && \ |
| 97 | + mkdir -p /usr/share/man/man1 /usr/share/man/man2 \ |
| 98 | + /usr/share/man/man3 /usr/share/man/man4 \ |
| 99 | + /usr/share/man/man5 /usr/share/man/man6 \ |
| 100 | + /usr/share/man/man7 /usr/share/man/man8 |
0 commit comments