brianc / node-pg-native

Native (C/C++) bindings to PostgreSQL with sync and async options.
247 stars 44 forks source link

Incorrect find usage in alpine #72

Open bazzilio opened 6 years ago

bazzilio commented 6 years ago

In alpine linux, used mostly for docker, Call to find failed, because in alpine find can't search in multiple locations.

gyp: Call to 'which pg_config || find /usr/bin /usr/local/bin /usr/pg* /opt -executable -name pg_config -print -quit' returned exit status 1

It would be better to split find calls, like this:

find /usr/bin params && find  /usr/local/bin params && etc.

Full log attached.had The problem had gone after installing postgresql-dev package.

Steps to reproduce:

  1. build container with a Dockerfile
    FROM node:8-alpine
    RUN npm install
  2. Error would happen, if node-gyp used

node_gyp_error.txt

hawkesn commented 5 years ago

I'm running into this exact issue right now with

FROM node:11.10.1-alpine

Installing postgresql-dev package did not resolve it for me Any ideas on how to resolve it?

hawkesn commented 5 years ago

I managed to resolve it with the following:

RUN apk --no-cache add make python gcc postgresql-dev g++
RUN yarn install
sehrope commented 5 years ago

That makes sense. Alpine images are slimmed down to contain the bare minimum so they likely do not have any of the build tools needed to compile the native driver (i.e. g++ and the libpq headers).

lukasa1993 commented 3 years ago

I managed to resolve it with the following:

RUN apk --no-cache add make python gcc postgresql-dev g++
RUN yarn install

after this can be node_modules copied into another alpine linux ( e.g docker multistage builds) to not have all those apk dependencies required ?

charmander commented 3 years ago

@lukasa1993 yes (try it!)

jorinvo commented 3 years ago

Hi there, thanks for this thread everyone! This seems to be the only documentation available on the internet on how to get pg-native running in Alpine containers :)

This is what worked for us:

In the base image we have

RUN apk add --no-cache python build-base gcc g++ postgresql-dev
RUN npm ci

and in the slimmed-down production stage of the the multi-stage image we then only need

RUN apk add --no-cache libpq

So it works with less dependencies, but libpq is still required, even after npm install.

Note that this is tested through Slonik.

Without libpq in the final container, Slonik logs pg-native module is not found.

Edit: I adjusted the code above to reflect the insights from below: In production only libpq and not postgresql-dev is needed.

charmander commented 3 years ago

@jorinvo You shouldn’t need the full postgresql-dev, just libpq.

jorinvo commented 3 years ago

@charmander thank you for the reply! I tested it and, indeed, libpq is enough for production, thanks! Interestingly it is not enough for npm install. I adjusted the above comment accordingly for reference.