Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: add generalized entity model for v2 search #530

Merged
merged 26 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2a28c90
feat: add generalized entity model for v2 search
adamdecaf Jan 4, 2024
9582e10
search/ofac: start parsing out remarks field, map to v2 generalized m…
adamdecaf Jan 4, 2024
8d81443
ofac: work out mapper for SDN -> Entity[SDN]
adamdecaf Jan 8, 2024
bdf548a
ofac: setup mapper for Aircraft and Vessels
adamdecaf Jan 12, 2024
1692849
feat: initial search endpoint
adamdecaf Mar 12, 2024
432fd23
search: add SourceID (to Entity) and AltNames (to Person)
adamdecaf Mar 12, 2024
b05cb47
feat: start on EU and US CSL mappers
adamdecaf Mar 12, 2024
1bbd9ac
meta: fix compile
adamdecaf Dec 17, 2024
62bf69b
ofac: finish implementing mapper
adamdecaf Dec 17, 2024
5785fe2
address: use libpostal to parse addresses
adamdecaf Dec 18, 2024
8af5585
search: fix test after adding Affiliations, SanctionsInfo, Historical…
adamdecaf Dec 18, 2024
28ed9f4
build: add install steps for libpostal and CI
adamdecaf Dec 18, 2024
e3c6637
build: remove watchmantest
adamdecaf Dec 18, 2024
0a4a74a
build: enable CGO once again
adamdecaf Dec 18, 2024
6af891b
docs: minor readme tweaks
adamdecaf Dec 18, 2024
03a3d5b
build: installing libpostal in docker images
adamdecaf Dec 18, 2024
246c8af
build: get libpostal working in docker images
adamdecaf Dec 18, 2024
2175b0e
build: remove batchsearch, finish libpostal setup
adamdecaf Dec 18, 2024
5bfb82d
build: optimize Dockerfiles for builder cache
adamdecaf Dec 18, 2024
8faae78
ofac: correct input for v2 address parsing
adamdecaf Dec 18, 2024
bbfba4d
cmd/server: wire up basic /v2/search
adamdecaf Dec 18, 2024
a975289
fix: add build tag when libpostal is linked / available
adamdecaf Dec 19, 2024
e024efc
build: remove "make install" from CI steps
adamdecaf Dec 19, 2024
d1aa810
meta: remove outdated file [skip ci]
adamdecaf Dec 19, 2024
a093b3f
address: only run libpostal tests with the build tag provided
adamdecaf Dec 19, 2024
4caee01
meta: ignore printf for now
adamdecaf Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .codecov.yml

This file was deleted.

1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libpostal/
27 changes: 0 additions & 27 deletions .github/workflows/examples.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,3 @@ jobs:
- name: Docker Build
if: runner.os == 'Linux'
run: make docker-hub

- name: Build batchsearch
if: runner.os == 'Linux'
run: make build-batchsearch

# - name: Integration Test
# if: runner.os == 'Linux'
# run: make test-integration

- name: Test Cleanup
if: runner.os == 'Linux' && always()
run: |
docker compose logs
make clean-integration
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ jobs:
- name: Docker Static
run: make docker-static

- name: Docker watchmantest
run: make docker-watchmantest

- name: Docker Push
run: |+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ openapi-generator*jar

*.db

/libpostal/

webui/build/
webui/node_modules/

Expand Down
72 changes: 63 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,79 @@
FROM golang:alpine as backend
# Backend build stage
FROM golang:1.23-bookworm as backend
ARG VERSION
WORKDIR /src
COPY . /src

# Install system dependencies first
RUN apt-get update && apt-get install -y \
curl \
autoconf \
automake \
libtool \
pkg-config \
git

# Clone and build libpostal (rarely changes)
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 (rarely changes)
RUN libpostal_data download all /usr/local/share/libpostal

# Copy go.mod and go.sum first to cache dependencies
COPY go.mod go.sum /src/
RUN go mod download
RUN CGO_ENABLED=0 go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/server /src/cmd/server

FROM node:21-alpine as frontend
# Now copy the rest of the source code (frequently changes)
COPY . /src/
WORKDIR /src
RUN VERSION=${VERSION} GOTAGS="-tags libpostal" make build-server

# Frontend build stage
FROM node:22-bookworm as frontend
ARG VERSION
COPY webui/ /watchman/
WORKDIR /watchman/

# Copy package files first to cache dependencies
COPY webui/package*.json webui/
WORKDIR /watchman/webui/
RUN npm install --legacy-peer-deps

# Copy and build frontend source (frequently changes)
COPY webui/ ./
RUN npm run build

FROM alpine:latest
# Final stage
FROM debian:bookworm
LABEL maintainer="Moov <[email protected]>"

# Install runtime dependencies
RUN apt-get update && \
apt-get install -y \
libssl3 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Create necessary directories and copy libpostal files
RUN mkdir -p /usr/local/share/libpostal
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/
RUN ldconfig

