Search code examples
node.jsdockerdockerfilebcryptalpine-linux

Dockerfile: How to install bcrypt correctly on a node alpine image?


I wrote a Dockerfile to create a nodeJS application based on the node:10.13 image. The application needs bcrypt. So far it is working great for the full node image. But of course the result is too big, so I tried to use the node:10.13-alpine image. Therefore I changed the Dockerfile to this:

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

But this gives me some errors. What is missing in my Dockerfile? Of course I would like to get a small result image...

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'

Solution

  • bcrypt is not available pre-packaged on Alpine, so npm builds it from source.

    What you're seeing are build warnings from gcc, the C++ compiler, particularly 5 deprecated-declarations warnings:

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

    These warnings are probably harmless: they indicate that functions marked with the deprecated function attribute were used. This is more of an issue to bcrypt maintainers, and you should be able to safely ignore it.