Permalink
Browse files

Fix Docker build & use Alpine w/ multi-stage build

  • Loading branch information...
dahlia committed Feb 13, 2018
1 parent 4f63bef commit e05ee16595f5377cd4fb8a7a1d21eac5302cad1d
Showing with 64 additions and 27 deletions.
  1. +1 −0 .dockerignore
  2. +4 −1 CHANGES.md
  3. +36 −11 Dockerfile
  4. +23 −15 package.yaml
@@ -1,4 +1,5 @@
.git
.stack-work
dist
Dockerfile
*.hpc
@@ -96,7 +96,9 @@ To be released.
### Et cetera
- The Docker image now has `docker` command in `PATH`. [[#155]]
- The Docker image now has `nirum` command in `PATH`. [[#155]]
- The Docker image became based and built on [Alpine Linux][] so that
the image is now much lighter.
[#10]: https://github.com/spoqa/nirum/issues/10
[#38]: https://github.com/spoqa/nirum/issues/38
@@ -174,6 +176,7 @@ To be released.
[python-exception]: https://docs.python.org/3/library/exceptions.html#Exception
[targets.python]: ./target/python.md
[python-name-error]: https://docs.python.org/3/library/exceptions.html#NameError
[Alpine Linux]: https://alpinelinux.org/
Version 0.2.0
@@ -1,19 +1,44 @@
FROM haskell:8
MAINTAINER Minyoung Jeong <kkungkkung@gmail.com>
# To correctly make a statically-linked binary, we use Alpine Linux.
# The distro entirely uses musl instead of glibc which is unfriendly to be
# statically linked.
FROM alpine:3.7 AS build
WORKDIR /opt/nirum
RUN apk add --no-cache \
bash=4.4.19-r1 \
build-base=0.5-r0 \
curl=7.58.0-r0 \
ghc=8.0.2-r6 \
zlib-dev=1.2.11-r1
RUN curl -sSL https://get.haskellstack.org/ | bash
# Add just the .cabal file to capture dependencies
COPY ./package.yaml /opt/nirum/package.yaml
COPY ./stack.yaml /opt/nirum/stack.yaml
RUN stack config set system-ghc --global true
# Add just the package.yaml file to capture dependencies
COPY package.yaml /src/nirum/package.yaml
COPY stack.yaml /src/nirum/stack.yaml
WORKDIR /src/nirum
# Docker will cache this command as a layer, freeing us up to
# modify source code without re-installing dependencies
# (unless the .cabal file changes!)
RUN stack build --only-snapshot
RUN stack setup
RUN stack install --only-dependencies --test --no-run-tests
RUN stack build --only-snapshot --flag nirum:static
COPY . /src/nirum
RUN mkdir -p "/root/.local/bin"
RUN stack build --flag nirum:static --copy-bins
FROM alpine:3.7
RUN apk add --no-cache bash=4.4.19-r1
COPY . /opt/nirum
RUN stack build --copy-bins
RUN mkdir -p /bin
COPY --from=build /root/.local/bin/nirum /bin/
COPY --from=build /src/nirum/docker-entrypoint.sh /bin/
RUN chmod +x /bin/nirum /bin/docker-entrypoint.sh
ENV CMD=nirum
ENTRYPOINT ["./docker-entrypoint.sh"]
ENV CMD=/bin/nirum
ENTRYPOINT /bin/docker-entrypoint.sh
@@ -28,6 +28,11 @@ extra-source-files:
- README.md
default-extensions:
- OverloadedStrings
flags:
static:
description: Static link
manual: true
default: false
ghc-options:
- -Wall
- -Werror
@@ -69,23 +74,26 @@ executables:
nirum:
main: nirum.hs
source-dirs: app
ghc-options:
- -fwarn-incomplete-uni-patterns
- -threaded
- -with-rtsopts=-N
dependencies:
- nirum
nirum-static:
main: nirum.hs
source-dirs: app
ghc-options:
- -fwarn-incomplete-uni-patterns
- -threaded
- -with-rtsopts=-N
- -static
dependencies:
- base >=4.7 && <5
- nirum
when:
- condition: flag(static)
then:
ghc-options:
- -fwarn-incomplete-uni-patterns
- -threaded
- -with-rtsopts=-N
# Static link
- -static
- -optl-static
- -optl-pthread
- -optc-Os
- -fPIC
else:
ghc-options:
- -fwarn-incomplete-uni-patterns
- -threaded
- -with-rtsopts=-N
tests:
hlint:
main: HLint.hs

0 comments on commit e05ee16

Please sign in to comment.