无法通过部署在 Google App Engine 中的 Nodejs API 连接 Oracle 数据库

Unable to connect Oracle DB through Nodejs API deployed in Google App Engine

任何人都可以帮助我通过部署在 Google App Engine 中的 Nodejs api 连接 oracle 数据库。 我引用此 link 连接到数据库。但它不起作用。

相同的代码在本地运行良好,我从本地文件夹引用 oracle 即时客户端。

下面是我用来安装的 dockerfile instantClient.But 我无法正确映射路径。

FROM node:12.9.1-buster-slim

WORKDIR /tmp
RUN apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get install -y alien libaio1

RUN wget https://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.3-basiclite-19.3.0.0.0-1.x86_64.rpm
RUN alien -i --scripts oracle-instantclient*.rpm
RUN rm -f oracle-instantclient19.3*.rpm && apt-get -y autoremove && apt-get -y clean

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install production dependencies.
RUN npm install --only=production

# Copy local code to the container image.
COPY . .

# Run the web service on container startup.
CMD [ "npm", "start" ]

希望我的回答能对正在寻找解决方案的其他人有所帮助。

我已经使用 dockerfile 和 app.yaml 在 App Engine 中进行部署。

我在下面提到 link 用于 OracleDB 连接。它在本地非常有效。但是当我部署到 AppEngine 时,我无法映射 oracle 即时客户端文件夹路径。

所以我使用 Dockerfile 安装了 Oracle instantclient。

# Use the official Node.js 12 image.
# https://hub.docker.com/_/node

FROM node:12-buster-slim

RUN apt-get update && apt-get install -y libaio1 wget unzip

WORKDIR /opt/oracle

RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \
    unzip instantclient-basiclite-linuxx64.zip && rm -f instantclient-basiclite-linuxx64.zip && \
    cd /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *mql1* *ipc1* *jar uidrvci genezi adrci && \
    echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig

# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./

# Install production dependencies.
RUN npm install --only=production

# Copy local code to the container image.
COPY . .

# Run the web service on container startup.
CMD [ "npm", "start" ]

App.yaml 文件

# [START appengine_websockets_yaml]
runtime: custom
env: flex
service: servicename
network:
  name: path
env_variables:

# Use only a single instance, so that this local-memory-only chat app will work
# consistently with multiple users. To work across multiple instances, an
# extra-instance messaging system or data store would be needed.
manual_scaling:
  instances: 1
# [END appengine_websockets_yaml]

要初始化 OracleClient,请使用以下代码

const ORACLE_CLIENT_PATH = process.env.ldconfig

exports.initializeOracleClient = async () => {
    oracledb.initOracleClient({ libDir: ORACLE_CLIENT_PATH });
}