0

每当我运行我的 docker 映像时,我都会收到关于节点的系统/架构之间不兼容的错误...

我试过这个命令:

npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary

但是问题依然存在...

这是我的文件以获取更多上下文:

完全错误在我尝试运行我的 docker 映像后

Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v83-linux-x64-glibc
Found: [node-v72-darwin-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v83-linux-x64-glibc/grpc_node.node'

Require stack:
- /usr/src/app/node_modules/grpc/src/grpc_extension.js
- /usr/src/app/node_modules/grpc/src/client_interceptors.js
- /usr/src/app/node_modules/grpc/src/client.js
- /usr/src/app/node_modules/grpc/index.js
- /usr/src/app/booksServer.js
    at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
    at Function.Module._load (internal/modules/cjs/loader.js:950:14)
    at Module.require (internal/modules/cjs/loader.js:1125:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:144:12)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10) {
  code: 'MODULE_NOT_FOUND'

Dockerfile(运行我的 gRPC 节点服务器)

FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
COPY . /usr/src/app
RUN npm install
EXPOSE 30043
CMD ["node", "booksServer.js"]

Booksserver.js (GRPC 服务器)

// const PROTO_PATH = "../protos/books.proto";
const path = require('path');
const PROTO_PATH = path.join(__dirname, '../protos/books.proto');
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const express = require("express");
const controller = require("./booksController.js");
const app = express();
app.use(express.json());

const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  arrays: true,
});

const booksProto = grpc.loadPackageDefinition(packageDefinition);

const { v4: uuidv4 } = require("uuid");

const server = new grpc.Server();

server.addService(booksProto.BooksService.service, {
  CreateBook: (call, callback) => {
    console.log("call to CreateBook");

    //sample will take the call information from the client(stub)
    const book = {
      title: call.request.title,
      author: call.request.author,
      numberOfPages: call.request.numberOfPages,
      publisher: call.request.publisher,
      id: call.request.id,
    };

    controller.createBook(book);

    let meta = new grpc.Metadata();
    meta.add("response", "none");
    call.sendMetadata(meta);

    callback(
      null,
      //bookmodel.create
      {
        title: `completed for: ${call.request.title}`,
        author: `completed for: ${call.request.author}`,
        numberOfPages: `completed for: ${call.request.numberOfPages}`,
        publisher: `completed for: ${call.request.publisher}`,
        id: `completed for: ${call.request.id}`,
      }
    );
  },
  GetBooks: (call, callback) => {
    console.log("call to GetBooks");
    // read from database
    let meta = new grpc.Metadata();
    meta.add('response', 'none');
    call.sendMetadata(meta);

    controller.getBooks(callback);
  },
  GetBookByID: (call, callback) => {
    console.log("call to GetBookByID");
    
    let sampleID = {id: 100};

    let meta = new grpc.Metadata();
    meta.add('response', 'none');
    call.sendMetadata(meta);

    controller.getBookByID(sampleID, callback);
  },
  DeleteBook: (call, callback) => {
    //sample will take the call information from the client(stub)
    const bookID = {
      id: call.request.id,
    };

    //this actually sends data to booksController.
    controller.deleteBook(bookID);

    let meta = new grpc.Metadata();
    meta.add('response', 'none');
    call.sendMetadata(meta);

    // delete from database
    callback(null, { message: "DELETED" });
  },
});

server.bind("127.0.0.1:30043", grpc.ServerCredentials.createInsecure());
console.log("booksServer.js running at http://127.0.0.1:30043");

console.log("call from books server");

server.start();

4

0 回答 0