From 571285d9aa497153253bcc908d0a59edf59a8549 Mon Sep 17 00:00:00 2001 From: Colin Nelson Date: Tue, 9 Oct 2018 10:42:49 -0700 Subject: [PATCH] Optimized adservice Image Size (#67) * adservice: Reduced docker image size to ~165MB (down from ~886MB) by switching to alpine and using multi stage builds * adservice: Changed install of glibc in builder to not require untrusted packages * adservice: Refactored Dockerfile to be a multi stage build. The 'build' step runs from openjdk:8-slim, but the final image is alpine based. We can get away from this since java runs in a vm & the architecture of the images doesn't change between biuld steps --- src/adservice/Dockerfile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/adservice/Dockerfile b/src/adservice/Dockerfile index 1095220..78b0452 100644 --- a/src/adservice/Dockerfile +++ b/src/adservice/Dockerfile @@ -1,16 +1,22 @@ -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-slim as builder + WORKDIR /app -# Next three steps are for caching dependency downloads -# to improve subsequent docker build. COPY ["build.gradle", "gradlew", "./"] COPY gradle gradle RUN ./gradlew downloadRepos COPY . . RUN ./gradlew installDist + +FROM openjdk:8-alpine + +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"]