From 34cc25383ac3729c9c7ebcd06ab068ee24ae55f4 Mon Sep 17 00:00:00 2001 From: uniquestring <36343026+uniquestring@users.noreply.github.com> Date: Sat, 11 Aug 2018 01:08:00 +0200 Subject: [PATCH] Improved Dockerfiles/docker image size (#821) * Add dockerfiles to .dockerignore Otherwise changes in the dockerfiles would invalidate the cache * Rewrite Dockerfile - Fix deprecated MAINTAINER instruction - Move maintainer label to the bottom (improving cache) - Tidy up apt-get - Use COPY instead of ADD see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy - Remove WORKDIR instruction (we don't really need this) - Combine remaining RUN layers to reduce layer count - Move final binary instead of copying (reduce image size) * Use -slim image an multistage build Reduce size by using multistage builds and the -slim image. Use debian:stable instead of an specific code name (future proof). * [cosmetic] indent Dockerfile instructions Make it easier to see where a new build stage begins * Rewrite Dockerfile.ccl Apply the same changes to Dockerfile.ccl as we did for Dockerfile --- .dockerignore | 2 ++ Dockerfile | 57 +++++++++++++++++++++++++++++++------------- Dockerfile.ccl | 64 ++++++++++++++++++++++++++++++++++---------------- 3 files changed, 87 insertions(+), 36 deletions(-) diff --git a/.dockerignore b/.dockerignore index d075b3e..6be6907 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ .git .vagrant build +Dockerfile +Dockerfile.ccl \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 6fc43dc..0500aa2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,45 @@ -FROM debian:stretch -MAINTAINER Dimitri Fontaine +FROM debian:stable-slim as builder -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - wget curl make git bzip2 time \ - ca-certificates \ - libzip-dev libssl1.1 openssl \ - patch unzip libsqlite3-dev gawk \ - freetds-dev sbcl && \ - rm -rf /var/lib/apt/lists/* + RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + bzip2 \ + ca-certificates \ + curl \ + freetds-dev \ + gawk \ + git \ + libsqlite3-dev \ + libssl1.1 \ + libzip-dev \ + make \ + openssl \ + patch \ + sbcl \ + time \ + unzip \ + wget \ + && rm -rf /var/lib/apt/lists/* -ADD ./ /opt/src/pgloader -WORKDIR /opt/src/pgloader + COPY ./ /opt/src/pgloader -# build/ is in the .dockerignore file, but we actually need it now -RUN mkdir -p build/bin -RUN make + RUN mkdir -p /opt/src/pgloader/build/bin \ + && cd /opt/src/pgloader \ + && make -RUN cp /opt/src/pgloader/build/bin/pgloader /usr/local/bin +FROM debian:stable-slim + + RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl \ + freetds-dev \ + gawk \ + libsqlite3-dev \ + libzip-dev \ + make \ + sbcl \ + unzip \ + && rm -rf /var/lib/apt/lists/* + + COPY --from=builder /opt/src/pgloader/build/bin/pgloader /usr/local/bin + + LABEL maintainer="Dimitri Fontaine " \ No newline at end of file diff --git a/Dockerfile.ccl b/Dockerfile.ccl index a33f8c9..f88468a 100644 --- a/Dockerfile.ccl +++ b/Dockerfile.ccl @@ -1,25 +1,49 @@ -FROM debian:stretch -MAINTAINER Dimitri Fontaine +FROM debian:stable-slim as builder -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - wget curl make git bzip2 time \ - ca-certificates \ - libzip-dev libssl1.1 openssl \ - patch unzip libsqlite3-dev gawk \ - freetds-dev sbcl && \ - rm -rf /var/lib/apt/lists/* + RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + bzip2 \ + ca-certificates \ + curl \ + freetds-dev \ + gawk \ + git \ + libsqlite3-dev \ + libssl1.1 \ + libzip-dev \ + make \ + openssl \ + patch \ + sbcl \ + time \ + unzip \ + wget \ + && rm -rf /var/lib/apt/lists/* -WORKDIR /usr/local/src -RUN curl --location -O https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz -RUN tar xf ccl-1.11.5-linuxx86.tar.gz -RUN cp /usr/local/src/ccl/scripts/ccl64 /usr/local/bin/ccl + RUN curl -SL https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz \ + | tar xz -C /usr/local/src/ \ + && mv /usr/local/src/ccl/scripts/ccl64 /usr/local/bin/ccl -ADD ./ /opt/src/pgloader -WORKDIR /opt/src/pgloader + COPY ./ /opt/src/pgloader -# build/ is in the .dockerignore file, but we actually need it now -RUN mkdir -p build/bin -RUN make CL=ccl DYNSIZE=256 + RUN mkdir -p /opt/src/pgloader/build/bin \ + && cd /opt/src/pgloader \ + && make CL=ccl DYNSIZE=256 -RUN cp /opt/src/pgloader/build/bin/pgloader /usr/local/bin +FROM debian:stable-slim + + RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl \ + freetds-dev \ + gawk \ + libsqlite3-dev \ + libzip-dev \ + make \ + sbcl \ + unzip \ + && rm -rf /var/lib/apt/lists/* + + COPY --from=builder /opt/src/pgloader/build/bin/pgloader /usr/local/bin + + LABEL maintainer="Dimitri Fontaine " \ No newline at end of file