node-pg-native icon indicating copy to clipboard operation
node-pg-native copied to clipboard

Incorrect find usage in alpine

Open bazzilio opened this issue 6 years ago • 8 comments

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
  1. Error would happen, if node-gyp used

node_gyp_error.txt

bazzilio avatar Aug 22 '18 13:08 bazzilio

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 avatar Mar 05 '19 20:03 hawkesn

I managed to resolve it with the following:

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

hawkesn avatar Mar 05 '19 20:03 hawkesn

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).

sehrope avatar Mar 05 '19 20:03 sehrope

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 ?

lukasa1993 avatar Apr 10 '21 17:04 lukasa1993

@lukasa1993 yes (try it!)

charmander avatar Apr 11 '21 00:04 charmander

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.

jorinvo avatar Jul 20 '21 08:07 jorinvo

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

charmander avatar Jul 20 '21 22:07 charmander

@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.

jorinvo avatar Jul 21 '21 08:07 jorinvo