Skip to content

Commit 34cc253

Browse files
uniquestringdimitri
authored andcommitted
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
1 parent 5ca3ee8 commit 34cc253

File tree

3 files changed

+92
-41
lines changed

3 files changed

+92
-41
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.git
22
.vagrant
33
build
4+
Dockerfile
5+
Dockerfile.ccl

Dockerfile

+41-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
1-
FROM debian:stretch
2-
MAINTAINER Dimitri Fontaine <[email protected]>
1+
FROM debian:stable-slim as builder
32

4-
RUN apt-get update && \
5-
apt-get install -y --no-install-recommends \
6-
wget curl make git bzip2 time \
7-
ca-certificates \
8-
libzip-dev libssl1.1 openssl \
9-
patch unzip libsqlite3-dev gawk \
10-
freetds-dev sbcl && \
11-
rm -rf /var/lib/apt/lists/*
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends \
5+
bzip2 \
6+
ca-certificates \
7+
curl \
8+
freetds-dev \
9+
gawk \
10+
git \
11+
libsqlite3-dev \
12+
libssl1.1 \
13+
libzip-dev \
14+
make \
15+
openssl \
16+
patch \
17+
sbcl \
18+
time \
19+
unzip \
20+
wget \
21+
&& rm -rf /var/lib/apt/lists/*
1222

13-
ADD ./ /opt/src/pgloader
14-
WORKDIR /opt/src/pgloader
23+
COPY ./ /opt/src/pgloader
1524

16-
# build/ is in the .dockerignore file, but we actually need it now
17-
RUN mkdir -p build/bin
18-
RUN make
25+
RUN mkdir -p /opt/src/pgloader/build/bin \
26+
&& cd /opt/src/pgloader \
27+
&& make
1928

20-
RUN cp /opt/src/pgloader/build/bin/pgloader /usr/local/bin
29+
FROM debian:stable-slim
30+
31+
RUN apt-get update \
32+
&& apt-get install -y --no-install-recommends \
33+
curl \
34+
freetds-dev \
35+
gawk \
36+
libsqlite3-dev \
37+
libzip-dev \
38+
make \
39+
sbcl \
40+
unzip \
41+
&& rm -rf /var/lib/apt/lists/*
42+
43+
COPY --from=builder /opt/src/pgloader/build/bin/pgloader /usr/local/bin
44+
45+
LABEL maintainer="Dimitri Fontaine <[email protected]>"

Dockerfile.ccl

+49-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
1-
FROM debian:stretch
2-
MAINTAINER Dimitri Fontaine <[email protected]>
3-
4-
RUN apt-get update && \
5-
apt-get install -y --no-install-recommends \
6-
wget curl make git bzip2 time \
7-
ca-certificates \
8-
libzip-dev libssl1.1 openssl \
9-
patch unzip libsqlite3-dev gawk \
10-
freetds-dev sbcl && \
11-
rm -rf /var/lib/apt/lists/*
12-
13-
WORKDIR /usr/local/src
14-
RUN curl --location -O https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz
15-
RUN tar xf ccl-1.11.5-linuxx86.tar.gz
16-
RUN cp /usr/local/src/ccl/scripts/ccl64 /usr/local/bin/ccl
17-
18-
ADD ./ /opt/src/pgloader
19-
WORKDIR /opt/src/pgloader
20-
21-
# build/ is in the .dockerignore file, but we actually need it now
22-
RUN mkdir -p build/bin
23-
RUN make CL=ccl DYNSIZE=256
24-
25-
RUN cp /opt/src/pgloader/build/bin/pgloader /usr/local/bin
1+
FROM debian:stable-slim as builder
2+
3+
RUN apt-get update \
4+
&& apt-get install -y --no-install-recommends \
5+
bzip2 \
6+
ca-certificates \
7+
curl \
8+
freetds-dev \
9+
gawk \
10+
git \
11+
libsqlite3-dev \
12+
libssl1.1 \
13+
libzip-dev \
14+
make \
15+
openssl \
16+
patch \
17+
sbcl \
18+
time \
19+
unzip \
20+
wget \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
RUN curl -SL https://github.com/Clozure/ccl/releases/download/v1.11.5/ccl-1.11.5-linuxx86.tar.gz \
24+
| tar xz -C /usr/local/src/ \
25+
&& mv /usr/local/src/ccl/scripts/ccl64 /usr/local/bin/ccl
26+
27+
COPY ./ /opt/src/pgloader
28+
29+
RUN mkdir -p /opt/src/pgloader/build/bin \
30+
&& cd /opt/src/pgloader \
31+
&& make CL=ccl DYNSIZE=256
32+
33+
FROM debian:stable-slim
34+
35+
RUN apt-get update \
36+
&& apt-get install -y --no-install-recommends \
37+
curl \
38+
freetds-dev \
39+
gawk \
40+
libsqlite3-dev \
41+
libzip-dev \
42+
make \
43+
sbcl \
44+
unzip \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
COPY --from=builder /opt/src/pgloader/build/bin/pgloader /usr/local/bin
48+
49+
LABEL maintainer="Dimitri Fontaine <[email protected]>"

0 commit comments

Comments
 (0)