Comments (15)
It looks like you are using some exact mongodb version in your tests.
Please add MONGOMS_VERSION
var to your env variables in CI config.
Related to #76
from mongodb-memory-server.
By default downloaded latest
version
from mongodb-memory-server.
I am using the env variable in my Dockerfile
.
Part of my Dockerfile:
## Dockerfile
FROM node:8.9.3-slim
ENV MONGOMS_VERSION=3.4.4
COPY . /my-app/source
RUN rm -rf ./node_modules
RUN npm install --unsafe-perm --loglevel=warn
# Here we see downloading process
RUN npm test
#And here we see downloading process
I took a look on code and seems like in MongoBinary
you create cache
as empty object on startup without checking any existing downloads. And then the version is put to the cache object only after downloading.
But when docker container is running it doesn't have run MongoInstance
and the cache object is still empty and it is a reason why it tries to download it again.
from mongodb-memory-server.
Can you make PR?
from mongodb-memory-server.
@nodkz Is the env variable MONGOMS_DOWNLOAD_DIR not enough for this specific use case ?
By specifying it in the Dockerfile and providing the cache binary from gitlab to the path specified by MONGOMS_DOWNLOAD_DIR in the container.
The code in the getPath function of MongoBinary class using this env variable :
const defaultOptions = {
downloadDir:
process.env?.MONGOMS_DOWNLOAD_DIR || path.resolve(os.homedir(), '.mongodb-binaries'),
platform: process.env?.MONGOMS_PLATFORM || os.platform(),
arch: process.env?.MONGOMS_ARCH || os.arch(),
version: process.env?.MONGOMS_VERSION || 'latest',
debug:
typeof process.env.MONGOMS_DEBUG === 'string'
? ['1', 'on', 'yes', 'true'].indexOf(process.env.MONGOMS_DEBUG.toLowerCase()) !== -1
: false,
};
from mongodb-memory-server.
Need to meet MONGOMS_DOWNLOAD_DIR and MONGOMS_VERSION. These vars are used for storing binaries in some path.
So by default with npm install will be downloaded latest
version. But if tests uses for example v3.6.4 it will be fownloaded again.
What I think, that this lib should have some bin script, which can be used in docker file:
- firstly install npm
- then run cmd for install other mongo version if needed
from mongodb-memory-server.
@nodkz I've been trying to cache as well the mongdb binary download with Gitlab CI as well.
I've tried doing that by using the env variables you suggested (I'm using the lastest version of the mongodb binary so I didn't specified MONGOMS_VERSION), here is my gitlab ci file :
stages:
- functionnal_tests
functionnal_tests:
image: node:8
stage: functionnal_tests
variables:
MONGOMS_DOWNLOAD_DIR: 'mongobinary'
cache:
paths:
- mongobinary
- node_modules
script:
- npm install
- npm test
I've suceeded to cache the npm test command where the mongodb binary is downloaded to the path specified by MONGOMS_DOWNLOAD_DIR.
But it seems that on the npm install command the binary is not downloaded to the same path, it is downloaded to node_modules/mongodb-memory-server/ + MONGOMS_DOWNLOAD_DIR, here is the trace of the debug of mongdb-memory-server :
$ npm install
> [email protected] postinstall /builds/api/node_modules/mongodb-memory-server
> node ./postinstall.js
mongodb-memory-server: checking MongoDB binaries cache...
Downloading MongoDB latest: 0 % (0mb / 84.5mb)
Downloading MongoDB latest: 52.2 % (44.1mb / 84.5mb)
mongodb-memory-server: binary path is /builds/api/node_modules/mongodb-memory-server/mongobinary/latest/mongod
Is this behaviour normal ?
Maybe the MongoBinary class is just appending a download path to the current directory ?
It would explain why my binary is downloaded in the node_modules directory since the npm install is done in that directory.
And is the binary download on the npm install command really useful ? Isn't the download on npm test when we create an instance of MongodbMemoryServer enough ?
from mongodb-memory-server.
I found out the source of the problem it was because of the path I gave to MONGOMS_DOWNLOAD_DIR that was incorrect and using the current directory, I specified the path of the build directory of the gitlab pipeline and I suceeded to cache the npm install
and npm test
binary download :)
But still why do we need to download two times the mongodb binary in npm install
and npm test
and not only in the npm test
command ?
from mongodb-memory-server.
Sorry for delay, I've investigated it deeper and when I set version as latest
it works correct but if I provide another version it downloads twice. Seems like it needs to delete version: 'latest'
from postinstall.js
anyway it will use it by default.
About previous comment of install only in the npm test
command in my case it nice to have this feature but if you will change it please leave a possibility to install it in npm install
command may be just add env variable MONGOMS_DOWNLOAD_ON_POSTINSTALL
from mongodb-memory-server.
Fix already on npm.
from mongodb-memory-server.
Can I add one more PR for MONGOMS_DOWNLOAD_ON_POSTINSTALL
env variable?
from mongodb-memory-server.
It should download binary automatically on post install, cause many users don't know how to increase timeout limit for test runners. So better to download binaries on package install.
Why do you need to add MONGOMS_DOWNLOAD_ON_POSTINSTALL
variable?
You have any problems right now? Binary did not download as expected?
from mongodb-memory-server.
I found one more situation that I need to don't download in npm i
. I would like to add env variable that will cancel this issue but leave it as it is by default. So in this case if you need to download in npm i
you don't need to do anything, but with this variable you can avoid it.
from mongodb-memory-server.
Another words I have 2 cases when I need to download in npm i
and another one when I need to download it in npm test
from mongodb-memory-server.
So it can be named MONGOMS_DISABLE_POSTINSTALL
Open PR!
from mongodb-memory-server.
Related Issues (20)
- Can't connect to dockerized mongodb-memory-server replica set running as a service in GitLab HOT 11
- Change `forceSamePort` parameter to also be a config option
- oplogSize for replSet should be removed in README HOT 2
- Use RHEL 9 binaries HOT 2
- Add Support for "Rocky Linux 9" HOT 4
- [SOLUTION] Jest and Fake Timers HOT 1
- Amazon EC2 instance download failed, combination does not exist (403) HOT 4
- "getport" sometimes throwing an error HOT 41
- DownloadError: Download failed for url "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-5.0.19.tgz" HOT 10
- Weird "db.watch" issue HOT 1
- postinstallHelper always installs to $HOME/.cache instead of node_modules/.cache HOT 6
- Enabling debug mode through package.json does not work HOT 3
- Randomizing db names for each test
- GridFS streams not working correctly HOT 4
- Jest + mongodb-memory-server + mongoose - Calling 'find' hangs indefinitely HOT 2
- Invalid version reported for version strings ending in -latest HOT 2
- Ubuntu >= 22.04 is unsupported when using MongoDB >= 6.0.4 HOT 7
- _startUpInstance threw a Error: TypeError: (intermediate value).finally is not a function HOT 3
- Mongod instance closed with code "127" HOT 7
- Case: InMemory DB refuses to update after Making changes to model HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongodb-memory-server.