Skip to content

Commit

Permalink
Improved Dockerfiles/docker image size (dimitri#821)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
uniquestring authored and dimitri committed Aug 10, 2018
1 parent 5ca3ee8 commit 34cc253
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.git
.vagrant
build
Dockerfile
Dockerfile.ccl
57 changes: 41 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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>"
74 changes: 49 additions & 25 deletions Dockerfile.ccl
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
FROM debian:stretch
MAINTAINER Dimitri Fontaine <dim@tapoueh.org>

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/*

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

ADD ./ /opt/src/pgloader
WORKDIR /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 cp /opt/src/pgloader/build/bin/pgloader /usr/local/bin
FROM debian:stable-slim as builder

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/*

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

COPY ./ /opt/src/pgloader

RUN mkdir -p /opt/src/pgloader/build/bin \
&& cd /opt/src/pgloader \
&& make CL=ccl DYNSIZE=256

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>"

0 comments on commit 34cc253

Please sign in to comment.