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
This commit is contained in:
uniquestring 2018-08-11 01:08:00 +02:00 committed by Dimitri Fontaine
parent 5ca3ee8aad
commit 34cc25383a
3 changed files with 87 additions and 36 deletions

View File

@ -1,3 +1,5 @@
.git
.vagrant
build
Dockerfile
Dockerfile.ccl

View File

@ -1,20 +1,45 @@
FROM debian:stretch
MAINTAINER Dimitri Fontaine <dim@tapoueh.org>
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 <dim@tapoueh.org>"

View File

@ -1,25 +1,49 @@
FROM debian:stretch
MAINTAINER Dimitri Fontaine <dim@tapoueh.org>
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 <dim@tapoueh.org>"