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

Does mongo-unit work in docker containers? #15

Open
batmanhit opened this issue Oct 17, 2018 · 5 comments
Open

Does mongo-unit work in docker containers? #15

batmanhit opened this issue Oct 17, 2018 · 5 comments

Comments

@batmanhit
Copy link

No description provided.

@mikhail-angelov
Copy link
Owner

yes it does
ci is integrated with cycle-ci here, and it run tests inside docker container

@Philmod
Copy link
Contributor

Philmod commented Dec 10, 2018

What do you have to install to make it work in a container?

@mebibou
Copy link
Contributor

mebibou commented Feb 1, 2019

I am doing something like this:

// test/Dockerfile
FROM node:10.1.0

WORKDIR /app

COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm install

COPY . /app

CMD npm test

Then I can build the image using:

docker build -f test/Dockerfile -t my-test .

And run it using:

docker run --rm -v ${PWD}/src:/app/src -v ${PWD}/coverage:/app/coverage my-test:latest

The only annoying thing is, every time you run the tests you'll have to re-download the binaries for this library, maybe there is a way to cache it idk

@Philmod
Copy link
Contributor

Philmod commented Feb 2, 2019

If you want to avoid the download every time, you could download the mongo during the docker build:

FROM node:8.11.1

ARG mongo_version=3.4.14

WORKDIR /usr/src/app

RUN npm install -g mongodb-download

RUN mongodb-download --version=${mongo_version}

COPY package.json /usr/src/app/package.json
RUN npm install
COPY . . 

CMD [ "npm", "test" ]

@mebibou
Copy link
Contributor

mebibou commented Feb 4, 2019

@Philmod ah yes thanks for pointing me in the right direction, I instead create a little script

const { start, stop } = require('mongo-unit');

const run = async () => {
  await start();
  await stop();
};

run()
  .then(() => process.exit(0))
  .catch(err => {
    console.error(err);
    process.exit(1);
  });

And added RUN node script.js after RUN npm install and it works now without installing extra packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants