typegoose / mongodb-memory-server

Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.
https://typegoose.github.io/mongodb-memory-server/
MIT License
2.57k stars 185 forks source link

Support Ubuntu 22.04 properly (Error: `libcrypto.so.1.1 missing`) #732

Closed lyj711 closed 1 year ago

lyj711 commented 1 year ago

Versions

package: mongo-memory-server

What is the Problem?

When running 'pnpm test', following error occured:

Instance failed to start because a library is missing or cannot be opened: "libcrypto.so.1.1"

Code Example

import { Test, TestingModule } from '@nestjs/testing';
import { EventController } from './event.controller';
import { EventService } from './event.service';
import {MongoMemoryReplSet} from 'mongodb-memory-server';
import {Event} from '@prisma/client';
import { PrismaService } from '../prisma.service';
import { BadRequestException } from '@nestjs/common';
import { BlockchainService } from '../blockchain/blockchain.service';

describe('EventController', () => {
  let controller: EventController;
  let prisma: PrismaService;
  let mongodb: MongoMemoryReplSet;
  let eventModel: Event;

  beforeAll(async () => {
    mongodb = await MongoMemoryReplSet.create();
  });

  beforeEach(async () => {
    process.env.DATABASE_URL = mongodb.getUri('test');

    const module: TestingModule = await Test.createTestingModule({
      controllers: [EventController],
      providers: [EventService,PrismaService,BlockchainService],
    }).compile();

    controller = module.get<EventController>(EventController);
    eventModel = module.get<Event>(Event);
  });

  afterEach(async () => {
    await prisma.event.deleteMany({});

  })

  afterAll(async () => {
    await mongodb.stop();
  });

  it('Should throw an error if event id is not valid',async  () => {
    await expect(() => controller.getEvent('63bbd31c7a644b96fc34dc28')).toThrow(
      BadRequestException);
  });
});

Debug Output

Debug Output ```txt EventController › Should throw an error if event id is not valid Instance failed to start because a library is missing or cannot be opened: "libcrypto.so.1.1" ```

Do you know why it happenes?

no

hasezoey commented 1 year ago

known issue, nothing MMS can do about - there are just no Ubuntu 2204 binaries yet, so MMS falls back to 2004 binaries, but those require OpenSSL 1.1, and Ubuntu 2204 only ships 3.x, so your options are:

see https://jira.mongodb.org/browse/SERVER-62300 TL;DR: they are planning to add a ubuntu 2204 binary for 6.0.4

*1 somehow in ubuntu APT archives, there are mongodb builds for ubuntu 2204, but no "official" mongodb builds (Official builds can be found here)

MichaelJCole commented 1 year ago

See also: https://github.com/shelfio/jest-mongodb/issues/408

I have mongodb running all over the place on 22.04 with docker.

Would it be possible to substitute the binary download for a docker command?

In my experience, mongodb is much more focused on their Atlas platform than the community editions, so this might be one of many future issues like this. I spent hours on a workaround but came up empty. I'm probably not the first. I saw someone else suggest packaging mongo with the library in a snap or appimage, but I don't know how to do that (or if it would work)

Here is a reproduction:

git clone  git@github.com:renatops1991/clean-code-api.git 
cd clean-code-api
npm install
npm run test

This will come at the issue through jest-mongo

hasezoey commented 1 year ago

Would it be possible to substitute the binary download for a docker command?

MMS is currently not build to use anything other than the direct binary, you currently have 2 options:

i dont think MMS will add the ability to use anything other than the direct binary, though you could also just run MMS inside a container and let it use a binary there

hasezoey commented 1 year ago

update, there is now mongodb 6.0.4, which has a build for ubuntu 2204 (though that version is seemingly not documented yet)

build 6.0.4 ubuntu2204

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 8.11.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

hasezoey commented 1 year ago

Note: for now it still required to set a custom mongodb version with at least 6.0.4 (currently default for MMS 8.x is still mongodb 5.0.x, see config option VERSION

see When a Version gets upgraded

forivall commented 1 year ago

if someone needs 6.0.3 for any weird reason, i found that the .deb download contains a version which should work https://github.com/nodkz/mongodb-memory-server/issues/686#issuecomment-1370468664

sagrawal31 commented 1 year ago

Still facing the problem in GitLab node:lts on GitLab CI (after setting export MONGOMS_VERSION=6.0.4)-

Running with gitlab-runner 16.1.0~beta.5.gf131a6a2 (f131a6a2)
  on green-5.shared.runners-manager.gitlab.com/default xS6Vzpvo, system ID: s_d878f787d8ea
  feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor
Using Docker executor with image node:lts ...

https://github.com/nodkz/mongodb-memory-server/issues/480#issuecomment-1488548395 fixed it for me for the time being.

hasezoey commented 1 year ago

docker image node:lts is currently based on debian:12

there are currently no native binaries for debian 12, last being debian 11, i assume debian 12 changes the libcrypto version like ubuntu 22 did, maybe try to use the ubuntu 22 binary via config option ARCHIVE_NAME (valid archive names can be found here, use the .tgz archives)

sagrawal31 commented 1 year ago

Thanks, @hasezoey. I changed to node:lts-bullseye and it worked.

olof-nord commented 8 months ago

This error is occurring for me too - trying to upgrade from Node.js v18.18.2 to v20.

NodeJS: 20.9.0
mongodb-memory-server-*: 9.1.1
mongodb(the binary version): 6.0.6
mongodb(the js package): 5.9.2
system: Ubuntu

does anyone have any ideas how to resolve this?

hasezoey commented 8 months ago

This error is occurring for me too - trying to upgrade from Node.js v18.18.2 to v20.

this issue has nothing to do with a nodejs version upgrade, if you have such issues, please open a new issue

olof-nord commented 8 months ago

This error is occurring for me too - trying to upgrade from Node.js v18.18.2 to v20.

this issue has nothing to do with a nodejs version upgrade, if you have such issues, please open a new issue

Many thanks for the quick reply. So it turns out the problem was somewhere else (CI) - the search results led me here though.