emilbayes / secure-password

Making Password storage safer for all
ISC License
569 stars 22 forks source link

Import fails when using node alpine docker image #21

Open dyc3 opened 4 years ago

dyc3 commented 4 years ago

I'm using the docker image node:alpine3.11 to build and deploy my application.

internal/modules/cjs/loader.js:1197
 return process.dlopen(module, path.toNamespacedPath(filename));

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/app/node_modules/sodium-native/prebuilds/linux-x64/libsodium.so.23)
 at Object.Module._extensions..node (internal/modules/cjs/loader.js:1197:18)
 at Module.load (internal/modules/cjs/loader.js:996:32)
 at Function.Module._load (internal/modules/cjs/loader.js:896:14)
 at Module.require (internal/modules/cjs/loader.js:1036:19)
 at require (internal/modules/cjs/helpers.js:72:18)
 at load (/usr/app/node_modules/node-gyp-build/index.js:21:10)
 at Object.<anonymous> (/usr/app/node_modules/sodium-native/index.js:1:39)
 at Module._compile (internal/modules/cjs/loader.js:1147:30)
 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
 at Module.load (internal/modules/cjs/loader.js:996:32)
emilbayes commented 4 years ago

Hi, it seems like your docker image failed to load the correct binary. Can you share more of your Dcokerfile?

You might have this issue: https://github.com/sodium-friends/sodium-native/issues/126

dyc3 commented 4 years ago

Sure, its in a PR for one of my projects: https://github.com/dyc3/opentogethertube/pull/209 commit ddc38da

This is what the docker file looks like

### Build stage ###
FROM node:alpine3.11 as build-stage

# Create app directory
WORKDIR /usr/app

# Copy the important file
COPY . .

# Install app dependencies
RUN npm install

# Build the application for deployement
RUN npm run build

### Deployement server nginx ###
FROM node:alpine3.11 as production-stage

# Create app directory
WORKDIR /usr/app/

# Environnement variable redis/postgres/webport
ENV REDIS_PORT 6379
# Environnement variable nodejs
ENV NODE_ENV production
ENV PORT 8080

# Install sqlite3
RUN apk update -q
RUN apk add sqlite curl -q

# Copy from build stage
COPY --from=build-stage /usr/app/ /usr/app/
COPY --from=build-stage /usr/app/docker/scripts/wait_for_db.sh /usr/app/wait_for_db.sh

# Install app dependencies
RUN npm install --production

# Remove all the unnecessary directories
RUN rm -rf docker .github .vscode db public test src

# Remove all the unnecessary files
RUN rm -rf env .browserslistrc .eslintrc.js .gitignore .travis.yml codecov.yaml
RUN rm -rf jest.config.js postcss.config.js vue.config.js babel.config.js docker-compose.yml

RUN mkdir env && touch env/production.env 

# Healthcheck API, WEB, REDIS
HEALTHCHECK CMD ( curl -f http://localhost:8080/ || exit 1 )

# Start Server
CMD ["/bin/sh", "wait_for_db.sh", "postgres_db:5432", "--", "npm", "run", "start"]
emilbayes commented 4 years ago

Did you see the other issue I linked? I'm not too familiar with docker build stages

dyc3 commented 4 years ago

After adding the line

RUN apk --update add --no-cache curl git python alpine-sdk bash autoconf libtool automake

It still fails with the same error.

emilbayes commented 4 years ago

@dyc3 what stage did you add it to?

emilbayes commented 4 years ago

And what node version is that running?

dyc3 commented 4 years ago

The node:alpine3.11 tag runs the latest version of node (13.13.0) on alpine 3.11

marcbachmann commented 3 years ago

This might be helpful to others. I'm using the following Dockerfile instructions using alpine linux. The environment variable helps in finding the prebuilt version:

FROM node:15-alpine
RUN apk add --no-cache --virtual build-deps python alpine-sdk autoconf libtool automake && \
  mkdir -p /prebuilds && cd /prebuilds && npm init -y && npm install sodium-native@3.1.1 && \
  apk del build-deps
ENV SODIUM_NATIVE_PREBUILD=/prebuilds/node_modules/sodium-native/

and a new version with node 16 (includes python3 instead of python2):

FROM node:16-alpine
RUN apk add --no-cache --virtual build-deps python3 alpine-sdk autoconf libtool automake && \
  mkdir -p /prebuilds && cd /prebuilds && npm init -y && npm install sodium-native@3.1.1 && \
  apk del build-deps
ENV SODIUM_NATIVE_PREBUILD=/prebuilds/node_modules/sodium-native/