-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (68 loc) · 1.91 KB
/
Dockerfile
File metadata and controls
86 lines (68 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Multi-stage build for hledger-api
# Stage 1: Build the application
FROM debian:bookworm-slim AS builder
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
bash \
ca-certificates \
curl \
gcc \
g++ \
gnupg \
pkg-config \
libc6-dev \
libffi-dev \
libgmp-dev \
liblzma-dev \
libnuma-dev \
libtinfo-dev \
netbase \
zlib1g-dev \
make \
xz-utils \
git && \
rm -rf /var/lib/apt/lists/*
# Install Stack
RUN curl -sSL https://get.haskellstack.org/ | bash
# Set working directory
WORKDIR /build
# Copy stack configuration files first (better layer caching)
COPY stack.yaml stack.yaml.lock package.yaml ./
# Let Stack handle GHC installation
RUN stack setup
# Download dependencies
RUN stack build --only-dependencies
# Copy source code
COPY . .
# Build with optimizations
RUN stack build \
--ghc-options='-O2' \
--copy-bins \
--local-bin-path /build/bin
# Strip debug symbols to reduce binary size
RUN strip /build/bin/hledger-api-exe
# Stage 2: Minimal runtime image
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
libgmp10 \
libtinfo6 \
libffi8 \
libnuma1 && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /build/bin/hledger-api-exe /usr/local/bin/hledger-api
# Set working directory and ensure it's owned by nobody
WORKDIR /data
RUN chown nobody:nogroup /data
# Run as nobody user (UID 65534)
USER nobody
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
LEDGER_FILE=/data/ledger.journal
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD timeout 2 bash -c "</dev/tcp/localhost/8080" || exit 1
ENTRYPOINT ["/usr/local/bin/hledger-api"]
CMD ["--port", "8080", "--host", "0.0.0.0"]