Skip to content

mongod ENOENT on Alpine using gitlab CI #428

Closed
@valavanisleonidas

Description

@valavanisleonidas

Versions

  • NodeJS: 14.15.3
  • mongodb-memory-server-*: 6.9.2
  • mongodb: 3.6.3
  • system: Linux Alpine docker image

package: mongo-memory-server

What is the Problem?

2021-01-09T17:23:09.168Z MongoMS:MongoInstance Mongo[43073]: MongodbInstance: Instance has failed: Error: spawn /builds/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.14/mongod ENOENT
2021-01-09T17:23:09.172Z MongoMS:MongoInstance Mongo[43073]: Mongod instance closed with an non-0 code!
2021-01-09T17:23:09.173Z MongoMS:MongoInstance Mongo[43073]: CLOSE: -2
2021-01-09T17:23:09.173Z MongoMS:MongoInstance Mongo[43073]: MongodbInstance: Instance has failed: Mongod instance closed with code "-2"

It runs locally but it fails through gitlab CI.

I know there are duplicates to this problem but their solution does not work for me.

Code Example

my ts code is
(it will not run as it is because they are parts taken from different files) but this is the gist of what I do

    let mongoServer = new MongoMemoryServer();
    const fake_connection_url = await mongoServer.getUri()
    
    const options = {useNewUrlParser: true, useUnifiedTopology: true};

  // Use connect method to connect to the server
  return new Promise((resolve, reject) => {

    mongoClient.connect(connection_url, options, (err, client) => {
      if (err) {
        logger.log("error", "Error connecting to MongoDB - " + err);
        reject(err);
        return;
      }
      logger.log("info", "Connected successfully to server");

      db = client.db(dbName);
      adminDb = db.admin();
      dbClient = client;

      resolve('success');
    });
  });

My dockerfile is :

FROM node:lts-alpine3.12
# App directory
WORKDIR /opt/node/app

# App dependencies
COPY package*.json ./
RUN npm install

# Copy app source code
COPY . .

# Test
RUN npm run test

# Build
RUN npm run build

# Env setup

# Start the app
CMD [ "npm", "run", "start"]

Do you know why it happens?

I know that it happens because of Alpine and mongo incompatibility. But from the duplicate posts it should work if I put in the docker file something like

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/main' >> /etc/apk/repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/community' >> /etc/apk/repositories
RUN apk update
# mongodb installation throws an error, but seems to work, so ignoring the exit status.
RUN apk add mongodb=4.0.5-r0 || true
# this is required by mongodb-memory-server to avoid trying to download the mongod file.
ENV MONGOMS_SYSTEM_BINARY=/usr/bin/mongod

but it does not work.

I have checked these related links but found nothing so far.

  1. Error: spawn /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod ENOENT #171
  2. Can't run mongodb-memory-server on Linux Alpine #32
  3. https://stackoverflow.com/questions/32724556/execute-mongodb-binaries-on-alpine-linux

any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions