From 4640cac4eb2d8c06df667ae7698a3d62d20ab90b Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Wed, 19 Dec 2018 11:45:40 -0800 Subject: [PATCH] Reduce Docker image size This is achieved with these techniques: - Use Alpine as the base image, which is only ~5MB. - Use docker's multi-stage build to keep only the result binaries in the final image. The new image is ~15MB after this change. Also updated Dockerfile to use the current checkout code instead of always sync from the latest. Also added a .dockerignore file to ignore temporary build artifacts. Closes #535. Change-Id: I3c90805ebba40295e69241214ed6d7adbde465b8 --- .dockerignore | 13 +++++++++++++ Dockerfile | 42 +++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..046d758623 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +*.pyc +*.sln +*.VC.db +*.vcxproj* +*/.vs/* +*~ +.DS_store +.cproject +.project +.pydevproject +.repo +.settings +/out* diff --git a/Dockerfile b/Dockerfile index e6f092f420..01420e960a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,31 @@ -FROM ubuntu:14.04 +FROM alpine:3.8 as builder -ENV DEBIAN_FRONTEND noninteractive +# Install packages needed for Shaka Packager. +RUN apk add --no-cache bash build-base curl findutils git ninja python \ + bsd-compat-headers linux-headers libexecinfo-dev -# update, and install basic packages -RUN apt-get update -RUN apt-get install -y \ - build-essential \ - curl \ - git \ - python - -# install depot_tools http://www.chromium.org/developers/how-tos/install-depot-tools +# Install depot_tools. RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git -ENV PATH /depot_tools:$PATH +ENV PATH $PATH:/depot_tools -# install shaka-packager -RUN mkdir shaka_packager +# Alpine uses musl which does not have mallinfo defined in malloc.h. Define the +# structure to workaround a Chromium base bug. +RUN sed -i \ + '/malloc_usable_size/a \\nstruct mallinfo {\n int arena;\n int hblkhd;\n int uordblks;\n};' \ + /usr/include/malloc.h + +ENV GYP_DEFINES='clang=0 use_experimental_allocator_shim=0 use_allocator=none musl=1' + +# Build shaka-packager WORKDIR shaka_packager -RUN gclient config https://www.github.com/google/shaka-packager.git --name=src -RUN gclient sync --no-history +RUN gclient config https://www.github.com/google/shaka-packager.git --name=src --unmanaged +COPY . src +RUN gclient sync RUN cd src && ninja -C out/Release -ENV PATH /shaka_packager/src/out/Release:$PATH + +# Copy only result binaries to our final image. +FROM alpine:3.8 +RUN apk add --no-cache libstdc++ +COPY --from=builder /shaka_packager/src/out/Release/packager \ + /shaka_packager/src/out/Release/mpd_generator \ + /usr/bin/