Skip to content

Commit 4c97718

Browse files
authored
Merge pull request #184 from reitzig/patch-1
Utilize multi-stage build to improve the image size
2 parents d3de7ee + 8ca411c commit 4c97718

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

Dockerfile

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
FROM alpine:3.13
2-
3-
LABEL MAINTAINERS="Guillaume Scheibel <[email protected]>, Damien DUPORTAL <[email protected]>"
1+
FROM alpine:3.13 AS base
42

53
ARG asciidoctor_version=2.0.12
64
ARG asciidoctor_confluence_version=0.0.2
@@ -20,8 +18,42 @@ ENV ASCIIDOCTOR_VERSION=${asciidoctor_version} \
2018
ASCIIDOCTOR_MATHEMATICAL_VERSION=${asciidoctor_mathematical_version} \
2119
ASCIIDOCTOR_REVEALJS_VERSION=${asciidoctor_revealjs_version} \
2220
KRAMDOWN_ASCIIDOC_VERSION=${kramdown_asciidoc_version} \
23-
ASCIIDOCTOR_BIBTEX_VERSION=${asciidoctor_bibtex_version} \
24-
PATH="/root/.cabal/bin/:${PATH}"
21+
ASCIIDOCTOR_BIBTEX_VERSION=${asciidoctor_bibtex_version}
22+
23+
24+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
25+
# Haskell build for: erd
26+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
27+
28+
FROM base AS build-haskell
29+
RUN echo "building Haskell dependencies" # keep here to help --cache-from along
30+
31+
RUN apk add --no-cache \
32+
alpine-sdk \
33+
cabal \
34+
ghc-dev \
35+
ghc \
36+
gmp-dev \
37+
gnupg \
38+
libffi-dev \
39+
linux-headers \
40+
perl-utils \
41+
wget \
42+
xz \
43+
zlib-dev
44+
45+
RUN cabal v2-update \
46+
&& cabal v2-install erd
47+
48+
49+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
50+
# Final image
51+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
52+
53+
FROM base AS main
54+
RUN echo "building main image" # keep here to help --cache-from along
55+
56+
LABEL MAINTAINERS="Guillaume Scheibel <[email protected]>, Damien DUPORTAL <[email protected]>"
2557

2658
# Installing package required for the runtime of
2759
# any of the asciidoctor-* functionnalities
@@ -64,7 +96,6 @@ RUN apk add --no-cache --virtual .rubymakedepends \
6496
asciimath \
6597
"asciidoctor-pdf:${ASCIIDOCTOR_PDF_VERSION}" \
6698
"asciidoctor-revealjs:${ASCIIDOCTOR_REVEALJS_VERSION}" \
67-
bigdecimal \
6899
coderay \
69100
epubcheck-ruby:4.2.4.0 \
70101
haml \
@@ -91,23 +122,7 @@ RUN apk add --no-cache --virtual .pythonmakedepends \
91122
seqdiag \
92123
&& apk del -r --no-cache .pythonmakedepends
93124

94-
# ERD
95-
RUN apk add --no-cache --virtual .haskellmakedepends \
96-
alpine-sdk \
97-
cabal \
98-
ghc-dev \
99-
ghc \
100-
gmp-dev \
101-
gnupg \
102-
libffi-dev \
103-
linux-headers \
104-
perl-utils \
105-
wget \
106-
xz \
107-
zlib-dev \
108-
&& cabal v2-update \
109-
&& cabal v2-install erd \
110-
&& apk del -r --no-cache .haskellmakedepends
125+
COPY --from=build-haskell root/.cabal/bin/erd /bin/
111126

112127
WORKDIR /documents
113128
VOLUME /documents

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ all: build test README.md
3636

3737
build:
3838
docker build \
39+
--target build-haskell \
40+
--tag="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
41+
--build-arg BUILDKIT_INLINE_CACHE=1 \
42+
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
43+
--file=Dockerfile \
44+
$(CURDIR)/
45+
docker build \
46+
--target main \
3947
--tag="$(DOCKER_IMAGE_NAME_TO_TEST)" \
48+
--build-arg BUILDKIT_INLINE_CACHE=1 \
49+
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
50+
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)" \
4051
--file=Dockerfile \
4152
$(CURDIR)/
4253

0 commit comments

Comments
 (0)