ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

Build failing with node:16-alpine Docker #908

Closed jonwrona closed 1 year ago

jonwrona commented 1 year ago

I'm having trouble getting the ibm_db package through its build stage when setting up a Dockerfile. Right now the build is failing at: 'node-gyp configure build --IS_DOWNLOADED=true --IBM_DB_HOME="$IBM_DB_HOME"

Below are my Dockerfile and the error output from the build. The Dockerfile is based on the Nextjs template.

Any guidance for how to get this build working is greatly appreciated.

Dockerfile

FROM node:16-alpine AS base

# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat gcc g++ make curl python3

WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi

# Rebuild the source code only when needed
FROM base AS builder

WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

Build Error

#12 118.7 error /app/node_modules/ibm_db: Command failed.
#12 118.7 Exit code: 1
#12 118.7 Command: node installer/driverInstall.js
#12 118.7 Arguments: 
#12 118.7 Directory: /app/node_modules/ibm_db
#12 118.7 Output:
#12 118.7 platform = linux, arch = x64, node.js version = v16.19.1
#12 118.7 make version =GNU Make 4.3
#12 118.7 
#12 118.7 ****************************************
#12 118.7 You are downloading a package which includes the Node.js module for IBM DB2/Informix.  The module is licensed under the Apache License 2.0. The package also includes IBM ODBC and CLI Driver from IBM, which is automatically downloaded as the node module is installed on your system/device. The license agreement to the IBM ODBC and CLI Driver is available in /app/node_modules/ibm_db/installer/clidriver. Check for additional dependencies, which may come with their own license agreement(s). Your use of the components of the package and dependencies constitutes your acceptance of their respective license agreements. If you do not accept the terms of any license agreement(s), then delete the relevant component(s) from your device.
#12 118.7 ****************************************
#12 118.7 
#12 118.7 Downloading DB2 ODBC CLI Driver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz ...
#12 118.7 
73.42% | 18579456 bytes downloaded out of info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
100.00% | 25304884 bytes downloaded out of 25304884 bytes.
#12 118.7 
#12 118.7 Downloading and extraction of DB2 ODBC CLI Driver completed successfully.
#12 118.7 
#12 118.7 make: Entering directory '/app/node_modules/ibm_db/build'
#12 118.7   CXX(target) Release/obj.target/odbc_bindings/src/odbc.o
#12 118.7 make: Leaving directory '/app/node_modules/ibm_db/build'
#12 118.7 
#12 118.7 Error: Command failed: node-gyp configure build  --IS_DOWNLOADED=true --IBM_DB_HOME="$IBM_DB_HOME"
#12 118.7 gyp info it worked if it ends with ok
#12 118.7 gyp info using node-gyp@9.1.0
#12 118.7 gyp info using node@16.19.1 | linux | x64
#12 118.7 gyp info find Python using Python version 3.10.10 found at "/usr/bin/python3"
#12 118.7 gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.19.1/node-v16.19.1-headers.tar.gz
#12 118.7 gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.19.1/node-v16.19.1-headers.tar.gz
#12 118.7 gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.19.1/SHASUMS256.txt
#12 118.7 gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.19.1/SHASUMS256.txt
#12 118.7 gyp info spawn /usr/bin/python3
#12 118.7 gyp info spawn args [
#12 118.7 gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
#12 118.7 gyp info spawn args   'binding.gyp',
#12 118.7 gyp info spawn args   '-f',
#12 118.7 gyp info spawn args   'make',
#12 118.7 gyp info spawn args   '-I',
#12 118.7 gyp info spawn args   '/app/node_modules/ibm_db/build/config.gypi',
#12 118.7 gyp info spawn args   '-I',
#12 118.7 gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
#12 118.7 gyp info spawn args   '-I',
#12 118.7 gyp info spawn args   '/root/.cache/node-gyp/16.19.1/include/node/common.gypi',
#12 118.7 gyp info spawn args   '-Dlibrary=shared_library',
#12 118.7 gyp info spawn args   '-Dvisibility=default',
#12 118.7 gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.19.1',
#12 118.7 gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
#12 118.7 gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.19.1/<(target_arch)/node.lib',
#12 118.7 gyp info spawn args   '-Dmodule_root_dir=/app/node_modules/ibm_db',
#12 118.7 gyp info spawn args   '-Dnode_engine=v8',
#12 118.7 gyp info spawn args   '--depth=.',
#12 118.7 gyp info spawn args   '--no-parallel',
#12 118.7 gyp info spawn args   '--generator-output',
#12 118.7 gyp info spawn args   'build',
#12 118.7 gyp info spawn args   '-Goutput_dir=.'
#12 118.7 gyp info spawn args ]
#12 118.7 gyp info spawn make
#12 118.7 gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
#12 118.7 In file included from ../src/odbc.cpp:29:
#12 118.7 ../src/odbc.h: In constructor 'ODBC::ODBC()':
#12 118.7 ../src/odbc.h:142:23: error: cast from 'std::nullptr_t' to 'SQLHENV' {aka 'int'} loses precision [-fpermissive]
#12 118.7   142 |     ODBC() { m_hEnv = (SQLHENV)NULL; }
#12 118.7       |                       ^
#12 118.7 ../src/odbc.cpp: In member function 'void ODBC::Free()':
#12 118.7 ../src/odbc.cpp:110:14: error: cast from 'std::nullptr_t' to 'SQLHENV' {aka 'int'} loses precision [-fpermissive]
#12 118.7   110 |     m_hEnv = (SQLHENV)NULL;
#12 118.7       |              ^
#12 118.7 ../src/odbc.cpp: In static member function 'static Nan::NAN_METHOD_RETURN_TYPE ODBC::New(Nan::NAN_METHOD_ARGS_TYPE)':
#12 118.7 ../src/odbc.cpp:122:17: error: cast from 'std::nullptr_t' to 'SQLHENV' {aka 'int'} loses precision [-fpermissive]
#12 118.7   122 |   dbo->m_hEnv = (SQLHENV)NULL;
#12 118.7       |                 ^
#12 118.7 ../src/odbc.cpp: In static member function 'static void ODBC::UV_AfterCreateConnection(uv_work_t*, int)':
#12 118.7 ../src/odbc.cpp:216:19: warning: 'v8::Local<v8::Value> Nan::Callback::Call(int, v8::Local<v8::Value>*) const' is deprecated [-Wdeprecated-declarations]
#12 118.7   216 |     data->cb->Call(1, info);
#12 118.7       |     ~~~~~~~~~~~~~~^~~~~~~~~
#12 118.7 In file included from ../src/odbc.h:23:
#12 118.7 ../../nan/nan.h:1746:3: note: declared here
#12 118.7  1746 |   Call(int argc, v8::Local<v8::Value> argv[]) const {
#12 118.7       |   ^~~~
#12 118.7 ../src/odbc.cpp:228:19: warning: 'v8::Local<v8::Value> Nan::Callback::Call(int, v8::Local<v8::Value>*) const' is deprecated [-Wdeprecated-declarations]
#12 118.7   228 |     data->cb->Call(2, info);
#12 118.7       |     ~~~~~~~~~~~~~~^~~~~~~~~
#12 118.7 ../../nan/nan.h:1746:3: note: declared here
#12 118.7  1746 |   Call(int argc, v8::Local<v8::Value> argv[]) const {
#12 118.7       |   ^~~~
#12 118.7 ../src/odbc.cpp: In static member function 'static v8::Local<v8::Value> ODBC::CallbackSQLError(SQLSMALLINT, SQLHANDLE, char*, Nan::Callback*)':
#12 118.7 ../src/odbc.cpp:1507:11: warning: 'v8::Local<v8::Value> Nan::Callback::Call(int, v8::Local<v8::Value>*) const' is deprecated [-Wdeprecated-declarations]
#12 118.7  1507 |   cb->Call(1, info);
#12 118.7       |   ~~~~~~~~^~~~~~~~~
#12 118.7 ../../nan/nan.h:1746:3: note: declared here
#12 118.7  1746 |   Call(int argc, v8::Local<v8::Value> argv[]) const {
#12 118.7       |   ^~~~
#12 118.7 In file included from ../src/odbc.cpp:24:
#12 118.7 ../src/odbc.cpp: At global scope:
#12 118.7 /root/.cache/node-gyp/16.19.1/include/node/node.h:887:7: warning: cast between incompatible function types from 'void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)' {aka 'void (*)(v8::Local<v8::Object>)'} to 'node::addon_register_func' {aka 'void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)'} [-Wcast-function-type]
#12 118.7   887 |       (node::addon_register_func) (regfunc),                          \
#12 118.7       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#12 118.7 /root/.cache/node-gyp/16.19.1/include/node/node.h:921:3: note: in expansion of macro 'NODE_MODULE_X'
#12 118.7   921 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
#12 118.7       |   ^~~~~~~~~~~~~
#12 118.7 ../src/odbc.cpp:1671:1: note: in expansion of macro 'NODE_MODULE'
#12 118.7  1671 | NODE_MODULE(odbc_bindings, init)
#12 118.7       | ^~~~~~~~~~~
#12 118.7 ../src/odbc.cpp: In static member function 'static v8::Local<v8::Value> ODBC::GetColumnValue(SQLHSTMT, Column, uint16_t*, size_t)':
#12 118.7 ../src/odbc.cpp:598:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   598 |         if(column.type == SQL_BIGINT)
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:603:5: note: here
#12 118.7   603 |     case SQL_DBCLOB:
#12 118.7       |     ^~~~
#12 118.7 ../src/odbc.cpp:604:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   604 |         if(column.type == SQL_DBCLOB)
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:609:5: note: here
#12 118.7   609 |     default :
#12 118.7       |     ^~~~~~~
#12 118.7 ../src/odbc.cpp: In static member function 'static v8::Local<v8::Value> ODBC::GetOutputParameter(Parameter)':
#12 118.7 ../src/odbc.cpp:772:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   772 |         if(prm.type == SQL_NUMERIC)
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:774:5: note: here
#12 118.7   774 |     case SQL_BIGINT :
#12 118.7       |     ^~~~
#12 118.7 ../src/odbc.cpp:826:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   826 |         if(prm.type == SQL_DECIMAL) {
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:829:5: note: here
#12 118.7   829 |     case SQL_FLOAT :
#12 118.7       |     ^~~~
#12 118.7 ../src/odbc.cpp:871:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   871 |         if((int) prm.type == SQL_DBCLOB)
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:875:5: note: here
#12 118.7   875 |     case SQL_BLOB :
#12 118.7       |     ^~~~
#12 118.7 ../src/odbc.cpp:876:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
#12 118.7   876 |         if((int) prm.type == SQL_BLOB)
#12 118.7       |         ^~
#12 118.7 ../src/odbc.cpp:880:5: note: here
#12 118.7   880 |     default :
#12 118.7       |     ^~~~~~~
#12 118.7 make: *** [odbc_bindings.target.mk:120: Release/obj.target/odbc_bindings/src/odbc.o] Error 1
#12 118.7 gyp ERR! build error 
#12 118.7 gyp ERR! stack Error: `make` failed with exit code: 2
#12 118.7 gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
#12 118.7 gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
#12 118.7 gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
#12 118.7 gyp ERR! System Linux 5.10.25-linuxkit
#12 118.7 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build" "--IS_DOWNLOADED=true" "--IBM_DB_HOME=/app/node_modules/ibm_db/installer/clidriver"
#12 118.7 gyp ERR! cwd /app/node_modules/ibm_db
#12 118.7 gyp ERR! node -v v16.19.1
#12 118.7 gyp ERR! node-gyp -v v9.1.0
#12 118.7 gyp ERR! not ok 
#12 118.7 
#12 118.7     at ChildProcess.exithandler (node:child_process:402:12)
#12 118.7     at ChildProcess.emit (node:events:513:28)
#12 118.7     at maybeClose (node:internal/child_process:1100:16)
#12 118.7     at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) {
#12 118.7   code: 1,
#12 118.7   killed: false,
#12 118.7   signal: null,
#12 118.7   cmd: 'node-gyp configure build  --IS_DOWNLOADED=true --IBM_DB_HOME="$IBM_DB_HOME"'
#12 118.7 }
jonwrona commented 1 year ago

I've noticed that in the documentation you mention that this require python 2, not 3. Unfortunately Nextjs v13 requires at least Node 14.6.0, and python 2 is deprecated in the node:14-alpine base image.

Also just to make sure I tried the build with python2 on node:12-alpine, and it was successful.

jonwrona commented 1 year ago

Ah I missed in the documentation that Alpine is not supported. Does anyone have a recommendation for a base Docker image for Node?

bimalkjha commented 1 year ago

@jonwrona You can use x64 version of linux docker. The amazonlinux OS in docker works fine for ibm_db. You can refer similar issue #633 where some solution is mentioned in last. Also, check this comment for working docker image: https://github.com/ibmdb/node-ibm_db/issues/803#issuecomment-1105911743 Thanks.