誰能幫我通過部署在 Google App Engine 中的 Nodejs api 連接 oracle DB。我參考了此鏈接以連接到 DB。但它不起作用。
相同的代碼在本地運行良好,我從本地檔案夾參考 oracle 即時客戶端。
下面是我用來安裝 InstantClient 的 dockerfile。但我無法正確映射路徑。
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" ]
uj5u.com熱心網友回復:
我希望我的回答能幫助其他正在尋找解決方案的人。
我已經使用 dockerfile 和 app.yaml 在 App Engine 中進行部署。
我在下面提到了 OracleDB 連接的鏈接。它在本地就像一個魅力。但是當我部署到 AppEngine 時,我無法映射 oracle 即時客戶端檔案夾路徑。
所以我使用 Dockerfile 安裝了 Oracle 即時客戶端。
# 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" ]
應用程式.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 });
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433878.html
