Skip to content

Commit

Permalink
build: installing libpostal in docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Dec 18, 2024
1 parent 6af891b commit 03a3d5b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libpostal/
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <oss@moov.io>"
COPY --from=backend /src/bin/server /bin/server
COPY --from=frontend /watchman/build/ /watchman/
Expand Down
26 changes: 18 additions & 8 deletions Dockerfile-openshift
Original file line number Diff line number Diff line change
@@ -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 <oss@moov.io>"
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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 03a3d5b

Please sign in to comment.