diff --git a/Dockerfile b/Dockerfile index 8b67e0aa..0f45a3e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 " + +# 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"] diff --git a/Dockerfile-openshift b/Dockerfile-openshift index 76e8dc9b..ff425674 100644 --- a/Dockerfile-openshift +++ b/Dockerfile-openshift @@ -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 " 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"]