Skip to content

Commit

Permalink
Merge pull request #184 from reitzig/patch-1
Browse files Browse the repository at this point in the history
Utilize multi-stage build to improve the image size
  • Loading branch information
dduportal authored Mar 1, 2021
2 parents d3de7ee + 8ca411c commit 4c97718
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
61 changes: 38 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FROM alpine:3.13

LABEL MAINTAINERS="Guillaume Scheibel <[email protected]>, Damien DUPORTAL <[email protected]>"
FROM alpine:3.13 AS base

ARG asciidoctor_version=2.0.12
ARG asciidoctor_confluence_version=0.0.2
Expand All @@ -20,8 +18,42 @@ ENV ASCIIDOCTOR_VERSION=${asciidoctor_version} \
ASCIIDOCTOR_MATHEMATICAL_VERSION=${asciidoctor_mathematical_version} \
ASCIIDOCTOR_REVEALJS_VERSION=${asciidoctor_revealjs_version} \
KRAMDOWN_ASCIIDOC_VERSION=${kramdown_asciidoc_version} \
ASCIIDOCTOR_BIBTEX_VERSION=${asciidoctor_bibtex_version} \
PATH="/root/.cabal/bin/:${PATH}"
ASCIIDOCTOR_BIBTEX_VERSION=${asciidoctor_bibtex_version}


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Haskell build for: erd
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

FROM base AS build-haskell
RUN echo "building Haskell dependencies" # keep here to help --cache-from along

RUN apk add --no-cache \
alpine-sdk \
cabal \
ghc-dev \
ghc \
gmp-dev \
gnupg \
libffi-dev \
linux-headers \
perl-utils \
wget \
xz \
zlib-dev

RUN cabal v2-update \
&& cabal v2-install erd


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Final image
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

FROM base AS main
RUN echo "building main image" # keep here to help --cache-from along

LABEL MAINTAINERS="Guillaume Scheibel <[email protected]>, Damien DUPORTAL <[email protected]>"

# Installing package required for the runtime of
# any of the asciidoctor-* functionnalities
Expand Down Expand Up @@ -64,7 +96,6 @@ RUN apk add --no-cache --virtual .rubymakedepends \
asciimath \
"asciidoctor-pdf:${ASCIIDOCTOR_PDF_VERSION}" \
"asciidoctor-revealjs:${ASCIIDOCTOR_REVEALJS_VERSION}" \
bigdecimal \
coderay \
epubcheck-ruby:4.2.4.0 \
haml \
Expand All @@ -91,23 +122,7 @@ RUN apk add --no-cache --virtual .pythonmakedepends \
seqdiag \
&& apk del -r --no-cache .pythonmakedepends

# ERD
RUN apk add --no-cache --virtual .haskellmakedepends \
alpine-sdk \
cabal \
ghc-dev \
ghc \
gmp-dev \
gnupg \
libffi-dev \
linux-headers \
perl-utils \
wget \
xz \
zlib-dev \
&& cabal v2-update \
&& cabal v2-install erd \
&& apk del -r --no-cache .haskellmakedepends
COPY --from=build-haskell root/.cabal/bin/erd /bin/

WORKDIR /documents
VOLUME /documents
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ all: build test README.md

build:
docker build \
--target build-haskell \
--tag="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
--file=Dockerfile \
$(CURDIR)/
docker build \
--target main \
--tag="$(DOCKER_IMAGE_NAME_TO_TEST)" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)-build-haskell" \
--cache-from="$(DOCKER_IMAGE_NAME_TO_TEST)" \
--file=Dockerfile \
$(CURDIR)/

Expand Down

0 comments on commit 4c97718

Please sign in to comment.