【问题标题】:Dockerfile: How to install bcrypt correctly on a node alpine image?Dockerfile:如何在节点高山映像上正确安装 bcrypt?
【发布时间】:2020-01-02 00:57:39
【问题描述】:

我写了一个 Dockerfile 来创建一个基于 node:10.13 镜像的 nodeJS 应用程序。该应用程序需要bcrypt。到目前为止,它对完整节点映像非常有效。但是当然结果太大了,所以我尝试使用node:10.13-alpine 图像。因此我将 Dockerfile 更改为:

FROM node:10.13-alpine
RUN apk --no-cache add --virtual \
      builds-deps \
      build-base \
      python

WORKDIR /home/node/app

COPY ./package*.json ./
COPY ./.babelrc ./

RUN npm set progress=false \
    && npm config set depth 0 \
    && npm install --only=production --silent \
    && cp -R node_modules prod_node_modules \
    && npm install --silent \
    && apk del builds-deps

但这给了我一些错误。我的 Dockerfile 中缺少什么?当然我想得到一个小的结果图像......

Step 7/7 : RUN npm set progress=false && npm config set depth 0 && npm install --only=production --silent && cp -R node_modules prod_node_modules && npm install --silent
 ---> Running in 3eadd8526173
make: Entering directory '/home/node/app/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
In file included from ../../nan/nan_new.h:189:0,
                 from ../../nan/nan.h:222,
                 from ../src/bcrypt_node.cc:1:
../../nan/nan_implementation_12_inl.h: In static member function 'static Nan::imp::FactoryBase<v8::StringObject>::return_t Nan::imp::Factory<v8::StringObject>::New(v8::Local<v8::String>)':
../../nan/nan_implementation_12_inl.h:340:37: warning: 'static v8::Local<v8::Value> v8::StringObject::New(v8::Local<v8::String>)' is deprecated: Use Isolate* version [-Wdeprecated-declarations]
   return v8::StringObject::New(value).As<v8::StringObject>();
                                     ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:5053:37: note: declared here
                 static Local<Value> New(Local<String> value));
                                     ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
In file included from ../src/bcrypt_node.cc:1:0:
../../nan/nan.h: In constructor 'Nan::Utf8String::Utf8String(v8::Local<v8::Value>)':
../../nan/nan.h:1066:53: warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]
       v8::Local<v8::String> string = from->ToString();
                                                     ^
In file included from /root/.node-gyp/10.13.0/include/node/node.h:63:0,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:10040:15: note: declared here
 Local<String> Value::ToString() const {
               ^~~~~
In file included from ../src/bcrypt_node.cc:1:0:
../../nan/nan.h:1080:74: warning: 'int v8::String::WriteUtf8(char*, int, int*, int) const' is deprecated: Use Isolate* version [-Wdeprecated-declarations]
         length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
                                                                          ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:2659:21: note: declared here
                 int WriteUtf8(char* buffer, int length = -1,
                     ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/bcrypt_node.cc: In function 'char {anonymous}::ToCharVersion(v8::Local<v8::String>)':
../src/bcrypt_node.cc:66:30: warning: 'v8::String::Utf8Value::Utf8Value(v8::Local<v8::Value>)' is deprecated: Use Isolate version [-Wdeprecated-declarations]
   String::Utf8Value value(str);
                              ^
In file included from /root/.node-gyp/10.13.0/include/node/v8.h:26:0,
                 from /root/.node-gyp/10.13.0/include/node/node.h:63,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:2892:28: note: declared here
                   explicit Utf8Value(Local<v8::Value> obj));
                            ^
/root/.node-gyp/10.13.0/include/node/v8config.h:324:3: note: in definition of macro 'V8_DEPRECATED'
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/bcrypt_node.cc: In function 'Nan::NAN_METHOD_RETURN_TYPE {anonymous}::GenerateSalt(Nan::NAN_METHOD_ARGS_TYPE)':
../src/bcrypt_node.cc:121:60: warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]
     const char minor_ver = ToCharVersion(info[0]->ToString());
                                                            ^
In file included from /root/.node-gyp/10.13.0/include/node/node.h:63:0,
                 from ../../nan/nan.h:52,
                 from ../src/bcrypt_node.cc:1:
/root/.node-gyp/10.13.0/include/node/v8.h:10040:15: note: declared here
 Local<String> Value::ToString() const {
               ^~~~~

  // ... repeated above message

  SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
  COPY Release/bcrypt_lib.node
  COPY /home/node/app/node_modules/bcrypt/lib/binding/bcrypt_lib.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/home/node/app/node_modules/bcrypt/build'

【问题讨论】:

  • 真的失败了吗? (如果你添加了 Dockerfile 的其余部分来复制应用程序并声明一个 CMD 来启动它,它会运行吗?)
  • @DavidMaze 是的,它运行。但是这些日志是什么意思?我不应该避免这些吗?

标签: node.js docker dockerfile bcrypt alpine


【解决方案1】:

bcrypt 无法在 Alpine 上预先打包,因此 npm 从源代码构建它。

您看到的是来自 gcc(C++ 编译器)的构建警告,尤其是 5 个 deprecated-declarations 警告:

 warning: 'v8::Local<v8::String> v8::Value::ToString() const' is deprecated: Use maybe version [-Wdeprecated-declarations]

这些警告可能是无害的:它们表明使用了标有deprecated 函数属性的函数。这对于bcrypt 的维护者来说是一个更大的问题,您应该可以放心地忽略它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-26
    • 2020-09-07
    • 1970-01-01
    • 2019-04-01
    • 2016-07-23
    • 2020-08-03
    • 1970-01-01
    • 2019-10-02
    相关资源
    最近更新 更多