-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.alpine
More file actions
102 lines (83 loc) · 3.22 KB
/
Copy pathDockerfile.alpine
File metadata and controls
102 lines (83 loc) · 3.22 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# syntax=docker/dockerfile:1
# ==============================================================================
# Stage 1: Builder
# ==============================================================================
FROM alpine:latest AS builder
ARG LIBPOSTAL_REPO="https://github.com/openvenues/libpostal.git"
ARG LIBPOSTAL_COMMIT="master"
ARG LIBPOSTAL_REST_REPO="https://github.com/rezaghazeli/libpostal-rest.git"
ARG LIBPOSTAL_REST_COMMIT="master"
# Install build dependencies
RUN set -ex \
&& apk add --no-cache \
curl \
git \
gcc \
g++ \
make \
libtool \
autoconf \
automake \
pkgconf \
binutils \
go
WORKDIR /src
# 1. Build libpostal and generate BOTH downloader scripts
# We run configure twice to generate the different data scripts
RUN set -ex \
&& git clone "$LIBPOSTAL_REPO" . \
&& git checkout "$LIBPOSTAL_COMMIT" \
&& ./bootstrap.sh \
# Generate Default Downloader
&& ./configure --prefix=/usr --datadir=/data --disable-data-download \
&& cp src/libpostal_data /tmp/libpostal_data_default \
# Generate Senzing Downloader
&& ./configure --prefix=/usr --datadir=/data --disable-data-download MODEL=senzing \
&& cp src/libpostal_data /tmp/libpostal_data_senzing \
# Build and Install (using the last configuration, which is fine as the library code is same)
&& make -j "$(nproc)" \
&& make install \
&& strip /usr/lib/libpostal.so*
# 2. Build libpostal-rest (Go binary)
WORKDIR /go/src/libpostal-rest
RUN set -ex \
&& git clone "$LIBPOSTAL_REST_REPO" . \
&& git checkout "$LIBPOSTAL_REST_COMMIT" \
&& CGO_ENABLED=1 go build -ldflags="-s -w" -o /usr/bin/libpostal-rest .
# ==============================================================================
# Stage 2: Base Image (Libpostal Only)
# ==============================================================================
FROM alpine:latest AS base
LABEL maintainer="rezaghazeli"
# Runtime dependencies
RUN set -ex \
&& apk add --no-cache \
curl
# Create data directory
WORKDIR /data
# Copy libpostal libraries and headers
COPY --from=builder /usr/lib/libpostal.so* /usr/lib/
COPY --from=builder /usr/lib/libpostal.a /usr/lib/
COPY --from=builder /usr/lib/libpostal.la /usr/lib/
COPY --from=builder /usr/include/libpostal /usr/include/libpostal
COPY --from=builder /usr/lib/pkgconfig/libpostal.pc /usr/lib/pkgconfig/libpostal.pc
# Copy BOTH data downloader scripts
COPY --from=builder /tmp/libpostal_data_default /usr/local/bin/libpostal_data_default
COPY --from=builder /tmp/libpostal_data_senzing /usr/local/bin/libpostal_data_senzing
# Copy entrypoint script
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# Environment variables
ENV LD_LIBRARY_PATH=/usr/lib
ENTRYPOINT ["entrypoint.sh"]
# Default command for base image is just a shell or help
CMD ["/bin/sh"]
# ==============================================================================
# Stage 3: REST Image (Libpostal + REST API)
# ==============================================================================
FROM base AS rest
# Copy libpostal-rest binary
COPY --from=builder /usr/bin/libpostal-rest /usr/bin/libpostal-rest
# Expose the REST API port
EXPOSE 8080 9090
CMD ["libpostal-rest"]