From commits-return-8566-apmail-kudu-commits-archive=kudu.apache.org@kudu.apache.org Mon Mar 9 19:52:35 2020 Return-Path: X-Original-To: apmail-kudu-commits-archive@minotaur.apache.org Delivered-To: apmail-kudu-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 25BAA19FA2 for ; Mon, 9 Mar 2020 19:52:35 +0000 (UTC) Received: (qmail 30991 invoked by uid 500); 9 Mar 2020 19:52:34 -0000 Delivered-To: apmail-kudu-commits-archive@kudu.apache.org Received: (qmail 30871 invoked by uid 500); 9 Mar 2020 19:52:34 -0000 Mailing-List: contact commits-help@kudu.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kudu.apache.org Delivered-To: mailing list commits@kudu.apache.org Received: (qmail 30843 invoked by uid 99); 9 Mar 2020 19:52:34 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Mar 2020 19:52:34 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6264D8DACD; Mon, 9 Mar 2020 19:52:34 +0000 (UTC) Date: Mon, 09 Mar 2020 19:52:36 +0000 To: "commits@kudu.apache.org" Subject: [kudu] 02/03: [docker] Reduce docker image size MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: granthenke@apache.org In-Reply-To: <158378355429.7719.1429203519855987688@gitbox.apache.org> References: <158378355429.7719.1429203519855987688@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: kudu X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: c1b7d76bbe91fa9d024358c2923051fb9df91a5c X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20200309195234.6264D8DACD@gitbox.apache.org> 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.