SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
249 stars 73 forks source link

Help Wanted: node-rfc in docker image #292

Closed paulwer closed 12 months ago

paulwer commented 12 months ago

Hello everyone: I just trying to wrap my head around, how to deploy a docker image with node-rfc.

My current docker image is as follows:

###################
# BUILD FOR LOCAL DEVELOPMENT
###################

FROM node:bullseye As development

RUN mkdir -p /usr/local/sap

# install nwrfcsdk https://github.com/SAP/node-rfc/tree/main/doc#linux
COPY ./nwrfcsdk /usr/local/sap/nwrfcsdk
ENV SAPNWRFC_HOME /usr/local/sap/nwrfcsdk
ENV LD_LIBRARY_PATH /usr/local/sap/nwrfcsdk/lib

# The content file to nwrfcsdk.conf
#### START CONTENT ### 
# # include nwrfcsdk
# /usr/local/sap/nwrfcsdk/lib
##### END CONTENT ###
COPY nwrfcsdk.conf /etc/ld.so.conf.d/
RUN ldconfig

# Create app directory
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY --chown=node:node package*.json ./

# Install app dependencies using the `npm ci` command instead of `npm install`
RUN npm ci

# Bundle app source
COPY --chown=node:node . .

# Use the node user from the image (instead of the root user)
USER node

###################
# BUILD FOR PRODUCTION
###################

FROM node:bullseye As build

WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./

# In order to run `npm run build` we need access to the Nest CLI which is a dev dependency. In the previous development stage we ran `npm ci` which installed all dependencies, so we can copy over the node_modules directory from the development image
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules

# copy prisma files
COPY --chown=node:node prisma ./prisma/

COPY --chown=node:node . .

# Run the build command which creates the production bundle
RUN npm run build

# Set NODE_ENV environment variable
ENV NODE_ENV production

# Reducing Dockerimage Size to the minimal required
# TODO: Running `npm ci` removes the existing node_modules directory and passing in --only=production ensures that only the production dependencies are installed. Or usage of `npm prune --omit=dev`. This ensures that the node_modules directory is as optimized as possible. Clearing the cache will also reduce in a smaller size, but currently removes the necessary files from ,prisma/client
# RUN npm prune --omit=dev
# run npm cache clean --force

USER node

###################
# PRODUCTION
###################

FROM node:bullseye As production

# Copy the bundled code from the build stage to the production image
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist

# TODO: revoke using local .env??
COPY --chown=node:node .env ./

# Start the server using the production build
CMD [ "node", "dist/src/main.js" ]

But I will always get the following error:

