diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..74a6af5c0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/.stack-work diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..338a2b2ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM debian:stable-slim as dev + +RUN apt-get update +RUN apt-get install -y curl libtinfo-dev +RUN (curl -sSL https://get.haskellstack.org/ | sh) +RUN mkdir /root/hledger +WORKDIR /root/hledger + +# Install GHC +COPY ./stack*.yaml ./ +RUN stack setup + +# Pre-cache dependencies +RUN mkdir hledger-lib hledger hledger-ui hledger-web hledger-api +COPY hledger-lib/package.yaml hledger-lib/package.yaml +COPY hledger/package.yaml hledger/package.yaml +COPY hledger-ui/package.yaml hledger-ui/package.yaml +COPY hledger-web/package.yaml hledger-web/package.yaml +COPY hledger-api/package.yaml hledger-api/package.yaml +RUN stack install --dependencies-only + +# Actually compile sources +COPY . . +RUN stack install + +FROM debian:stable-slim + +RUN apt-get update && apt-get install libgmp10 && rm -rf /var/lib/apt/lists + +COPY --from=dev /root/.local/bin/hledger* /usr/bin/ + +ENV LC_ALL C.UTF-8 + +RUN mkdir /data && touch /data/hledger.journal +VOLUME /data + +EXPOSE 5000 5001 + +COPY docker/start.sh /start.sh + +CMD ["/start.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..bef40454b --- /dev/null +++ b/docker/README.md @@ -0,0 +1,11 @@ +## Build instructions + +Build slim container with binaries only +``` +docker image build --rm --tag hledger . +``` + +Build container suitable for development +``` +docker image build --tag hledger --target dev . +``` diff --git a/docker/start.sh b/docker/start.sh new file mode 100755 index 000000000..3818a2726 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "host: ${HLEDGER_HOST:=0.0.0.0}" +echo "port: ${HLEDGER_PORT:=5000}" +echo "base url: ${HLEDGER_BASE_URL:="http://localhost:$HLEDGER_PORT"}" +echo "file url: ${HLEDGER_FILE_URL:=}" +echo "input file: ${HLEDGER_JOURNAL_FILE:=/data/hledger.journal}" +echo "debug level: ${HLEDGER_DEBUG:=1}" +echo "rules file: ${HLEDGER_RULES_FILE:=/data/hledger.rules}" + +exec hledger-web \ + --server \ + --host=$HLEDGER_HOST \ + --port=$HLEDGER_PORT \ + --file "$HLEDGER_JOURNAL_FILE" \ + --debug=$HLEDGER_DEBUG \ + --base-url=$HLEDGER_BASE_URL \ + --file-url=$HLEDGER_FILE_URL \ + --rules-file="$HLEDGER_RULES_FILE"