This repository reproduces a bug in npm package [email protected]
What is going wrong is mongo binary being downloaded twice: first during postinstall, and later during test run.
Here is shell session output
$ docker build . -t mms-cache-bug --no-cache mongodb-memory-server-cache-bug/git/master
Sending build context to Docker daemon 39.42kB
Step 1/6 : FROM node:10.14
---> 8a752d5af4ce
Step 2/6 : RUN mkdir /app
---> Running in e5205bfdabd7
Removing intermediate container e5205bfdabd7
---> 5c64c54580b3
Step 3/6 : WORKDIR /app
Removing intermediate container 6c4dab4d9f83
---> b8bc2615cdce
Step 4/6 : RUN npm install [email protected]
---> Running in 907e12a93255
> [email protected] postinstall /app/node_modules/mongodb-memory-server
> node ./postinstall.js
mongodb-memory-server: checking MongoDB binaries cache...
mongodb-memory-server: binary path is /app/node_modules/mongodb-memory-server/mongodb-binaries/4.0.3/mongod
npm WARN saveError ENOENT: no such file or directory, open '/app/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/app/package.json'
npm WARN app No description
npm WARN app No repository field.
npm WARN app No README data
npm WARN app No license field.
+ [email protected]
added 94 packages from 51 contributors and audited 179 packages in 93.222s
found 0 vulnerabilities
Removing intermediate container 907e12a93255
---> 10eff9dc31b6
Step 5/6 : COPY ./index.js .
---> 0fc3173229f2
Step 6/6 : CMD node ./index.js
---> Running in 589661a3e3e5
Removing intermediate container 589661a3e3e5
---> afb90df9d688
Successfully built afb90df9d688
Successfully tagged mms-cache-bug:latest
$ docker run mms-cache-bug
Downloading MongoDB 4.0.3: 2.6 % (2.1mb / 79.4mb)
To work around, you can pass env variable MONGOMS_DOWNLOAD_DIR=/app/node_modules/mongodb-memory-server/mongodb-binaries
:
$ docker run -e MONGOMS_DOWNLOAD_DIR=/app/node_modules/mongodb-memory-server/mongodb-binaries mms-cache-bug
mongodb://127.0.0.1:43125/b71d900d-6c58-4e95-998b-f1c4da9afac4