Step #0: npm ERR! code 1
Step #0: npm ERR! path /usr/src/app/node_modules/node-rfc
Step #0: npm ERR! command failed
Step #0: npm ERR! command sh -c node-gyp-build
Step #0: npm ERR! make: Entering directory '/usr/src/app/node_modules/node-rfc/build'
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/addon.o
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/nwrfcsdk.o
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/Client.o
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/Pool.o
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/Server.o
Step #0: npm ERR!   CXX(target) Release/obj.target/sapnwrfc/src/cpp/Throughput.o
Step #0: npm ERR!   SOLINK_MODULE(target) Release/obj.target/sapnwrfc.node
Step #0: npm ERR! make: Leaving directory '/usr/src/app/node_modules/node-rfc/build'
Step #0: npm ERR! gyp info it worked if it ends with ok
Step #0: npm ERR! gyp info using node-gyp@9.4.0
Step #0: npm ERR! gyp info using node@20.4.0 | linux | x64
Step #0: npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3"
Step #0: npm ERR! gyp http GET https://nodejs.org/download/release/v20.4.0/node-v20.4.0-headers.tar.gz
Step #0: npm ERR! gyp http 200 https://nodejs.org/download/release/v20.4.0/node-v20.4.0-headers.tar.gz
Step #0: npm ERR! gyp http GET https://nodejs.org/download/release/v20.4.0/SHASUMS256.txt
Step #0: npm ERR! gyp http 200 https://nodejs.org/download/release/v20.4.0/SHASUMS256.txt
Step #0: npm ERR! gyp info spawn /usr/bin/python3
Step #0: npm ERR! gyp info spawn args [
Step #0: npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
Step #0: npm ERR! gyp info spawn args   'binding.gyp',
Step #0: npm ERR! gyp info spawn args   '-f',
Step #0: npm ERR! gyp info spawn args   'make',
Step #0: npm ERR! gyp info spawn args   '-I',
Step #0: npm ERR! gyp info spawn args   '/usr/src/app/node_modules/node-rfc/build/config.gypi',
Step #0: npm ERR! gyp info spawn args   '-I',
Step #0: npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
Step #0: npm ERR! gyp info spawn args   '-I',
Step #0: npm ERR! gyp info spawn args   '/root/.cache/node-gyp/20.4.0/include/node/common.gypi',
Step #0: npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
Step #0: npm ERR! gyp info spawn args   '-Dvisibility=default',
Step #0: npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/20.4.0',
Step #0: npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
Step #0: npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/20.4.0/<(target_arch)/node.lib',
Step #0: npm ERR! gyp info spawn args   '-Dmodule_root_dir=/usr/src/app/node_modules/node-rfc',
Step #0: npm ERR! gyp info spawn args   '-Dnode_engine=v8',
Step #0: npm ERR! gyp info spawn args   '--depth=.',
Step #0: npm ERR! gyp info spawn args   '--no-parallel',
Step #0: npm ERR! gyp info spawn args   '--generator-output',
Step #0: npm ERR! gyp info spawn args   'build',
Step #0: npm ERR! gyp info spawn args   '-Goutput_dir=.'
Step #0: npm ERR! gyp info spawn args ]
Step #0: npm ERR! gyp info spawn make
Step #0: npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
Step #0: npm ERR! /usr/bin/ld: cannot find -lsapnwrfc
Step #0: npm ERR! /usr/bin/ld: cannot find -lsapucum
Step #0: npm ERR! collect2: error: ld returned 1 exit status
Step #0: npm ERR! make: *** [sapnwrfc.target.mk:192: Release/obj.target/sapnwrfc.node] Error 1
Step #0: npm ERR! gyp ERR! build error
Step #0: npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
Step #0: npm ERR! gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
Step #0: npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:512:28)
Step #0: npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
Step #0: npm ERR! gyp ERR! System Linux 5.10.0-23-cloud-amd64
Step #0: npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
Step #0: npm ERR! gyp ERR! cwd /usr/src/app/node_modules/node-rfc
Step #0: npm ERR! gyp ERR! node -v v20.4.0
Step #0: npm ERR! gyp ERR! node-gyp -v v9.4.0
Step #0: npm ERR! gyp ERR! not ok
Step #0:
Step #0: npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-07-11T14_33_54_612Z-debug-0.log
Step #0: The command '/bin/sh -c npm ci' returned a non-zero code: 1
Finished Step #0
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

What am I doing wrong?

bsrdjan commented 12 months ago

Linking fails because linker cannot find SAP NW RFC SDK libraries:

Step #0: npm ERR! /usr/bin/ld: cannot find -lsapnwrfc
Step #0: npm ERR! /usr/bin/ld: cannot find -lsapucum

SAPNWRFC_HOME env variable should be set to /usr/local/sap/nwrfcsdk

paulwer commented 12 months ago

Thank you for your answer, I already have set the suggested variable. (4th command in Dockerfile)

bsrdjan commented 12 months ago

How the node-rfc should be installed, what triggers the build?

This docker container works also when nods:18 replaced with bullseye:

https://github.com/SAP/fundamental-tools/blob/main/docker/node18.Dockerfile

Is correct SAP NW RFC SDK VERSION installed? For Linux x64 platform? ARM Linux is not supported

paulwer commented 12 months ago

thats it. I was provided with the windows binaries. thank you