From 03a3d5b8f63283eba0e364cab18e7be8cb5b35b3 Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 18 Dec 2024 12:30:24 -0600 Subject: [PATCH] build: installing libpostal in docker images --- .dockerignore | 1 + Dockerfile | 10 ++++++---- Dockerfile-openshift | 26 ++++++++++++++++++-------- README.md | 2 +- makefile | 7 ++++--- 5 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..82c4e456 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +libpostal/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0484a8dd..8b67e0aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,20 @@ -FROM golang:alpine as backend +FROM golang:1.23-bookworm as backend ARG VERSION WORKDIR /src COPY . /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 +RUN apt-get update && apt-get install -y curl autoconf automake libtool pkg-config +RUN make install +RUN go build -ldflags "-X github.com/moov-io/watchman.Version=${VERSION}" -o ./bin/server /src/cmd/server -FROM node:21-alpine as frontend +FROM node:22-bookworm as frontend ARG VERSION COPY webui/ /watchman/ WORKDIR /watchman/ RUN npm install --legacy-peer-deps RUN npm run build -FROM alpine:latest +FROM debian:bookworm LABEL maintainer="Moov " COPY --from=backend /src/bin/server /bin/server COPY --from=frontend /watchman/build/ /watchman/ diff --git a/Dockerfile-openshift b/Dockerfile-openshift index b48cf01c..76e8dc9b 100644 --- a/Dockerfile-openshift +++ b/Dockerfile-openshift @@ -1,28 +1,38 @@ -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 +RUN dnf install -y --allowerasing --setopt=tsflags=nodocs \ + curl \ + autoconf \ + automake \ + libtool \ + pkgconfig \ + && dnf clean all + +# 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 --from=builder-deps /usr /usr COPY . . RUN go mod download +RUN make install RUN VERSION=${VERSION} make build-server +# Stage 3: Frontend build FROM node:21-bookworm as frontend COPY webui/ /watchman/ WORKDIR /watchman/ RUN npm install --legacy-peer-deps RUN npm run build -FROM quay.io/fedora/fedora:40-x86_64 -RUN yum install -y glibc - +# Stage 4: Final stage +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5-1733767867 ARG VERSION=unknown LABEL maintainer="Moov " LABEL name="watchman" LABEL version=$VERSION - COPY --from=builder /opt/app-root/src/bin/server /bin/server - COPY --from=frontend /watchman/build/ /watchman/ ENV WEB_ROOT=/watchman/ - ENTRYPOINT ["/bin/server"] diff --git a/README.md b/README.md index 2d4f12f9..51563867 100644 --- a/README.md +++ b/README.md @@ -300,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 diff --git a/makefile b/makefile index 31d7d922..16d643a2 100644 --- a/makefile +++ b/makefile @@ -38,6 +38,9 @@ else CONFIGURE_FLAGS := --datadir=/tmp/libpostal-data endif +# Detect if we need sudo +SUDO := $(shell if command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then echo "sudo"; else echo ""; fi) + # Installation target install: ifeq ($(detected_OS),Windows) @@ -52,12 +55,10 @@ else endif install-linux: - sudo apt-get install -y curl autoconf automake libtool pkg-config @$(MAKE) install-libpostal install-macos: brew install curl autoconf automake libtool pkg-config - @echo "Detecting architecture: $(ARCH)" ifeq ($(ARCH),arm64) @echo "ARM architecture detected (M1/M2). SSE2 will be disabled." else @@ -80,7 +81,7 @@ install-libpostal: if [ "$(detected_OS)" = "Windows" ]; then \ make install; \ else \ - sudo make install; \ + $(SUDO) make install; \ fi .PHONY: install install-linux install-macos install-windows install-libpostal