This is an automated email from the ASF dual-hosted git repository. granthenke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git commit c1b7d76bbe91fa9d024358c2923051fb9df91a5c Author: Grant Henke AuthorDate: Mon Mar 9 09:50:37 2020 -0500 [docker] Reduce docker image size This patch reduces the Docker `kudu` image size by ~60 MB (295MB -> 235MB). It does this by moving the chown calls to before the files are copied and using the `—chown` flag when copying files. Before this change the chown command would effecively double the size due to how aufs layers work. I also removed some optional and unused packages from the runtime and dev images. Change-Id: I88238679912149d00ae3edc6a9d2d568f13aafca Reviewed-on: http://gerrit.cloudera.org:8080/15389 Tested-by: Kudu Jenkins Reviewed-by: Alexey Serbin --- docker/Dockerfile | 23 +++++++++++++---------- docker/bootstrap-dev-env.sh | 28 ++++++++++++++++++---------- docker/bootstrap-runtime-env.sh | 2 -- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index fe4b3ac..185ff3d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -280,24 +280,27 @@ ARG GID=1000 ARG INSTALL_DIR="/opt/kudu" ARG DATA_DIR="/var/lib/kudu" +# Setup the kudu user and create the neccessary directories. +# We do this before copying any files othwerwise the image size is doubled by the chown change. +RUN groupadd -g ${GID} kudu || groupmod -n kudu $(getent group ${GID} | cut -d: -f1) \ + && useradd --shell /bin/bash -u ${UID} -g ${GID} -m kudu \ + && mkdir -p ${INSTALL_DIR} && chown -R kudu:kudu ${INSTALL_DIR} \ + && mkdir -p ${DATA_DIR} && chown -R kudu:kudu ${DATA_DIR} + # Copy the binaries. WORKDIR $INSTALL_DIR/bin -COPY --from=build /kudu/build/latest/bin/kudu ./ +COPY --chown=kudu:kudu --from=build /kudu/build/latest/bin/kudu ./ # Add to the binaries to the path. ENV PATH=$INSTALL_DIR/bin/:$PATH -WORKDIR $INSTALL_DIR # Copy the web files. -COPY --from=build /kudu/www ./www -COPY ./docker/kudu-entrypoint.sh / +WORKDIR $INSTALL_DIR +COPY --chown=kudu:kudu --from=build /kudu/www ./www -# Setup the kudu user and create the neccessary directories. -RUN groupadd -g ${GID} kudu || groupmod -n kudu $(getent group ${GID} | cut -d: -f1) \ - && useradd --shell /bin/bash -u ${UID} -g ${GID} -m kudu \ - && chown -R kudu:kudu ${INSTALL_DIR} \ - && mkdir -p ${DATA_DIR} && chown -R kudu:kudu ${DATA_DIR} -USER kudu +# Copy the entrypoint script. +COPY --chown=kudu:kudu ./docker/kudu-entrypoint.sh / +USER kudu # Add the entrypoint. ENTRYPOINT ["/kudu-entrypoint.sh"] CMD ["help"] diff --git a/docker/bootstrap-dev-env.sh b/docker/bootstrap-dev-env.sh index 62754ba..9ea5aad 100755 --- a/docker/bootstrap-dev-env.sh +++ b/docker/bootstrap-dev-env.sh @@ -49,7 +49,6 @@ if [[ -f "/usr/bin/yum" ]]; then krb5-workstation \ libtool \ make \ - nscd \ ntp \ openssl-devel \ patch \ @@ -62,12 +61,13 @@ if [[ -f "/usr/bin/yum" ]]; then wget # Install docs build libraries. - yum install -y \ - doxygen \ - gem \ - graphviz \ - ruby-devel \ - zlib-devel + # Note: Uncomment to include in your dev images. These are excluded to reduce image size and build time. + # yum install -y \ + # doxygen \ + # gem \ + # graphviz \ + # ruby-devel \ + # zlib-devel # To build on a version older than 7.0, the Red Hat Developer Toolset # must be installed (in order to have access to a C++11 capable compiler). @@ -133,7 +133,6 @@ elif [[ -f "/usr/bin/apt-get" ]]; then libtool \ lsb-release \ make \ - nscd \ ntp \ openssl \ patch \ @@ -141,9 +140,9 @@ elif [[ -f "/usr/bin/apt-get" ]]; then python \ rsync \ unzip \ - vim-common + vim-common \ + wget - # Install docs build libraries. apt-get install -y --no-install-recommends \ doxygen \ gem \ @@ -151,6 +150,15 @@ elif [[ -f "/usr/bin/apt-get" ]]; then ruby-dev \ xsltproc \ zlib1g-dev + # Install docs build libraries. + # Note: Uncomment to include in your dev images. These are excluded to reduce image size and build time. + # apt-get install -y --no-install-recommends \ + # doxygen \ + # gem \ + # graphviz \ + # ruby-dev \ + # xsltproc \ + # zlib1g-dev # Reduce the image size by cleaning up after the install. apt-get clean diff --git a/docker/bootstrap-runtime-env.sh b/docker/bootstrap-runtime-env.sh index e8353c6..654ec4d 100755 --- a/docker/bootstrap-runtime-env.sh +++ b/docker/bootstrap-runtime-env.sh @@ -37,7 +37,6 @@ if [[ -f "/usr/bin/yum" ]]; then cyrus-sasl-plain \ krb5-server \ krb5-workstation \ - nscd \ openssl # Reduce the image size by cleaning up after the install. @@ -60,7 +59,6 @@ elif [[ -f "/usr/bin/apt-get" ]]; then libsasl2-2 \ libsasl2-modules \ libsasl2-modules-gssapi-mit \ - nscd \ openssl # Reduce the image size by cleaning up after the install.