-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (61 loc) · 2.46 KB
/
Dockerfile
File metadata and controls
76 lines (61 loc) · 2.46 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
# ==========================================
# Stage 1: Builder
# ==========================================
FROM golang:1.26-trixie AS builder
# args
ARG TARGETARCH
ARG BUILD_VERSION=
ARG BUILD_GIT_COMMIT=
# Install packages needed to build gems
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
build-essential \
curl \
autoconf \
automake \
libtool \
pkg-config \
git \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Clone, build, and install libpostal
RUN git clone https://github.com/openvenues/libpostal /code/libpostal
WORKDIR /code/libpostal
RUN ./bootstrap.sh && \
./configure --datadir=/usr/share/libpostal $([ "$TARGETARCH" = "arm64" ] && echo "--disable-sse2" || echo "") && \
make -j4 && make check && make install && \
ldconfig
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies.
# This allows the container build to reuse cached dependencies.
# Expecting to copy go.mod and if present go.sum.
COPY go.* ./
RUN go mod download
# Copy local code to the container image.
COPY . ./
# Build the binary.
ENV CGO_ENABLED=1
RUN go build -trimpath -ldflags="-s -w -X github.com/le0pard/postal_server/version.Version=$BUILD_VERSION -X github.com/le0pard/postal_server/version.GitCommit=$BUILD_GIT_COMMIT -X github.com/le0pard/postal_server/version.BuildTime=$(TZ=UTC date +"%Y-%m-%dT%H:%M:%S%z")" -v -o postal_server
# ==========================================
# Stage 2: Final Runtime
# ==========================================
# Use a slim debian image that matches the builder's OS (trixie) to avoid glibc version mismatches
FROM debian:trixie-slim
ARG GIN_MODE=release
ENV GIN_MODE=${GIN_MODE}
# Install minimal runtime dependencies (ca-certificates for external API calls if any, curl for healthchecks)
RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy the compiled libpostal shared libraries from the builder
COPY --from=builder /usr/local/lib/libpostal.so* /usr/local/lib/
# Copy the downloaded libpostal machine learning data models
COPY --from=builder /usr/share/libpostal /usr/share/libpostal
# Update dynamic linker run-time bindings so the OS knows where libpostal.so is
RUN ldconfig
# Copy the compiled Go binary from the builder
WORKDIR /app
COPY --from=builder /app/postal_server /app/postal_server
EXPOSE 8000
# Run the web service on container startup.
CMD ["/app/postal_server"]