Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize multi-stage build to improve the image size #184

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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