Unable to run node-gdal on Alpine Linux: “__printf

2019-08-12 05:59发布

问题:

I'm trying to add Gitlab CI for my project using node-gdal (Node.js bindings for GDAL). CI configuration is based on Alpine Linux docker image due to performance reasons but I'm unable to get it working. Gitlab CI job fails while running Node.js script that requires node-gdal with the following error:

internal/modules/cjs/loader.js:718
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: Error relocating /builds/project-0/node_modules/gdal/lib/binding/node-v64-linux-x64/gdal.node: __printf_chk: symbol not found
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/builds/project-0/node_modules/gdal/lib/gdal.js:12:29)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)

Tried to install glibc for Alpine but still with no luck.

.gitlab-ci.yml

image: node:lts-alpine

stages:
  - test

test:
  stage: test
  before_script:
    - apk add --no-cache bash ca-certificates wget
    - wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
    - wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk
    - apk add glibc-2.29-r0.apk
  script:
    - yarn
    - node index.js

This is a repo reproducing the issue and this is a link to failed job.

Is there any solution to use the library on Alpine?

回答1:

Thanks to this and this related questions and answers, I was able to build node-gdal linking against shared GDAL library on Alpine with the following CI configuration (link to passed job):

.gitlab-ci.yml

image: node:lts-alpine

stages:
  - test

test:
  stage: test
  before_script:
    - apk add --no-cache bash make gcc g++ python linux-headers udev --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing --repository http://dl-cdn.alpinelinux.org/alpine/edge/main gdal gdal-dev
  script:
    - npm install gdal --build-from-source --shared_gdal
    - node index.js