-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: get libpostal working in docker images
- Loading branch information
Showing
2 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,22 @@ ARG VERSION | |
WORKDIR /src | ||
COPY . /src | ||
RUN go mod download | ||
RUN apt-get update && apt-get install -y curl autoconf automake libtool pkg-config | ||
RUN make install | ||
RUN apt-get update && apt-get install -y curl autoconf automake libtool pkg-config git | ||
|
||
# Clone and install libpostal | ||
RUN git clone https://github.com/openvenues/libpostal.git /src/libpostal | ||
WORKDIR /src/libpostal | ||
RUN ./bootstrap.sh && \ | ||
./configure && \ | ||
make -j$(shell nproc) && \ | ||
make install && \ | ||
ldconfig | ||
|
||
# Download libpostal data files | ||
RUN libpostal_data download all /usr/local/share/libpostal | ||
|
||
# Build the application | ||
WORKDIR /src | ||
RUN go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/server /src/cmd/server | ||
|
||
FROM node:22-bookworm as frontend | ||
|
@@ -16,12 +30,33 @@ RUN npm run build | |
|
||
FROM debian:bookworm | ||
LABEL maintainer="Moov <[email protected]>" | ||
|
||
# Install required runtime dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
libssl3 \ | ||
ca-certificates \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Create necessary directories | ||
RUN mkdir -p /usr/local/share/libpostal | ||
|
||
# Copy libpostal shared libraries and configuration | ||
COPY --from=backend /usr/local/lib/libpostal.so* /usr/local/lib/ | ||
COPY --from=backend /usr/local/lib/pkgconfig/libpostal.pc /usr/local/lib/pkgconfig/ | ||
COPY --from=backend /usr/local/share/libpostal/ /usr/local/share/libpostal/ | ||
|
||
# Update shared library cache | ||
RUN ldconfig | ||
|
||
# Copy application files | ||
COPY --from=backend /src/bin/server /bin/server | ||
COPY --from=frontend /watchman/build/ /watchman/ | ||
ENV WEB_ROOT=/watchman/ | ||
|
||
ENV WEB_ROOT=/watchman/ | ||
ENV LD_LIBRARY_PATH=/usr/local/lib | ||
ENV LIBPOSTAL_DATA_DIR=/usr/local/share/libpostal | ||
|
||
EXPOSE 8084 | ||
EXPOSE 9094 | ||
|
||
ENTRYPOINT ["/bin/server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,42 @@ RUN dnf install -y --allowerasing --setopt=tsflags=nodocs \ | |
automake \ | ||
libtool \ | ||
pkgconfig \ | ||
gcc \ | ||
gcc-c++ \ | ||
make \ | ||
git \ | ||
&& dnf clean all | ||
|
||
# Install libpostal with models - Fixed path handling | ||
RUN git clone https://github.com/openvenues/libpostal \ | ||
&& cd libpostal \ | ||
&& ./bootstrap.sh \ | ||
&& ./configure --prefix=/usr/local \ | ||
&& make -j4 \ | ||
&& make install \ | ||
&& mkdir -p /usr/local/share/libpostal \ | ||
&& cd src \ | ||
&& PATH=$PATH:/usr/local/bin ./libpostal_data download all /usr/local/share/libpostal \ | ||
&& chown -R 1001:0 /usr/local \ | ||
&& chmod -R g=u /usr/local | ||
|
||
# Stage 2: Build the application | ||
FROM registry.access.redhat.com/ubi9/go-toolset as builder | ||
ARG VERSION | ||
WORKDIR /opt/app-root/src/ | ||
|
||
# Copy the entire /usr and /usr/local directories | ||
COPY --from=builder-deps /usr /usr | ||
COPY --from=builder-deps /usr/local /usr/local | ||
|
||
# Set environment variables for build | ||
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig | ||
ENV LD_LIBRARY_PATH=/usr/local/lib | ||
|
||
# Copy source and build | ||
COPY . . | ||
RUN go mod download | ||
RUN make install | ||
USER 1001 | ||
RUN VERSION=${VERSION} make build-server | ||
|
||
# Stage 3: Frontend build | ||
|
@@ -32,7 +58,25 @@ ARG VERSION=unknown | |
LABEL maintainer="Moov <[email protected]>" | ||
LABEL name="watchman" | ||
LABEL version=$VERSION | ||
|
||
# Install runtime dependencies | ||
USER root | ||
RUN microdnf install -y \ | ||
libstdc++ \ | ||
&& microdnf clean all | ||
|
||
# Copy libpostal files and setup | ||
COPY --from=builder-deps /usr/local /usr/local | ||
ENV LD_LIBRARY_PATH=/usr/local/lib | ||
|
||
# Copy application files | ||
COPY --from=builder /opt/app-root/src/bin/server /bin/server | ||
COPY --from=frontend /watchman/build/ /watchman/ | ||
ENV WEB_ROOT=/watchman/ | ||
|
||
# Set final permissions | ||
RUN chown -R 1001:0 /bin/server /watchman \ | ||
&& chmod -R g=u /bin/server /watchman | ||
|
||
USER 1001 | ||
ENTRYPOINT ["/bin/server"] |