# Copy application files
COPY --from=backend /src/bin/server /bin/server
COPY --from=frontend /watchman/build/ /watchman/
ENV WEB_ROOT=/watchman/
COPY --from=frontend /watchman/webui/build/ /watchman/

# Set environment variables
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"]
93 changes: 84 additions & 9 deletions Dockerfile-openshift
Original file line number Diff line number Diff line change
@@ -1,28 +1,103 @@
FROM quay.io/fedora/fedora:40-x86_64 as builder
# Stage 1: Install dependencies with root privileges
FROM registry.access.redhat.com/ubi9/go-toolset as builder-deps
USER root

# Install system dependencies first - rarely changes
RUN dnf install -y --allowerasing --setopt=tsflags=nodocs \
curl \
autoconf \
automake \
libtool \
pkgconfig \
gcc \
gcc-c++ \
make \
git \
&& dnf clean all

# Install libpostal with models - rarely changes
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

# Download libpostal data - separate step for better caching
RUN cd libpostal/src && \
PATH=$PATH:/usr/local/bin ./libpostal_data download all /usr/local/share/libpostal

# Set permissions - should be last in this stage
RUN 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
RUN yum install -y git golang make npm wget glibc
WORKDIR /opt/app-root/src/
COPY . .

# Copy only the necessary files from builder-deps
COPY --from=builder-deps /usr/local /usr/local
COPY --from=builder-deps /usr/lib64 /usr/lib64

# Set environment variables for build
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
ENV LD_LIBRARY_PATH=/usr/local/lib

# Copy go.mod and go.sum first to cache dependencies
COPY go.mod go.sum ./
RUN go mod download
RUN VERSION=${VERSION} make build-server

# Copy source files
COPY . .

# Create bin directory and set permissions BEFORE building
USER root
RUN mkdir -p bin && \
chown -R 1001:0 . && \
chmod -R g=u .

USER 1001
RUN VERSION=${VERSION} GOTAGS="-tags libpostal" make build-server

# Stage 3: Frontend build
FROM node:21-bookworm as frontend
COPY webui/ /watchman/
WORKDIR /watchman/

# Copy package files first to cache dependencies
COPY webui/package*.json ./
RUN npm install --legacy-peer-deps
RUN npm run build

FROM quay.io/fedora/fedora:40-x86_64
RUN yum install -y glibc
# Copy frontend source and build - frequently changes
COPY webui/ ./
RUN npm run build

# Stage 4: Final stage
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5-1733767867
ARG VERSION=unknown
LABEL maintainer="Moov <[email protected]>"
LABEL name="watchman"
LABEL version=$VERSION

COPY --from=builder /opt/app-root/src/bin/server /bin/server
# 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 and switch to non-root user
RUN chown -R 1001:0 /bin/server /watchman && \
chmod -R g=u /bin/server /watchman
USER 1001

ENTRYPOINT ["/bin/server"]
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,11 @@ By design, Watchman **does not persist** (save) any data about the search queri

### Go library

This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/moov-io/watchman/releases/latest) as well. We highly recommend you use a tagged release for production.

```
$ [email protected]:moov-io/watchman.git

# Pull down into the Go Module cache
$ go get -u github.com/moov-io/watchman

$ go doc github.com/moov-io/watchman/client Search
```
Watchman offers [several packages for usage as libraries](https://pkg.go.dev/github.com/moov-io/watchman/pkg).

### In-browser Watchman search

Using our [in-browser utility](https://oss.moov.io/watchman/), you can instantly perform advanced Watchman searches. Simply fill search fields and generate a detailed report that includes match percentage, alternative names, effective/expiration dates, IDs, addresses, and other useful information. This tool is particularly useful for completing quick searches with the aid of a intuitive interface.
Using the [WebUI](https://moov-io.github.io/watchman/webui/), you can instantly perform advanced OFAC Watchman searches. Simply fill search fields and generate a detailed report that includes match percentage, alternative names, effective/expiration dates, IDs, addresses, and other useful information. This tool is particularly useful for completing quick searches with the aid of a intuitive interface.

## Reporting blocks to OFAC

Expand Down Expand Up @@ -309,7 +300,7 @@ Note: 32-bit platforms have known issues and are not supported.

Yes please! Please review our [Contributing guide](CONTRIBUTING.md) and [Code of Conduct](https://github.com/moov-io/ach/blob/master/CODE_OF_CONDUCT.md) to get started! Checkout our [issues for first time contributors](https://github.com/moov-io/watchman/contribute) for something to help out with.

This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/moov-io/watchman/releases/latest) as well. We highly recommend you use a tagged release for production.
Run `make install` to setup [gopostal](https://github.com/openvenues/gopostal) / [libpostal](https://github.com/openvenues/libpostal) for Watchman.

### Releasing

Expand Down
19 changes: 0 additions & 19 deletions cmd/batchsearch/README.md

This file was deleted.

Loading
Loading