From 8f1342adfc05470caa5438538153c11b600fd57d Mon Sep 17 00:00:00 2001 From: Colin Nelson Date: Thu, 4 Oct 2018 15:24:15 -0700 Subject: [PATCH] adservice: Reduced docker image size to ~165MB (down from ~886MB) by switching to alpine and using multi stage builds --- src/adservice/Dockerfile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/adservice/Dockerfile b/src/adservice/Dockerfile index 1095220..c4e1abc 100644 --- a/src/adservice/Dockerfile +++ b/src/adservice/Dockerfile @@ -1,9 +1,17 @@ -FROM openjdk:8 -RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ - wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ - chmod +x /bin/grpc_health_probe +FROM openjdk:8-alpine as base + +FROM base as builder + WORKDIR /app +# This is because the protoc-gen-grpc-java library +# is a glibc compiled binary and alpine is +# based on musl-libc +RUN apk add --no-cache --allow-untrusted \ + -X https://apkproxy.herokuapp.com/sgerrand/alpine-pkg-glibc \ + glibc \ + glibc-bin + # Next three steps are for caching dependency downloads # to improve subsequent docker build. COPY ["build.gradle", "gradlew", "./"] @@ -12,5 +20,15 @@ RUN ./gradlew downloadRepos COPY . . RUN ./gradlew installDist + +FROM base + +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe + +WORKDIR /app +COPY --from=builder /app . + EXPOSE 9555 ENTRYPOINT ["/app/build/install/hipstershop/bin/AdService"]