Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongod ENOENT on Alpine using gitlab CI #428

Closed
valavanisleonidas opened this issue Jan 9, 2021 · 2 comments
Closed

mongod ENOENT on Alpine using gitlab CI #428

valavanisleonidas opened this issue Jan 9, 2021 · 2 comments
Labels

Comments

@valavanisleonidas
Copy link

valavanisleonidas commented Jan 9, 2021

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?

@hasezoey
Copy link
Member

i dont know if this is just an example, but maybe try an version that is not an rc (i mean an stable build), like 4.2

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

# Copy app source code
COPY . .

i would recommend to either switch this around and delete node_modules, or only copy src (and all other necessary files) instead of everything (because this merged node_modules from container and host) [because of #256]


otherwise, please try the latest beta release (currently being 7.0.0-beta.12)

@hasezoey
Copy link
Member

Duplicate of #347

@hasezoey hasezoey marked this as a duplicate of #347 Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants