Skip to content

Commit

Permalink
build: get libpostal working in docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Dec 18, 2024
1 parent 03a3d5b commit 246c8af
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 5 deletions.
43 changes: 39 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
46 changes: 45 additions & 1 deletion Dockerfile-openshift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

0 comments on commit 246c8af

Please sign in to comment.