pymongo_inmemory icon indicating copy to clipboard operation
pymongo_inmemory copied to clipboard

pymongo_inmemory doesn't work in docker container alpine

Open trolliama opened this issue 2 years ago • 5 comments

Describe the bug I am having troubles in running my tests inside my docker alpine container. I installed the pymongo_inmemory properly and started the tests and this was returned to me:

FileNotFoundError: [Errno 2] No such file or directory: '/usr/src/venv/lib/python3.9/site-packages/pymongo_inmemory/downloader/../.cache/extract/mongodb-linux-x86_64-4.0.23-tgz/mongodb-linux-x86_64-4.0.23/bin/mongod'

I verified it and the mongod binary is there. So i tried to run the subprocess.Popen to just ls the folders and indeed the error appeared. With a little bit of research I've found that using the shell=True option in the Popen() class like this: subprocess.Popen(["ls path/to/bin"], shell=True) worked, but when I tried to run the mongod with this command it gave me this error:

/bin/sh: /usr/src/venv/lib/python3.9/site-packages/pymongo_inmemory/downloader/../.cache/extract/mongodb-linux-x86_64-4.0.23-tgz/mongodb-linux-x86_64-4.0.23/bin/mongod: not found

Obs: In my machine works if I don't use the docker container

To Reproduce Steps to reproduce the behavior:

  1. Create tests (I used pytest)
  2. Create a dockerfile (I used the alpine):
FROM python:3.9-alpine AS builder

RUN pip install --user pipenv

WORKDIR /usr/src

RUN apk update
RUN apk add postgresql-dev gcc python3-dev musl-dev
RUN apk add postgresql

ADD Pipfile.lock Pipfile /usr/src/

RUN /root/.local/bin/pipenv lock --dev -r > requirements.txt

RUN python -m venv venv
RUN venv/bin/pip install -r requirements.txt

FROM python:3.9-alpine AS runtime

RUN mkdir -v /usr/src/venv
COPY --from=builder /usr/src/venv /usr/src/venv

RUN apk update
RUN apk add gcc postgresql

WORKDIR /usr/src

RUN ln -snf /usr/share/zoneinfo/America/Sao_Paulo \
    /etc/localtime && \
    echo "America/Sao_Paulo" > /etc/timezone

COPY ./src/app ./app
COPY ./src/tests ./tests
COPY ./src/main.py ./

# Copy the crontab configuration file
COPY ./cronjobs/execute_updater.dev ./cronjobs/execute_updater
RUN /usr/bin/crontab ./cronjobs/execute_updater
RUN touch /var/log/cron.log

# path the python venv bin - tru not to change since its needed in the ci pipeline
# CMD  /usr/sbin/crond -f -l 8 & tail -f /var/log/cron.log
CMD ["python", "-m", "http.server", "8080"]
  1. Run the container and then run the tests (I ran inside the container itself)
  2. The error appears

Expected behavior It's expected that the tests pass

Screenshots image

Context:

  • Version of pymongo_inmemory [~=0.2.5]
  • python3.9-alpine docker image

trolliama avatar Apr 06 '22 16:04 trolliama