Skip to content

Commit 92ff040

Browse files
committed
Docker: T7568: clean apt cache + clean some /tmp files
This saves ~50Mb for vyos-build image: 2.04Gb -> 1.99Gb And ~19Mb for vyos image: 155Mb -> 136Mb Docker stores all files created in each layer so command ``` RUN wget -O /tmp/open-vmdk-master.zip https://github.com/.../master.zip && \ unzip -d /tmp/ /tmp/open-vmdk-master.zip && \ cd /tmp/open-vmdk-master/ && make && make install ``` will store open-vmdk-master.zip and /tmp/open-vmdk-master in the image even though there is a cleanup command later: ``` RUN rm -rf /tmp/* ``` The cleanup command just makes these files invisible in last layer. So temporary file must be removed in same RUN command not to be stored in the image. This commit adds such removals.
1 parent 3222553 commit 92ff040

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

docker-vyos/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ LABEL authors="VyOS Maintainers <maintainers@vyos.io>"
2525
ENV DEBIAN_FRONTEND noninteractive
2626

2727
RUN /bin/echo -e 'APT::Install-Recommends "0";\nAPT::Install-Suggests "0";' > /etc/apt/apt.conf.d/01norecommends
28+
# Clean cache after each apt-get install command so that it is not stored in the image
29+
RUN /bin/echo -e 'DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb /var/lib/apt/lists/* || true";};' > /etc/apt/apt.conf.d/clean
2830

2931
# Base packaged needed to build packages and their package dependencies
3032
RUN apt-get update && apt-get install -y \
@@ -69,6 +71,9 @@ RUN bash /tmp/vyos_install_stage_03.sh
6971
# Delete installer scripts
7072
RUN rm -rf /tmp/*
7173

74+
# Remove cleanup script so that in-container apt-get install uses cache
75+
RUN rm /etc/apt/apt.conf.d/clean
76+
7277

7378
# Make changes specific to the container environment
7479

docker/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ LABEL authors="VyOS Maintainers <maintainers@vyos.io>" \
5353
ENV DEBIAN_FRONTEND=noninteractive
5454

5555
RUN /bin/echo -e 'APT::Install-Recommends "0";\nAPT::Install-Suggests "0";' > /etc/apt/apt.conf.d/01norecommends
56+
# Clean cache after each apt-get install command so that it is not stored in the image
57+
RUN /bin/echo -e 'DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb /var/lib/apt/lists/* || true";};' > /etc/apt/apt.conf.d/clean
5658

5759
RUN apt-get update && apt-get install -y \
5860
dialog \
@@ -142,7 +144,8 @@ RUN dpkg-reconfigure ca-certificates; \
142144
RUN curl https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh \
143145
--output /tmp/opam_install.sh --retry 10 --retry-delay 5 && \
144146
sed -i 's/read_tty BINDIR/BINDIR=""/' /tmp/opam_install.sh && sh /tmp/opam_install.sh && \
145-
opam init --root=/opt/opam --comp=${OCAML_VERSION} --disable-sandboxing --no-setup
147+
opam init --root=/opt/opam --comp=${OCAML_VERSION} --disable-sandboxing --no-setup \
148+
&& rm /tmp/opam_install.sh
146149

147150
RUN eval $(opam env --root=/opt/opam --set-root) && opam install -y \
148151
re \
@@ -162,7 +165,8 @@ RUN apt-get update && apt-get install -y \
162165
# Install open-vmdk
163166
RUN wget -O /tmp/open-vmdk-master.zip https://github.com/vmware/open-vmdk/archive/master.zip && \
164167
unzip -d /tmp/ /tmp/open-vmdk-master.zip && \
165-
cd /tmp/open-vmdk-master/ && make && make install
168+
cd /tmp/open-vmdk-master/ && make && make install && \
169+
cd /tmp && rm -rf /tmp/open-vmdk-master/ && rm /tmp/open-vmdk-master.zip
166170

167171
# Packages need for build live-build
168172
RUN apt-get update && apt-get install -y \
@@ -175,7 +179,9 @@ RUN git clone https://salsa.debian.org/live-team/live-build.git /tmp/live-build
175179
patch -p1 < /tmp/0001-save-package-info.patch && \
176180
dch -n "Applying fix for save package info" && \
177181
dpkg-buildpackage -us -uc && \
178-
dpkg -i ../live-build*.deb
182+
dpkg -i ../live-build*.deb && \
183+
rm -rf /tmp/live-build
184+
179185
#
180186
# live-build: building in docker fails with mounting /proc | /sys
181187
#
@@ -190,13 +196,15 @@ RUN wget https://salsa.debian.org/klausenbusk-guest/debootstrap/commit/a9a603b17
190196
patch -p1 < /tmp/a9a603b17cadbf52cb98cde0843dc9f23a08b0da.patch && \
191197
dch -n "Applying fix for docker image compile" && \
192198
dpkg-buildpackage -us -uc && \
193-
sudo dpkg -i ../debootstrap*.deb
199+
sudo dpkg -i ../debootstrap*.deb \
200+
&& rm /tmp/a9a603b17cadbf52cb98cde0843dc9f23a08b0da.patch \
201+
&& rm -rf /tmp/debootstrap
194202

195203
# FPM is used when generation Debian pckages for e.g. Intel QAT drivers
196204
RUN gem install --no-document fpm
197205

198206
# Packages needed for vyos-1x
199-
RUN pip install --break-system-packages \
207+
RUN pip --no-cache --no-cache-dir install --break-system-packages \
200208
git+https://github.com/aristanetworks/j2lint.git@341b5d5db86 \
201209
pyhumps==3.8.0; \
202210
apt-get update && apt-get install -y \
@@ -323,6 +331,9 @@ RUN sed -i 's/UID_MAX\t\t\t60000/UID_MAX\t\t\t2000000000/g' /etc/login.defs
323331
# Cleanup
324332
RUN rm -rf /tmp/*
325333

334+
# Remove cleanup script so that in-container apt-get install uses cache
335+
RUN rm /etc/apt/apt.conf.d/clean
336+
326337
# Disable mouse in vim
327338
RUN printf "set mouse=\nset ttymouse=\n" > /etc/vim/vimrc.local
328339

0 commit comments

Comments
 (0)