1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00

Shrink docker image

Don't install apt recommendations and use the ADD directive instead of
running curl in the image. Saves ~380MB in docker image size.
This commit is contained in:
Erik Flodin 2020-12-29 14:42:58 +01:00
parent 39e43a7a74
commit 6df2a5df74
No known key found for this signature in database
GPG key ID: 420A7C865EE3F85F

View file

@ -1,12 +1,29 @@
FROM ubuntu:18.04
MAINTAINER Tim Byrne <sultan@locehilios.com>
# No input during build
ENV DEBIAN_FRONTEND noninteractive
# Shellcheck and esh versions
ARG SC_VER=0.7.1
ARG ESH_VER=0.3.0
# Install prerequisites and configure UTF-8 locale
RUN \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
expect \
git \
gnupg \
locales \
lsb-release \
make \
man \
python3-pip \
vim-tiny \
xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& update-locale LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
# UTF8 locale
RUN apt-get update && apt-get install -y locales
RUN locale-gen en_US.UTF-8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
# Convenience settings for the testbed's root account
@ -15,43 +32,33 @@ RUN echo 'set -o vi' >> /root/.bashrc
# Create a flag to identify when running inside the yadm testbed
RUN touch /.yadmtestbed
# Install prerequisites
RUN \
apt-get update && \
apt-get install -y \
curl \
expect \
git \
gnupg \
lsb-release \
make \
man \
python3-pip \
vim \
&& rm -rf /var/lib/apt/lists/*;
ARG SC_VER=0.7.1
RUN \
curl -fLo - \
https://github.com/koalaman/shellcheck/releases/download/v$SC_VER/shellcheck-v$SC_VER.linux.x86_64.tar.xz | \
tar -xJv && \
mv shellcheck-v$SC_VER/shellcheck /usr/bin && \
rm -rf shellcheck-v$SC_VER
# Install shellcheck
ADD https://github.com/koalaman/shellcheck/releases/download/v$SC_VER/shellcheck-v$SC_VER.linux.x86_64.tar.xz /opt
RUN cd /opt \
&& tar xf shellcheck-v$SC_VER.linux.x86_64.tar.xz \
&& rm -f shellcheck-v$SC_VER.linux.x86_64.tar.xz \
&& ln -s /opt/shellcheck-v$SC_VER/shellcheck /usr/local/bin
# Upgrade pip3 and install requirements
COPY test/requirements.txt /tmp/requirements.txt
RUN pip3 install --upgrade pip setuptools
RUN pip3 install --upgrade -r /tmp/requirements.txt
RUN python3 -m pip install --upgrade pip setuptools \
&& python3 -m pip install --upgrade -r /tmp/requirements.txt \
&& rm -f /tmp/requirements
RUN \
curl https://raw.githubusercontent.com/jirutka/esh/v0.3.0/esh > /usr/local/bin/esh && \
chmod +x /usr/local/bin/esh
# Install esh
ADD https://raw.githubusercontent.com/jirutka/esh/v$ESH_VER/esh /usr/local/bin
RUN chmod +x /usr/local/bin/esh
# Create workdir and dummy Makefile to be used if no /yadm volume is mounted
RUN mkdir /yadm \
&& echo "test:" > /yadm/Makefile \
&& echo "\t@echo 'The yadm project must be mounted at /yadm'" >> /yadm/Makefile \
&& echo "\t@echo 'Try using a docker parameter like -v \"\$\$PWD:/yadm:ro\"'" >> /yadm/Makefile \
&& echo "\t@false" >> /yadm/Makefile
# /yadm will be the work directory for all tests
# docker commands should mount the local yadm project as /yadm
WORKDIR /yadm
# Create a Makefile to be used if no /yadm volume is mounted
RUN echo "test:\n\t@echo 'The yadm project must be mounted at /yadm'\n\t@echo 'Try using a docker parameter like -v \"\$\$PWD:/yadm:ro\"'\n\t@false" > /yadm/Makefile
# By default, run all tests defined
CMD make test