Improved static linux alpine build.

* Use -split-objs (reduces executable size from ~50M to 32M), at
  cost of much slower compilation.
* Moved building of prereqs from CMD to RUN, so they can be cached.
  Doing 'make build' will fetch the latest from git and rebuild
  pandoc, but dependencies needn't be rebuilt.
This commit is contained in:
John MacFarlane 2017-03-17 16:02:49 +01:00
parent 63c96f8b91
commit 037af1b95b

View file

@ -9,10 +9,13 @@ RUN apk update
RUN apk add alpine-sdk git ca-certificates ghc cabal stack zlib-dev
RUN stack update
RUN stack config set system-ghc --global true
ADD ./ /usr/src/
RUN mkdir -p /etc/stack
RUN echo "build: { split-objs: true }" > /etc/stack/config.yaml
RUN mkdir -p /usr/src/
WORKDIR /usr/src/
RUN git clone https://github.com/jgm/pandoc
WORKDIR /usr/src/pandoc
RUN stack install --local-bin-path /usr/bin hsb2hs
RUN stack install --only-dependencies --flag 'pandoc:embed_data_files' --test --ghc-options '-O2 -optc-Os -optl-static -fPIC'
CMD git pull
CMD stack install --local-bin-path /usr/bin hsb2hs
CMD stack install --local-bin-path /artifacts --flag 'pandoc:embed_data_files' --test --ghc-options '-optl-static -fPIC'
CMD stack install --local-bin-path /artifacts --flag 'pandoc:embed_data_files' --test --ghc-options '-O2 -optc-Os -optl-static -fPIC'